mirror of
https://github.com/yihong0618/bilingual_book_maker.git
synced 2025-06-05 19:15:34 +00:00
fix: #173
This commit is contained in:
parent
17d4fbcf0a
commit
ba87d0aa97
@ -52,20 +52,39 @@ class EPUBBookLoader(BaseBookLoader):
|
|||||||
self.accumulated_num = 1
|
self.accumulated_num = 1
|
||||||
self.helper = EPUBBookLoaderHelper(self.translate_model, self.accumulated_num)
|
self.helper = EPUBBookLoaderHelper(self.translate_model, self.accumulated_num)
|
||||||
|
|
||||||
|
# monkey pathch for # 173
|
||||||
|
def _write_items_patch(obj):
|
||||||
|
for item in obj.book.get_items():
|
||||||
|
if isinstance(item, epub.EpubNcx):
|
||||||
|
obj.out.writestr(
|
||||||
|
"%s/%s" % (obj.book.FOLDER_NAME, item.file_name), obj._get_ncx()
|
||||||
|
)
|
||||||
|
elif isinstance(item, epub.EpubNav):
|
||||||
|
obj.out.writestr(
|
||||||
|
"%s/%s" % (obj.book.FOLDER_NAME, item.file_name),
|
||||||
|
obj._get_nav(item),
|
||||||
|
)
|
||||||
|
elif item.manifest:
|
||||||
|
obj.out.writestr(
|
||||||
|
"%s/%s" % (obj.book.FOLDER_NAME, item.file_name), item.content
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
obj.out.writestr("%s" % item.file_name, item.content)
|
||||||
|
|
||||||
|
epub.EpubWriter._write_items = _write_items_patch
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.origin_book = epub.read_epub(self.epub_name)
|
self.origin_book = epub.read_epub(self.epub_name)
|
||||||
except Exception:
|
except Exception:
|
||||||
# tricky for #71 if you don't know why please check the issue and ignore this
|
# tricky monkey pathch for #71 if you don't know why please check the issue and ignore this
|
||||||
# when upstream change will TODO fix this
|
# when upstream change will TODO fix this
|
||||||
def _load_spine(self):
|
def _load_spine(obj):
|
||||||
spine = self.container.find(
|
spine = obj.container.find("{%s}%s" % (epub.NAMESPACES["OPF"], "spine"))
|
||||||
"{%s}%s" % (epub.NAMESPACES["OPF"], "spine")
|
|
||||||
)
|
|
||||||
|
|
||||||
self.book.spine = [
|
obj.book.spine = [
|
||||||
(t.get("idref"), t.get("linear", "yes")) for t in spine
|
(t.get("idref"), t.get("linear", "yes")) for t in spine
|
||||||
]
|
]
|
||||||
self.book.set_direction(spine.get("page-progression-direction", None))
|
obj.book.set_direction(spine.get("page-progression-direction", None))
|
||||||
|
|
||||||
epub.EpubReader._load_spine = _load_spine
|
epub.EpubReader._load_spine = _load_spine
|
||||||
self.origin_book = epub.read_epub(self.epub_name)
|
self.origin_book = epub.read_epub(self.epub_name)
|
||||||
|
10
setup.py
10
setup.py
@ -11,7 +11,15 @@ setup(
|
|||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
url="https://github.com/yihong0618/bilingual_book_maker",
|
url="https://github.com/yihong0618/bilingual_book_maker",
|
||||||
python_requires=">=3.7",
|
python_requires=">=3.7",
|
||||||
install_requires=["bs4", "openai", "requests", "ebooklib", "rich", "tqdm", "tiktoken"],
|
install_requires=[
|
||||||
|
"bs4",
|
||||||
|
"openai",
|
||||||
|
"requests",
|
||||||
|
"ebooklib",
|
||||||
|
"rich",
|
||||||
|
"tqdm",
|
||||||
|
"tiktoken",
|
||||||
|
],
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user