Slice 3: Wire rename_chapters() into download pipeline #34

Closed
opened 2026-06-05 15:03:59 +02:00 by AlexKucera · 1 comment
AlexKucera commented 2026-06-05 15:03:59 +02:00 (Migrated from github.com)

Parent

#19

What to build

Wire the rename_chapters() function (slice #32) into the download pipeline so it runs automatically after MP3 extraction when config.rename_chapters is enabled.

End-to-end behavior: When a book is downloaded in MP3 format (either mp3_only or m4b_mp3_fallback fallback), and rename_chapters is not explicitly disabled, the extracted MP3 files are renamed to include chapter titles before the function returns. M4B downloads never trigger renaming. Verbose output logs each rename operation.

Key design decision — tracks availability: The manifest (with tracks[]) is fetched inside _download_mp3(). Options:

  • Preferred: Return tracks alongside the output path from _download_mp3() (minimal change, no re-fetch)
  • The tracks list flows to download_book() → passed to rename_chapters()

Wiring points:

  1. _download_mp3() — return (Path | None, list[dict]) tuple: output dir + tracks (or keep current return, store tracks on a local that download_book can close over)
  2. download_book() — after MP3 success paths (lines ~277-282 and ~286-291), if config.rename_chapters and format is "mp3": call rename_chapters(output_dir, tracks, book.title)
  3. Config reaches download_book() via the _download_fn closure in sync_run.py (already has access from slice #33 wiring)

Not in scope: Changing download logic, new API calls, or ID3 tag writing.

Acceptance criteria

  • mp3_only mode + rename_chapters=True → chapters renamed after extraction
  • m4b_mp3_fallback falling back to MP3 + rename_chapters=True → chapters renamed
  • m4b_mp3_fallback with M4B success → rename NOT called (no MP3s)
  • m4b_only mode → rename never called
  • rename_chapters=False in config → rename skipped even for MP3 downloads
  • Verbose mode logs each file rename (old name → new name)
  • Count mismatch between MP3 files and tracks produces warning log
  • No behavior change when rename_chapters disabled (backward compatible)

Blocked by

  • #32 (core rename_chapters() function must exist)
  • #33 (config.rename_chapters field must exist and be threaded through)
## Parent #19 ## What to build Wire the `rename_chapters()` function (slice #32) into the download pipeline so it runs automatically after MP3 extraction when `config.rename_chapters` is enabled. **End-to-end behavior:** When a book is downloaded in MP3 format (either `mp3_only` or `m4b_mp3_fallback` fallback), and `rename_chapters` is not explicitly disabled, the extracted MP3 files are renamed to include chapter titles before the function returns. M4B downloads never trigger renaming. Verbose output logs each rename operation. **Key design decision — tracks availability:** The manifest (with `tracks[]`) is fetched inside `_download_mp3()`. Options: - **Preferred:** Return tracks alongside the output path from `_download_mp3()` (minimal change, no re-fetch) - The `tracks` list flows to `download_book()` → passed to `rename_chapters()` **Wiring points:** 1. `_download_mp3()` — return `(Path | None, list[dict])` tuple: output dir + tracks (or keep current return, store tracks on a local that `download_book` can close over) 2. `download_book()` — after MP3 success paths (lines ~277-282 and ~286-291), if `config.rename_chapters` and format is `"mp3"`: call `rename_chapters(output_dir, tracks, book.title)` 3. Config reaches `download_book()` via the `_download_fn` closure in `sync_run.py` (already has access from slice #33 wiring) **Not in scope:** Changing download logic, new API calls, or ID3 tag writing. ## Acceptance criteria - [ ] `mp3_only` mode + `rename_chapters=True` → chapters renamed after extraction - [ ] `m4b_mp3_fallback` falling back to MP3 + `rename_chapters=True` → chapters renamed - [ ] `m4b_mp3_fallback` with M4B success → rename NOT called (no MP3s) - [ ] `m4b_only` mode → rename never called - [ ] `rename_chapters=False` in config → rename skipped even for MP3 downloads - [ ] Verbose mode logs each file rename (old name → new name) - [ ] Count mismatch between MP3 files and tracks produces warning log - [ ] No behavior change when rename_chapters disabled (backward compatible) ## Blocked by - #32 (core `rename_chapters()` function must exist) - #33 (`config.rename_chapters` field must exist and be threaded through)
AlexKucera commented 2026-06-05 17:46:53 +02:00 (Migrated from github.com)

Done via c1dc4ad on feature/rename-mp3. 6 new integration tests, 8/8 AC met.

Done via c1dc4ad on feature/rename-mp3. 6 new integration tests, 8/8 AC met.
Sign in to join this conversation.