From 7ca3f7660174bb95ba8186ae9accdf8efb55278b Mon Sep 17 00:00:00 2001 From: Claudio Santini Date: Wed, 15 Jan 2025 09:31:50 +0100 Subject: [PATCH] fixed chapters --- audiblez.py | 19 ++++++++++++++++--- pyproject.toml | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/audiblez.py b/audiblez.py index edc17ac..a223988 100755 --- a/audiblez.py +++ b/audiblez.py @@ -11,6 +11,7 @@ import subprocess import soundfile as sf import ebooklib import warnings +import re from pathlib import Path from string import Formatter from bs4 import BeautifulSoup @@ -83,13 +84,25 @@ def extract_texts(chapters): return texts -def find_chapters(book, verbose=False): - is_chapter = lambda c: 'chapter' in c.get_name().lower() or 'part' in c.get_name().lower() +def is_chapter(c): + name = c.get_name().lower() + part = r"part\d{1,3}" + if re.search(part, name): + return True + ch = r"ch\d{1,3}" + if re.search(ch, name): + return True + if 'chapter' in name: + return True + + +def find_chapters(book, verbose=True): chapters = [c for c in book.get_items() if c.get_type() == ebooklib.ITEM_DOCUMENT and is_chapter(c)] if verbose: for item in book.get_items(): if item.get_type() == ebooklib.ITEM_DOCUMENT: - print((item.get_name(), len(item.get_body_content()), 'YES' if item in chapters else '-')) + # print(f"'{item.get_name()}'" + ', #' + str(len(item.get_body_content()))) + print(f'{item.get_name()}'.ljust(60), str(len(item.get_body_content())).ljust(15), 'X' if item in chapters else '-') return chapters diff --git a/pyproject.toml b/pyproject.toml index 5c51521..9115ae6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "audiblez" -version = "0.1.5" +version = "0.1.7" description = "" authors = [ { name = "Claudio Santini", email = "hireclaudio@gmail.com" }