Browse Source

feat: mobi release automatically

master
Dnomd343 2 years ago
parent
commit
0d9bd0737f
  1. 18
      src/release/release.py
  2. 1
      src/release/utils/__init__.py
  3. 48
      src/release/utils/release.py

18
src/release/release.py

@ -6,13 +6,19 @@ from utils import txtRelease
from utils import jsonRelease
from utils import mobiRelease
from utils import staticRelease
from utils import calibreRelease
from utils import gitbookRelease
releaseEntry = {
'txt': txtRelease,
'json': jsonRelease,
'mobi': mobiRelease,
'static': staticRelease,
'calibre': calibreRelease,
'gitbook': gitbookRelease,
}
metadata, content = loadBook('rc-5')
# txtRelease(metadata, content)
# jsonRelease(metadata, content)
mobiRelease(metadata, content)
# staticRelease(metadata, content)
# gitbookRelease(metadata, content)
releaseSrc = 'rc-5'
metadata, content = loadBook(releaseSrc)
releaseEntry['mobi'](metadata, content)

1
src/release/utils/__init__.py

@ -7,4 +7,5 @@ from .release import txtRelease
from .release import jsonRelease
from .release import mobiRelease
from .release import staticRelease
from .release import calibreRelease
from .release import gitbookRelease

48
src/release/utils/release.py

@ -32,10 +32,6 @@ def jsonRelease(metadata: dict, content: dict) -> None:
saveFile(releaseInfo['json'], jsonSerialize(metadata, content))
def htmlRelease(metadata: dict, content: dict) -> None:
saveFile(releaseInfo['calibre'], htmlSerialize(metadata, content))
def gitbookRelease(metadata: dict, content: dict) -> None:
createFolder(releaseInfo['gitbook'])
createFolder(os.path.join(releaseInfo['gitbook'], './assets/'))
@ -177,13 +173,10 @@ def calibreRelease(metadata: dict, content: dict) -> None:
tempDir.cleanup()
def calibreBuild(workDir: str, suffix: str, extOption: list) -> None:
# TODO: xxrs.zip + cover.jpg -> temp folder
# TODO: combine calibre options as command (with file suffix)
command = [
def calibreBuild(workDir: str, suffix: str, extOption: list, metadata: dict, content: dict) -> None:
buildDir = '/xxrs/'
calibreImage = 'linuxserver/calibre'
calibreCommand = [
'ebook-convert',
'xxrs.zip', 'xxrs%s' % suffix,
'--output-profile=generic_eink',
@ -193,16 +186,18 @@ def calibreBuild(workDir: str, suffix: str, extOption: list) -> None:
'--remove-paragraph-spacing',
'--remove-paragraph-spacing-indent-size=2',
'--verbose',
] + extOption
print(' '.join(command))
# TODO: start docker container and run calibre build
# TODO: release target format
pass
]
buildCommand = 'docker run --rm -t -v %s:%s --workdir %s --entrypoint bash %s -c "%s"' % (
workDir, buildDir, buildDir, calibreImage, ' '.join(calibreCommand + extOption)
)
shutil.copy( # ebook cover
os.path.join(rootPath, './assets/cover.jpg'),
os.path.join(workDir, './cover.jpg')
)
os.chdir(workDir)
calibreDepends(workDir, metadata, content)
os.system('zip -qr xxrs.zip *') # generate calibre input format
subprocess.Popen(buildCommand, shell = True).wait() # blocking wait
# MOBI Type: KF7 = 0 (old) / KF7 + KF8 = 1 (both) / KF8 = 2 (new)
@ -217,15 +212,8 @@ def mobiRelease(metadata: dict, content: dict, mobiType: int = 1) -> None:
else:
print('Unknown MOBI type')
return
tempDir = tempfile.TemporaryDirectory() # access temporary directory
print('Calibre MOBI Build: %s' % tempDir.name)
shutil.copy( # ebook cover
os.path.join(rootPath, './assets/cover.jpg'),
os.path.join(tempDir.name, './cover.jpg')
)
calibreDepends(tempDir.name, metadata, content)
os.chdir(tempDir.name)
os.system('zip -r xxrs.zip *') # generate calibre input format
calibreBuild(tempDir.name, '.mobi', mobiOption)
calibreBuild(tempDir.name, '.mobi', mobiOption, metadata, content)
shutil.copy(os.path.join(tempDir.name, './xxrs.mobi'), releaseInfo['mobi'])
tempDir.cleanup()

Loading…
Cancel
Save