Browse Source

feat: epub format support

master
Dnomd343 2 years ago
parent
commit
26d2778e6e
  1. 4
      src/release/release.py
  2. 1
      src/release/utils/__init__.py
  3. 4
      src/release/utils/common.py
  4. 10
      src/release/utils/release.py

4
src/release/release.py

@ -4,6 +4,7 @@
from utils import loadBook
from utils import txtRelease
from utils import jsonRelease
from utils import epubRelease
from utils import mobiRelease
from utils import staticRelease
from utils import calibreRelease
@ -12,6 +13,7 @@ from utils import gitbookRelease
releaseEntry = {
'txt': txtRelease,
'json': jsonRelease,
'epub': epubRelease,
'mobi': mobiRelease,
'static': staticRelease,
'calibre': calibreRelease,
@ -21,4 +23,4 @@ releaseEntry = {
releaseSrc = 'rc-5'
metadata, content = loadBook(releaseSrc)
releaseEntry['mobi'](metadata, content)
releaseEntry['epub'](metadata, content)

1
src/release/utils/__init__.py

@ -5,6 +5,7 @@ from .common import loadBook
from .release import txtRelease
from .release import jsonRelease
from .release import epubRelease
from .release import mobiRelease
from .release import staticRelease
from .release import calibreRelease

4
src/release/utils/common.py

@ -32,6 +32,10 @@ resourceInfo = { # resource download links
'https://res.343.re/Share/XXRS/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.txt',
'https://cdn.dnomd343.top/xxrs/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.txt',
],
'EPUB 下载': [
'https://res.343.re/Share/XXRS/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.epub',
'https://cdn.dnomd343.top/xxrs/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.epub',
],
'MOBI 下载': [
'https://res.343.re/Share/XXRS/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.mobi',
'https://cdn.dnomd343.top/xxrs/%E6%A0%A9%E6%A0%A9%E8%8B%A5%E7%94%9F.mobi',

10
src/release/utils/release.py

@ -200,6 +200,14 @@ def calibreBuild(workDir: str, suffix: str, extOption: list, metadata: dict, con
subprocess.Popen(buildCommand, shell = True).wait() # blocking wait
def epubRelease(metadata: dict, content: dict) -> None:
tempDir = tempfile.TemporaryDirectory() # access temporary directory
print('Calibre EPUB Build -> %s' % tempDir.name)
calibreBuild(tempDir.name, '.epub', [], metadata, content)
shutil.copy(os.path.join(tempDir.name, './xxrs.epub'), releaseInfo['epub'])
tempDir.cleanup()
# MOBI Type: KF7 = 0 (old) / KF7 + KF8 = 1 (both) / KF8 = 2 (new)
def mobiRelease(metadata: dict, content: dict, mobiType: int = 1) -> None:
mobiOption = ['--mobi-toc-at-start']
@ -213,7 +221,7 @@ def mobiRelease(metadata: dict, content: dict, mobiType: int = 1) -> None:
print('Unknown MOBI type')
return
tempDir = tempfile.TemporaryDirectory() # access temporary directory
print('Calibre MOBI Build: %s' % tempDir.name)
print('Calibre MOBI Build -> %s' % tempDir.name)
calibreBuild(tempDir.name, '.mobi', mobiOption, metadata, content)
shutil.copy(os.path.join(tempDir.name, './xxrs.mobi'), releaseInfo['mobi'])
tempDir.cleanup()

Loading…
Cancel
Save