diff --git a/CHANGELOG.md b/CHANGELOG.md index 327e2c7..b0acf76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 1.1.6 (pre-release) - Fixed SRT subtitle numbering issue, mentioned by @page-muncher in #41 +- Improved EPUB chapter detection: Now reliably detects chapters from NAV HTML (TOC) files, even in non-standard EPUBs, fixes the issue mentioned by @jefro108 in #33 - Windows installer script now prompts the user to install the CUDA version of PyTorch even if no NVIDIA GPU is detected. - Abogen now includes Mandarin Chinese (misaki[zh]) by default; manual installation is no longer required. diff --git a/abogen/book_handler.py b/abogen/book_handler.py index d43446f..8f920ae 100644 --- a/abogen/book_handler.py +++ b/abogen/book_handler.py @@ -324,14 +324,29 @@ class HandlerDialog(QDialog): f"Found NCX item via ITEM_NAVIGATION: {ncx_in_nav.get_name()}" ) - # 3. If still no nav_item, check for ITEM_NCX directly - if not nav_item: - ncx_items = list(self.book.get_items_of_type(ebooklib.ITEM_NCX)) + # 3. If still no nav_item, check for NCX or fallback to NAV HTML in all ITEM_DOCUMENTs + ncx_constant = getattr(epub, 'ITEM_NCX', None) + if not nav_item and ncx_constant is not None: + ncx_items = list(self.book.get_items_of_type(ncx_constant)) if ncx_items: - nav_item = ncx_items[0] # Take the first one + nav_item = ncx_items[0] nav_type = "ncx" - logging.info(f"Found NCX item via ITEM_NCX: {ncx_items[0].get_name()}") - + logging.info(f"Found NCX item via ITEM_NCX: {nav_item.get_name()}") + # Fallback: search all ITEM_DOCUMENTs for a NAV HTML with