From 6d0e740b4225859457109821a4c77feff72c24b5 Mon Sep 17 00:00:00 2001 From: historia Date: Tue, 18 Aug 2026 02:30:21 -0400 Subject: feat: show chapter in console when splitting m4b into chapters --- converter/audio.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'converter/audio.py') diff --git a/converter/audio.py b/converter/audio.py index f1c508c..5a7ec35 100644 --- a/converter/audio.py +++ b/converter/audio.py @@ -210,14 +210,17 @@ def _collect_chunk_files(total_chunks: int, def combine_chunks(total_chunks: int, output_path: Path, chunk_results: Optional[Dict[int, Optional[Path]]] = None, - speed: float = 1.0, output_format: str = "mp3") -> bool: + speed: float = 1.0, output_format: str = "mp3", + intermediate: bool = False) -> bool: """Combine audio chunks into the final audiobook using ffmpeg's concat demuxer. ``chunk_results`` maps chunk numbers to the audio file each chunk produced (None for failed chunks); failed and missing chunks are skipped. When ``speed`` differs from 1.0, an additional speed-adjusted copy is written next to the normal-speed file. Chunks are streamed by ffmpeg, so the whole - book is never held in memory. + book is never held in memory. Set ``intermediate`` for scratch chapter + audio on the way to a larger output (e.g. a chaptered m4b) so save + messages don't present it as the final audiobook. """ if shutil.which("ffmpeg") is None or shutil.which("ffprobe") is None: logger.error("ffmpeg and ffprobe are required to combine audio chunks (install ffmpeg)") @@ -265,8 +268,14 @@ def combine_chunks(total_chunks: int, output_path: Path, if not duration_ok: return False - logger.info("Audiobook saved: %s (%d/%d chunks)", output_path, len(chunk_files), total_chunks) - print(f"[INFO] Saved audiobook: {output_path.name} ({len(chunk_files)}/{total_chunks} chunks)") + if intermediate: + logger.info("Chapter audio saved (intermediate): %s (%d/%d chunks)", + output_path, len(chunk_files), total_chunks) + print(f"[INFO] Saved chapter audio (intermediate): {output_path.name} " + f"({len(chunk_files)}/{total_chunks} chunks)") + else: + logger.info("Audiobook saved: %s (%d/%d chunks)", output_path, len(chunk_files), total_chunks) + print(f"[INFO] Saved audiobook: {output_path.name} ({len(chunk_files)}/{total_chunks} chunks)") if speed_path is not None: logger.info("Saved speed-adjusted audiobook (%gx): %s", speed, speed_path) -- cgit v1.2.3