Factor out the repeated post-download success logic from the three format-strategy blocks in download_book() (m4b_mp3_fallback, mp3_only, m4b_only). Each branch currently repeats: rename chapters → download accompanying files → return success DownloadResult. Extract this into a shared helper so each branch becomes: attempt download → if success, call success helper → return result.
All three format-strategy branches call the shared helper on success
No duplicated rename/accompany/return-success code across branches
All existing format-strategy tests pass (fallback, mp3_only, m4b_only)
Full test suite passes
Adding a new format strategy in the future requires only writing the download attempt + calling the existing success helper
Blocked by
#41 — Slice 5 (extract streaming loop) should land first so the function being refactored has stabilized
## Parent
#36 — PRD-003: Deepen Codebase Architecture
## What to build
Factor out the repeated post-download success logic from the three format-strategy blocks in `download_book()` (m4b_mp3_fallback, mp3_only, m4b_only). Each branch currently repeats: rename chapters → download accompanying files → return success DownloadResult. Extract this into a shared helper so each branch becomes: attempt download → if success, call success helper → return result.
## Acceptance criteria
- [ ] A private helper (e.g., `_finalize_download()`) handles rename_chapters + accompanying_files + success DownloadResult
- [ ] All three format-strategy branches call the shared helper on success
- [ ] No duplicated rename/accompany/return-success code across branches
- [ ] All existing format-strategy tests pass (fallback, mp3_only, m4b_only)
- [ ] Full test suite passes
- [ ] Adding a new format strategy in the future requires only writing the download attempt + calling the existing success helper
## Blocked by
#41 — Slice 5 (extract streaming loop) should land first so the function being refactored has stabilized
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Parent
#36 — PRD-003: Deepen Codebase Architecture
What to build
Factor out the repeated post-download success logic from the three format-strategy blocks in
download_book()(m4b_mp3_fallback, mp3_only, m4b_only). Each branch currently repeats: rename chapters → download accompanying files → return success DownloadResult. Extract this into a shared helper so each branch becomes: attempt download → if success, call success helper → return result.Acceptance criteria
_finalize_download()) handles rename_chapters + accompanying_files + success DownloadResultBlocked by
#41 — Slice 5 (extract streaming loop) should land first so the function being refactored has stabilized
Closed via
bf7e474— extracted_finalize_download()helper. 4 new tests, 126 total in test_downloader.py, full suite passes.