From deedb946fe1c10b3373f41b52be465d8e8822479 Mon Sep 17 00:00:00 2001 From: InzamZ Date: Tue, 7 Mar 2023 18:50:02 +0800 Subject: [PATCH] fix(#57): Fix the bug caused by parsing non-HTML files (#91) --- make_book.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/make_book.py b/make_book.py index 7b1db34..6923234 100644 --- a/make_book.py +++ b/make_book.py @@ -186,9 +186,9 @@ class BEPUB: new_book = self._make_new_book(self.origin_book) all_items = list(self.origin_book.get_items()) all_p_length = sum( - len(bs(i.content, "html.parser").findAll("p")) - if i.file_name.endswith(".xhtml") - else len(bs(i.content, "xml").findAll("p")) + 0 + if i.get_type() != ITEM_DOCUMENT + else len(bs(i.content, "html.parser").findAll("p")) for i in all_items ) pbar = tqdm(total=TEST_NUM) if IS_TEST else tqdm(total=all_p_length) @@ -217,7 +217,7 @@ class BEPUB: self._save_progress() # pbar.update(delta) not pbar.update(index)? pbar.update(1) - if IS_TEST and index > TEST_NUM: + if IS_TEST and index >= TEST_NUM: break item.content = soup.prettify().encode() new_book.add_item(item)