|
|
@ -228,29 +228,28 @@ def mobiRelease(metadata: dict, content: dict, mobiType: int = 1) -> None: |
|
|
|
|
|
|
|
|
|
|
|
def setPdocMark(originFile: str, targetFile: str) -> None: |
|
|
|
jdkImage = 'openjdk:17-alpine' |
|
|
|
tempDir = tempfile.TemporaryDirectory() # access temporary directory |
|
|
|
|
|
|
|
shutil.copy(originFile, os.path.join(tempDir.name, 'xxrs.azw3')) |
|
|
|
|
|
|
|
# TODO: copy originFile -> tempDir.name |
|
|
|
# remember changing the originFile suffix |
|
|
|
|
|
|
|
# TODO: fetch convert jar file (https://github.com/dnomd343/mobi-meta/releases/latest/download/mobi-meta.jar) |
|
|
|
|
|
|
|
# TODO: run openjdk container and generate new eBook (openjdk:17-alpine) |
|
|
|
# java -jar mobi-meta.jar edit {xxrs.azw3} {xxrs_new.azw3} --pdoc |
|
|
|
|
|
|
|
# TODO: copy output file as targetFile |
|
|
|
|
|
|
|
pass |
|
|
|
suffix = os.path.splitext(originFile)[-1] |
|
|
|
shutil.copy(originFile, os.path.join(tempDir.name, 'xxrs%s' % suffix)) |
|
|
|
shutil.copy( |
|
|
|
os.path.join(os.path.dirname(os.path.realpath(__file__)), 'mobi-meta.jar'), # script folder |
|
|
|
os.path.join(tempDir.name, 'mobi-meta.jar') |
|
|
|
) |
|
|
|
dockerCommand = 'docker run --rm -v %(src)s:%(tmp)s --workdir %(tmp)s --entrypoint sh %(img)s -c "%(cmd)s"' % { |
|
|
|
'src': tempDir.name, |
|
|
|
'tmp': '/xxrs/', |
|
|
|
'img': jdkImage, |
|
|
|
'cmd': 'java -jar mobi-meta.jar edit xxrs%s xxrs_mod%s --pdoc' % (suffix, suffix), |
|
|
|
} |
|
|
|
subprocess.Popen(dockerCommand, shell = True).wait() # blocking wait |
|
|
|
shutil.copy(os.path.join(tempDir.name, 'xxrs_mod%s' % suffix), targetFile) |
|
|
|
tempDir.cleanup() |
|
|
|
|
|
|
|
|
|
|
|
def azw3Release(metadata: dict, content: dict) -> None: |
|
|
|
tempDir = tempfile.TemporaryDirectory() # access temporary directory |
|
|
|
print('Calibre AZW3 Build -> %s' % tempDir.name) |
|
|
|
calibreBuild(tempDir.name, '.azw3', ['--mobi-toc-at-start'], metadata, content) |
|
|
|
|
|
|
|
# TODO: change `[EBOK]` as `[PDOC]` |
|
|
|
setPdocMark(os.path.join(tempDir.name, './xxrs.azw3'), releaseInfo['azw3']) |
|
|
|
|
|
|
|
tempDir.cleanup() |
|
|
|