From 8afee975983a3156fbd3b316f110c310cb8336eb Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Tue, 30 Dec 2025 09:38:56 +0100 Subject: [PATCH] improve comic book page count --- src/calibre/library/page_count.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/calibre/library/page_count.py b/src/calibre/library/page_count.py index 2712c3f6d2..e742f992b2 100644 --- a/src/calibre/library/page_count.py +++ b/src/calibre/library/page_count.py @@ -40,23 +40,28 @@ def count_pages_pdf(pathtoebook: str) -> int: return get_page_count(pathtoebook) -def count_pages_cbz(pathtoebook: str) -> int: +def fname_ok_cb(fname): from calibre.ebooks.metadata.archive import fname_ok + from calibre.libunzip import comic_exts + return fname_ok(fname) and fname.rpartition('.')[-1].lower() in comic_exts + + +def count_pages_cbz(pathtoebook: str) -> int: from calibre.utils.zipfile import ZipFile with closing(ZipFile(pathtoebook)) as zf: - return sum(1 for _ in filter(fname_ok, zf.namelist())) + return sum(1 for _ in filter(fname_ok_cb, zf.namelist())) def count_pages_cbr(pathtoebook: str) -> int: - from calibre.ebooks.metadata.archive import RAR, fname_ok + from calibre.ebooks.metadata.archive import RAR with closing(RAR(pathtoebook)) as zf: - return sum(1 for _ in filter(fname_ok, zf.namelist())) + return sum(1 for _ in filter(fname_ok_cb, zf.namelist())) def count_pages_cb7(pathtoebook: str) -> int: - from calibre.ebooks.metadata.archive import SevenZip, fname_ok + from calibre.ebooks.metadata.archive import SevenZip with closing(SevenZip(pathtoebook)) as zf: - return sum(1 for _ in filter(fname_ok, zf.namelist())) + return sum(1 for _ in filter(fname_ok_cb, zf.namelist())) def get_length(root):