fix: fix parser error of xml based epub (#50)

* fix: fix parser error of xml based epub

* fix: fix xhtml based epub error by detect automatically

* docs: update README
This commit is contained in:
InzamZ 2023-03-05 21:40:01 +08:00 committed by GitHub
parent 602ac2ca3e
commit 7200da7b0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -162,9 +162,12 @@ class BEPUB:
new_book.toc = self.origin_book.toc new_book.toc = self.origin_book.toc
all_items = list(self.origin_book.get_items()) all_items = list(self.origin_book.get_items())
# we just translate tag p # we just translate tag p
all_p_length = sum( all_p_length = 0
[len(bs(i.content, "html.parser").findAll("p")) for i in all_items] for i in all_items:
) if i.file_name.endswith(".xhtml"):
all_p_length += len(bs(i.content, "html.parser").findAll("p"))
else:
all_p_length += len(bs(i.content, "xml").findAll("p"))
if IS_TEST: if IS_TEST:
pbar = tqdm(total=TEST_NUM) pbar = tqdm(total=TEST_NUM)
else: else:

View File

@ -3,4 +3,4 @@ openai
requests requests
ebooklib ebooklib
rich rich
tqdm tqdm