From 36f27872074ebc3396dac7f16f34443ce8deb7a8 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sat, 18 Mar 2023 15:06:57 +0800 Subject: [PATCH] feat: azw3 format support --- src/release/release.py | 4 +++- src/release/utils/__init__.py | 1 + src/release/utils/common.py | 1 + src/release/utils/release.py | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/release/release.py b/src/release/release.py index 75be847..90f85b8 100755 --- a/src/release/release.py +++ b/src/release/release.py @@ -4,6 +4,7 @@ from utils import loadBook from utils import txtRelease from utils import jsonRelease +from utils import azw3Release from utils import epubRelease from utils import mobiRelease from utils import staticRelease @@ -13,6 +14,7 @@ from utils import gitbookRelease releaseEntry = { 'txt': txtRelease, 'json': jsonRelease, + 'azw3': azw3Release, 'epub': epubRelease, 'mobi': mobiRelease, 'static': staticRelease, @@ -23,4 +25,4 @@ releaseEntry = { releaseSrc = 'rc-5' metadata, content = loadBook(releaseSrc) -releaseEntry['epub'](metadata, content) +releaseEntry['azw3'](metadata, content) diff --git a/src/release/utils/__init__.py b/src/release/utils/__init__.py index 1ecaf43..6a3b7f3 100644 --- a/src/release/utils/__init__.py +++ b/src/release/utils/__init__.py @@ -5,6 +5,7 @@ from .common import loadBook from .release import txtRelease from .release import jsonRelease +from .release import azw3Release from .release import epubRelease from .release import mobiRelease from .release import staticRelease diff --git a/src/release/utils/common.py b/src/release/utils/common.py index 497a9c3..735214c 100644 --- a/src/release/utils/common.py +++ b/src/release/utils/common.py @@ -17,6 +17,7 @@ metadataFile = os.path.join(rootPath, './assets/metadata.json') releaseInfo = { # release file name 'json': 'XXRS.json', 'txt': '栩栩若生.txt', + 'azw3': '栩栩若生.azw3', 'epub': '栩栩若生.epub', 'mobi': '栩栩若生.mobi', 'calibre': 'xxrs.zip', diff --git a/src/release/utils/release.py b/src/release/utils/release.py index 5615f8a..1db37ec 100644 --- a/src/release/utils/release.py +++ b/src/release/utils/release.py @@ -225,3 +225,12 @@ def mobiRelease(metadata: dict, content: dict, mobiType: int = 1) -> None: calibreBuild(tempDir.name, '.mobi', mobiOption, metadata, content) shutil.copy(os.path.join(tempDir.name, './xxrs.mobi'), releaseInfo['mobi']) 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', [], metadata, content) + # TODO: change `[EBOK]` as `[PDOC]` + shutil.copy(os.path.join(tempDir.name, './xxrs.azw3'), releaseInfo['azw3']) + tempDir.cleanup()