Slice 3b: M4B download pipeline #5

Closed
opened 2026-06-03 10:27:06 +02:00 by AlexKucera · 0 comments
AlexKucera commented 2026-06-03 10:27:06 +02:00 (Migrated from github.com)

Parent

#1

What to build

The core M4B download pipeline — first working end-to-end audiobook download.

client module (M4B endpoint):

  • GET /api/v10/audiobooks/{isbn}/packaged_m4b — returns M4B download URL
  • Handle 404 (M4B not available for this book) — return None/raise specific error for caller to decide fallback

downloader module (I/O):

  • Streaming chunked download: 8MB chunks, write to {filename}.m4b.partial
  • On completion: atomic rename from .partial to final {filename}.m4b
  • Resume support: detect existing .partial file, read its size, send Range: bytes={size}- header
  • Use path resolution and sanitization from Slice 3a to determine output location
  • Apply subdirectory-vs-flat decision from Slice 3a
  • File I/O uses binary mode, respects output directory config

history integration:

  • After successful complete download (atomic rename done), write entry to download_history.json

cli wiring:

  • For each undownloaded book: resolve path → query M4B metadata → if available, download → update history
  • Books without M4B available are logged as "skipped (no M4B)" — fallback to MP3 is next slice
  • First working download end-to-end (with mocked HTTP in tests)

Acceptance criteria

  • M4B metadata query returns download URL when available
  • M4B metadata query returns None/specific error on 404 (book has no M4B)
  • Download writes to .partial file during transfer
  • On completion, file atomically renamed to final .m4b
  • Existing .partial file detected and resume via Range header
  • Resume starts from correct byte offset (partial file size)
  • Output path follows pattern from Slice 3a with sanitization applied
  • Subdirectory created when accompanying files present; flat otherwise
  • History entry written only after successful complete download
  • Book without M4B logged and skipped (not treated as error)
  • ~25 tests: M4B query success/404, streaming to temp dir, resume from partial, atomic rename, path resolution integration, happy-path orchestration with mocks
  • All tests pass

Blocked by

#4

## Parent #1 ## What to build The core M4B download pipeline — first working end-to-end audiobook download. **client module (M4B endpoint):** - `GET /api/v10/audiobooks/{isbn}/packaged_m4b` — returns M4B download URL - Handle 404 (M4B not available for this book) — return None/raise specific error for caller to decide fallback **downloader module (I/O):** - Streaming chunked download: 8MB chunks, write to `{filename}.m4b.partial` - On completion: atomic rename from `.partial` to final `{filename}.m4b` - Resume support: detect existing `.partial` file, read its size, send `Range: bytes={size}-` header - Use path resolution and sanitization from Slice 3a to determine output location - Apply subdirectory-vs-flat decision from Slice 3a - File I/O uses binary mode, respects output directory config **history integration:** - After successful complete download (atomic rename done), write entry to `download_history.json` **cli wiring:** - For each undownloaded book: resolve path → query M4B metadata → if available, download → update history - Books without M4B available are logged as "skipped (no M4B)" — fallback to MP3 is next slice - First **working** download end-to-end (with mocked HTTP in tests) ## Acceptance criteria - [ ] M4B metadata query returns download URL when available - [ ] M4B metadata query returns None/specific error on 404 (book has no M4B) - [ ] Download writes to `.partial` file during transfer - [ ] On completion, file atomically renamed to final `.m4b` - [ ] Existing `.partial` file detected and resume via Range header - [ ] Resume starts from correct byte offset (partial file size) - [ ] Output path follows pattern from Slice 3a with sanitization applied - [ ] Subdirectory created when accompanying files present; flat otherwise - [ ] History entry written only after successful complete download - [ ] Book without M4B logged and skipped (not treated as error) - [ ] ~25 tests: M4B query success/404, streaming to temp dir, resume from partial, atomic rename, path resolution integration, happy-path orchestration with mocks - [ ] All tests pass ## Blocked by #4
Sign in to join this conversation.