Merge branch 'release/1.4.0' into develop
This commit is contained in:
9 files changed
+288
-134
No files matched your search
+118
-118
@@ -1,11 +1,11 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
## [1.4.0] - 2026-06-06
|
||||
|
||||
### Added
|
||||
|
||||
- **selector:** Add interactive book selection module `selector.py` with
|
||||
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- **sync_run:** Wire `--select` into download pipeline. TTY guard
|
||||
(non-interactive terminals get error exit 1), dict→Book conversion
|
||||
via `from_library_row()`, selected Books pass to orchestrator
|
||||
without double-conversion, `--limit` bypassed with verbose note.
|
||||
without double-conversion, `--limit` bypassed with notice.
|
||||
6 integration tests. Closes #48.
|
||||
|
||||
### Fixed
|
||||
@@ -25,12 +25,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
`--select` is active. Previously the message was gated behind
|
||||
`--verbose`, so non-verbose users had no indication their flag
|
||||
was silently ignored.
|
||||
- **sync_run:** Check stdin (not stdout) for TTY guard, fixing the
|
||||
interactive selection check in non-interactive environments.
|
||||
|
||||
- **downloader:** Fix progress bar exceeding 100% on resumed downloads.
|
||||
`Content-Length` from a Range response covers only remaining bytes;
|
||||
now adds `resume_from` for the true total.
|
||||
- **session:** Stop reaching into `httpx.Client._transport` (private API).
|
||||
Transport reference is now stored at construction time.
|
||||
## [1.3.0] - 2026-06-06
|
||||
|
||||
### Added
|
||||
|
||||
@@ -38,12 +36,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
files with chapter titles from the download manifest. Natural sort by
|
||||
numeric prefix, auto zero-padding, null/blank title fallback, sanitization
|
||||
via existing `sanitize()`. 11 tests. Closes #32.
|
||||
|
||||
- **config:** Add `rename_chapters` boolean field to Config dataclass with default
|
||||
`True`. Read from YAML config, threaded through CLI (`--rename-chapters` flag)
|
||||
and `sync_run()` resolution (CLI True → config value). 5 new tests, 223 total.
|
||||
Closes #33.
|
||||
|
||||
- **downloader:** Wire `rename_chapters()` into download pipeline.
|
||||
`_download_mp3()` returns `(output_dir, tracks)` tuple; `download_book()`
|
||||
accepts `rename_chapters` kwarg; new `_rename_and_log()` helper calls rename
|
||||
@@ -51,6 +47,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
feedback: "Renamed N chapter(s) for 'Book' → 'example.mp3'".
|
||||
`sync_run.py` closure threads resolved flag through to `download_book()`.
|
||||
6 new integration tests, ~229 total. Closes #34.
|
||||
- **downloader:** Integration tests for rename_chapters pipeline wiring.
|
||||
Edge cases: special chars, single-track, 105-chapter 3-digit padding.
|
||||
Closes #35.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **downloader:** Fix progress bar exceeding 100% on resumed downloads.
|
||||
`Content-Length` from a Range response covers only remaining bytes;
|
||||
now adds `resume_from` for the true total.
|
||||
- **downloader:** Fix missing `Callable` import in module scope.
|
||||
- **session:** Stop reaching into `httpx.Client._transport` (private API).
|
||||
Transport reference is now stored at construction time.
|
||||
|
||||
### Refactored
|
||||
|
||||
@@ -59,12 +67,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
it on reporter objects as shared state. Remove `cancel_event` attribute from
|
||||
both `PlainTextReporter` and `ProgressReporter`. 429 tests (+5 net).
|
||||
Closes #39.
|
||||
|
||||
- **session:** Expose public `transport` property on `LibroFmSession` returning
|
||||
the underlying httpx transport. Update sole call site in `downloader.py` from
|
||||
`session._client._transport` to `session.transport`. 2 new tests, 425 total.
|
||||
Closes #38.
|
||||
|
||||
- **downloader:** Extract `_stream_to_file()` private helper from the
|
||||
duplicated ~30-line chunked-download loop in `download_m4b()`,
|
||||
`download_zip_part()`, `_download_cover()`, and `_download_pdf()`. All
|
||||
@@ -72,32 +78,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
shared helper. 5 new TDD tests (fresh download, resume, cancel
|
||||
mid-stream, progress callback, error propagation). 224 total tests.
|
||||
Net -22 lines in downloader.py. Closes #41.
|
||||
|
||||
|
||||
- **downloader:** Extract `_finalize_download()` from format-specific branches
|
||||
to consolidate post-download logic into a single helper.
|
||||
- **session:** Rename LibroFmClient → LibroFmSession, relocate to
|
||||
session.py, inject transport at construction time. Old client.py is now
|
||||
a deprecated re-export shim. Endpoint signatures slimmed from 4-5 params
|
||||
to ≤3 (transport removed). 227 tests pass (+17 new). Closes #27.
|
||||
|
||||
- **path:** Introduce OutputPlan frozen dataclass and resolve_output_plan()
|
||||
function to centralize all path computation for a book. Download functions
|
||||
now consume pre-resolved plan fields instead of computing paths inline,
|
||||
eliminating duplicated audio-filename logic. 237 tests pass (+10 new).
|
||||
Closes #28.
|
||||
|
||||
- **downloader:** Shrink download_book() from 9 parameters to 4
|
||||
domain-aligned params (book, session, plan, reporter) returning a frozen
|
||||
DownloadResult dataclass. Move history writing to caller (cli closure).
|
||||
Add format_strategy to OutputPlan, wire cancel_event through reporter,
|
||||
extract transport from session. Remove config from accompanying_files.
|
||||
368 tests pass (+15 new). Closes #29.
|
||||
|
||||
- **progress:** Return bound callable from start_download() instead of raw
|
||||
task_id. Task identity is fully internal to progress.py. Orchestrator
|
||||
no longer creates per-book closures — passes the bound callback
|
||||
directly. download_book() accepts optional progress= kwarg. Public
|
||||
update() drops task_id param. 382 tests pass (+11 new). Closes #30.
|
||||
|
||||
- **cli/sync-run:** Extract entire download pipeline from cli.run() into
|
||||
standalone sync_run() function in new sync_run.py module. Introduce
|
||||
SyncRunResult frozen dataclass (replaces OrchestratorResult as public
|
||||
@@ -106,8 +108,62 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
test_cli.py to test_sync_run.py (43 total + 10 CLI-only tests).
|
||||
Add select_mode stub (ADR #6 branch point) and fatal_error field for
|
||||
exit-code translation. 374 tests pass. Closes #31.
|
||||
- **sync-run:** Refactored `sync_run()` to injectable pipeline. 4 DI seams
|
||||
(session/history/reporter/download_fn), extracted 2 helpers
|
||||
(`_print_verbose_config`, `_resolve_history_path`), simplified closure.
|
||||
+10 tests. Closes #44.
|
||||
- **sync-run:** Consolidated `SyncRunResult`/`OrchestratorResult` via
|
||||
composition. `SyncRunResult` wraps `OrchestratorResult` + 6 delegating
|
||||
properties. Bridge copy code eliminated. +2 tests. Closes #45.
|
||||
- **history:** Relocate `_write_history()` from `downloader.py` → `history.py`.
|
||||
Updated all import sites. +1 net test. Closes #40.
|
||||
- **tests:** Reorganize test files to match production modules. Deleted 13
|
||||
duplicate path classes, moved 2 integration classes, removed duplicate
|
||||
`TestParallelProgressCallbackWiring`, rescued orphaned method. −470 net
|
||||
test lines, 374 tests. Closes #43.
|
||||
- **book:** Extract Book dataclass + `from_library_row()` and path logic
|
||||
(`sanitize`, `resolve_path`, `needs_subdirectory`) from monolithic
|
||||
`downloader.py` into `book.py` and `path.py`. 79 new tests. Closes #26.
|
||||
|
||||
## [1.2.0] - 2026-06-04
|
||||
|
||||
### Added
|
||||
|
||||
- **config:** Parallel download worker count: `workers` field on Config dataclass
|
||||
(default 3), `InvalidWorkersError` validation for values < 1, YAML parsing
|
||||
from `librofm.workers`, and `-w`/`--workers` CLI flag with three-layer
|
||||
resolution (CLI > config > default). 6 new tests (179 total). Closes #12.
|
||||
- **progress:** Per-book identity mapping for concurrent progress bars:
|
||||
replace singleton `_current_task`/`_current_book` with bidirectional
|
||||
`_tasks`/`_book_ids` dicts keyed by `id(book)`. `start_download()` now
|
||||
returns `task_id`, `update()` accepts optional `task_id` kwarg with
|
||||
backward-compat fallback to most-recent task. `complete()`/`fail()`
|
||||
clean up both mappings. PlainTextReporter unchanged (already stateless).
|
||||
10 new tests (194 total). Closes #14.
|
||||
- **api:** Rate limit concurrent Libro.fm API calls with `threading.Semaphore(3)`.
|
||||
CDN downloads bypass the limiter. 4 new tests (198 total). Closes #15.
|
||||
- **orchestrator:** ThreadPoolExecutor-based parallel download engine:
|
||||
`download_all_books()` replaces sequential for-loop in cli.py, submitting all
|
||||
books as futures with per-future failure isolation. Returns `OrchestratorResult`
|
||||
dataclass with stable-sorted counts, failed_books as (Book, reason) tuples,
|
||||
and skipped_books as Book objects. `_raw_to_book()` conversion extracted from
|
||||
cli.py. 20 new tests (218 total). Closes #16.
|
||||
- **orchestrator:** Graceful Ctrl+C drain during parallel downloads:
|
||||
first interrupt prints "Aborting...", drains in-flight downloads via
|
||||
`executor.shutdown(wait=True)`, then re-raises for exit code 130; second
|
||||
interrupt during drain force-quits immediately with
|
||||
`shutdown(cancel_futures=True)`. 13 new integration tests covering
|
||||
workers=1 regression parity, concurrent execution proof, summary ordering,
|
||||
failure isolation, verbose overlap safety, double-Ctrl+C fast exit, and
|
||||
partial file resume-safety after interrupt (231 total). Closes #17.
|
||||
- **docs:** Update all documentation for parallel downloads. Closes #18.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **history:** Make `DownloadHistory.write()` thread-safe with
|
||||
`threading.Lock` so concurrent worker threads don't corrupt or lose
|
||||
history entries during parallel downloads. Lock guards both in-memory
|
||||
mutation and disk flush. 5 new tests (184 total). Closes #13.
|
||||
- **progress:** Wire task_id through parallel progress callback.
|
||||
All concurrent download updates went to the same (most recently started) bar
|
||||
because `task_id` was never threaded from `start_download()` to `update()`.
|
||||
@@ -131,138 +187,82 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
## [1.1.0] - 2026-06-04
|
||||
|
||||
### Added
|
||||
- **config (closes #22):** XDG config path resolution with CWD fallback.
|
||||
|
||||
- **config:** XDG config path resolution with CWD fallback.
|
||||
`_resolve_config_file()` searches `~/.config/librofm-downloader/` then CWD.
|
||||
`load_config(None, None)` triggers search; missing config.yaml is non-fatal
|
||||
(prints notice, uses built-in defaults); missing secrets.yaml raises
|
||||
domain error listing searched paths. All OS exceptions wrapped as
|
||||
`ConfigError`. XDG directory auto-created on demand.
|
||||
- **cli (closes #23):** Wire XDG path resolution into CLI layer.
|
||||
`ConfigError`. XDG directory auto-created on demand. Closes #22.
|
||||
- **cli:** Wire XDG path resolution into CLI layer.
|
||||
History path defaults to `None` (resolves XDG → CWD, falls back to XDG
|
||||
location). Missing config message now lists searched paths. `--verbose`
|
||||
shows resolved file paths for config, secrets, and history. Explicit
|
||||
`--config`/`--secrets`/`--history` flags bypass search. Clean exit 1
|
||||
with no traceback when secrets missing from all locations.
|
||||
with no traceback when secrets missing from all locations. Closes #23.
|
||||
|
||||
### Documentation
|
||||
- **docs (closes #24):** Update all documentation for XDG path resolution.
|
||||
|
||||
- Update all documentation for XDG path resolution.
|
||||
configuration.md: new "Default file locations" section with search order,
|
||||
auto-creation, missing-config vs missing-secrets behavior, CLI flag
|
||||
overrides, validation error table with "not found" messages, and
|
||||
history default location. quickstart.md, cli-usage.md, troubleshooting.md,
|
||||
and README.md updated to reference XDG-first search.
|
||||
and README.md updated to reference XDG-first search. Closes #24.
|
||||
|
||||
## [1.0.0] - 2026-06-03
|
||||
|
||||
### Fixed
|
||||
|
||||
- **history:** Make `DownloadHistory.write()` thread-safe with
|
||||
`threading.Lock` so concurrent worker threads don't corrupt or lose
|
||||
history entries during parallel downloads. Lock guards both in-memory
|
||||
mutation and disk flush. 5 new tests (184 total) (closes #13)
|
||||
|
||||
### Added
|
||||
|
||||
- **progress:** Per-book identity mapping for concurrent progress bars:
|
||||
replace singleton `_current_task`/`_current_book` with bidirectional
|
||||
`_tasks`/`_book_ids` dicts keyed by `id(book)`. `start_download()` now
|
||||
returns `task_id`, `update()` accepts optional `task_id` kwarg with
|
||||
backward-compat fallback to most-recent task. `complete()`/`fail()`
|
||||
clean up both mappings. PlainTextReporter unchanged (already stateless).
|
||||
10 new tests (194 total) (closes #14)
|
||||
|
||||
- **config:** Parallel download worker count: `workers` field on Config dataclass
|
||||
(default 3), `InvalidWorkersError` validation for values < 1, YAML parsing
|
||||
from `librofm.workers`, and `-w`/`--workers` CLI flag with three-layer
|
||||
resolution (CLI > config > default). 6 new tests (179 total) (closes #12)
|
||||
|
||||
- **orchestrator:** ThreadPoolExecutor-based parallel download engine:
|
||||
`download_all_books()` replaces sequential for-loop in cli.py, submitting all
|
||||
books as futures with per-future failure isolation. Returns `OrchestratorResult`
|
||||
dataclass with stable-sorted counts, failed_books as (Book, reason) tuples,
|
||||
and skipped_books as Book objects. `_raw_to_book()` conversion extracted from
|
||||
cli.py. 20 new tests (218 total) (closes #16)
|
||||
|
||||
- **orchestrator:** Graceful Ctrl+C drain during parallel downloads:
|
||||
first interrupt prints "Aborting...", drains in-flight downloads via
|
||||
`executor.shutdown(wait=True)`, then re-raises for exit code 130; second
|
||||
interrupt during drain force-quits immediately with
|
||||
`shutdown(cancel_futures=True)`. 13 new integration tests covering
|
||||
workers=1 regression parity, concurrent execution proof, summary ordering,
|
||||
failure isolation, verbose overlap safety, double-Ctrl+C fast exit, and
|
||||
partial file resume-safety after interrupt (231 total) (closes #17)
|
||||
|
||||
- MP3 format fallback: download manifest fetch, ZIP part download+extraction
|
||||
with .partial tracking and resume, format strategy selector (m4b_mp3_fallback,
|
||||
mp3_only, m4b_only), and `--limit` CLI flag for capped downloads
|
||||
|
||||
|
||||
## [1.0.0]] - 2026-06-03
|
||||
|
||||
### Documentation
|
||||
- **docs site (closes #10):** MkDocs documentation with 8 pages — Quickstart,
|
||||
Configuration Reference, Secrets, Path Patterns, Format Strategies, CLI Usage,
|
||||
and Troubleshooting. Material theme, flat URLs, all code snippets verified
|
||||
against implementation. Polished README with badges, features table, format
|
||||
comparison, and project comparison note.
|
||||
|
||||
### Added
|
||||
|
||||
- MP3 format fallback: download manifest fetch, ZIP part download+extraction
|
||||
with .partial tracking and resume, format strategy selector (m4b_mp3_fallback,
|
||||
mp3_only, m4b_only), and `--limit` CLI flag for capped downloads
|
||||
- Project scaffolding: pyproject.toml, package structure, test suite,
|
||||
config module with YAML loading, secrets deep-merge, validation, and
|
||||
defaults. Closes #2.
|
||||
- OAuth2 client with password grant auth and paginated library fetch.
|
||||
Download history tracking with corrupt JSON recovery. Closes #3.
|
||||
- Path resolution with default conditional patterns and custom token
|
||||
substitution. Filesystem-safe component sanitization (illegal chars,
|
||||
control chars, colons). Immutable Book dataclass for typed book metadata.
|
||||
Subdirectory decision logic based on PDF extras or cover art presence.
|
||||
Closes #4.
|
||||
- M4B download pipeline: streaming chunked download with .partial files,
|
||||
atomic rename to .m4b, resume support via HTTP Range header
|
||||
- `fetch_m4b_url()` client method for M4B download URL lookup
|
||||
- `download_book()` orchestration: resolve path → query M4B → download →
|
||||
write history; returns None when book has no M4B available
|
||||
- Full CLI download loop with per-book status, summary counts, and --verbose
|
||||
flag showing config/auth/library/download details
|
||||
- `config.yaml` template and `secrets.yaml` gitignored credentials file
|
||||
- 12 new tests covering M4B query, streaming download, resume, path
|
||||
integration, subdirectory logic, history post-download, skip behavior,
|
||||
and verbose output (109 total)
|
||||
atomic rename to .m4b, resume support via HTTP Range header.
|
||||
Closes #5.
|
||||
- MP3 format fallback: download manifest fetch, ZIP part download+extraction
|
||||
with .partial tracking and resume, format strategy selector
|
||||
(m4b_mp3_fallback, mp3_only, m4b_only), and `--limit` CLI flag for
|
||||
capped downloads. Closes #6.
|
||||
- PDF extras and cover art download: `fetch_pdf_extra_url()` client
|
||||
endpoint, `download_accompanying_files()` with config toggles
|
||||
(`download_extras`, `download_covers`), streaming .partial → atomic
|
||||
rename pattern, non-critical failure handling (warnings only), and
|
||||
output structure verification (subdirectory vs flat layout)
|
||||
output structure verification (subdirectory vs flat layout).
|
||||
12 new tests. Closes #7.
|
||||
- TTY-aware download reporting: rich progress bars with live %/ETA/speed/
|
||||
file size for interactive terminals, plain log lines for pipes/cron,
|
||||
Content-Length-driven total so percentage works from first chunk,
|
||||
per-book failure isolation (one failed book doesn't stop batch),
|
||||
and fatal error immediate-exit before download loop starts
|
||||
- 12 new tests covering PDF URL fetch, cover/PDF download, .partial
|
||||
cleanup, config toggle behavior, failure handling, and directory layout
|
||||
(134 total)
|
||||
|
||||
and fatal error immediate-exit before download loop starts.
|
||||
18 new tests. Closes #8.
|
||||
- Enhanced summary: failed books listed with ISBN/title/reason, skipped
|
||||
books listed with ISBN/title; both plain-text and rich/TTY reporters
|
||||
- Graceful Ctrl+C handling: clean shutdown message instead of traceback,
|
||||
exit code 130 (standard Unix SIGINT convention)
|
||||
- 3 integration tests exercising full run() pipeline: happy path,
|
||||
mixed result (download/skip/fail), fatal auth failure
|
||||
- 12 new tests covering enhanced summary formatting, exit code semantics,
|
||||
graceful shutdown, and integration scenarios (168 total)
|
||||
books listed with ISBN/title; both plain-text and rich/TTY reporters.
|
||||
Graceful Ctrl+C handling: clean shutdown message instead of traceback,
|
||||
exit code 130 (standard Unix SIGINT convention). 3 integration tests.
|
||||
Closes #9.
|
||||
- MkDocs documentation site with 8 pages — Quickstart, Configuration
|
||||
Reference, Secrets, Path Patterns, Format Strategies, CLI Usage, and
|
||||
Troubleshooting. Material theme, flat URLs, all code snippets verified
|
||||
against implementation. Polished README with badges, features table,
|
||||
format comparison, and project comparison note. Closes #10.
|
||||
|
||||
### Fixed
|
||||
|
||||
- **downloader:** Path doubling: `resolve_path()` returns Author/Title but code
|
||||
appended title again, producing nested folders like Title/Title/Title.m4b.
|
||||
Also fix cover download: add Libro.fm headers to httpx client, normalize
|
||||
protocol-relative URLs (//cdn → https://cdn)
|
||||
- Library endpoint key mismatch: API returns "audiobooks" not "books"
|
||||
- M4B endpoint key mismatch: API returns "m4b_url" not "url"
|
||||
- Narrators nested under `audiobook_info.narrators` in API response
|
||||
protocol-relative URLs (//cdn → https://cdn).
|
||||
- Library endpoint key mismatch: API returns "audiobooks" not "books".
|
||||
- M4B endpoint key mismatch: API returns "m4b_url" not "url".
|
||||
- Narrators nested under `audiobook_info.narrators` in API response.
|
||||
- ISBN type mismatch in history lookup: JSON keys are strings but API
|
||||
returns ISBN as integer — added str() coercion in find/is_downloaded
|
||||
- Missing download loop in CLI run() function (listed books but never downloaded)
|
||||
|
||||
### Changed
|
||||
- Initial project scaffolding: pyproject.toml, package structure, test suite
|
||||
- Config module with YAML loading, secrets deep-merge, validation, and defaults
|
||||
- OAuth2 client with password grant auth and paginated library fetch
|
||||
- Download history tracking with corrupt JSON recovery
|
||||
- Path resolution with default conditional patterns and custom token substitution
|
||||
- Filesystem-safe component sanitization (illegal chars, control chars, colons)
|
||||
- Immutable Book dataclass for typed book metadata
|
||||
- Subdirectory decision logic based on PDF extras or cover art presence
|
||||
returns ISBN as integer — added str() coercion in find/is_downloaded.
|
||||
- Missing download loop in CLI run() function (listed books but never downloaded).
|
||||
@@ -10,14 +10,16 @@ No Docker. No JVM. Just Python and go.
|
||||
## Features
|
||||
|
||||
- **Full library sync** — fetches every audiobook in your Libro.fm account with automatic pagination
|
||||
- **Interactive book selection** — pick which books to download with `--select` (checkbox prompt)
|
||||
- **M4B + MP3 formats** — downloads M4B (single file) or MP3 (ZIP parts extracted) with automatic fallback
|
||||
- **Chapter renaming** — MP3 files renamed with chapter titles from the manifest (configurable)
|
||||
- **Resume support** — interrupted downloads pick up where they left off via `.partial` files
|
||||
- **Parallel downloads** — `ThreadPoolExecutor` downloads multiple books simultaneously; configurable via `--workers N` (default 3)
|
||||
- **Cover art & PDF extras** — optional download of cover images and accompanying PDFs
|
||||
- **Customizable output paths** — token-based patterns for organizing your library on disk
|
||||
- **TTY-aware progress** — rich progress bars in your terminal, clean log lines in cron jobs
|
||||
- **Download history** — tracks what's been downloaded so re-runs only fetch new books
|
||||
- **Graceful failure isolation** — one failed book doesn't stop the rest
|
||||
- **Parallel downloads** — `ThreadPoolExecutor` downloads multiple books simultaneously; configurable via `--workers N` (default 3)
|
||||
|
||||
## Quick Start
|
||||
|
||||
@@ -49,8 +51,10 @@ EOF
|
||||
|
||||
# 3. Run
|
||||
librofm-downloader # default: 3 parallel workers
|
||||
librofm-downloader --select # pick books interactively
|
||||
librofm-downloader -w 5 # 5 parallel workers
|
||||
librofm-downloader --workers 1 # sequential (1 worker)
|
||||
librofm-downloader --limit 5 # only download 5 new books
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
@@ -17,6 +17,8 @@ librofm-downloader [OPTIONS]
|
||||
| `--history` | | XDG → CWD search | Path to download history JSON (overrides default search) |
|
||||
| `-v, --verbose` | | off | Print extra detail (URLs, paths, API responses) |
|
||||
| `--limit` N | | `0` (no limit) | Maximum number of books to download |
|
||||
| `--rename-chapters` | | config | Rename extracted MP3 files with chapter titles |
|
||||
| `--select` | | off | Interactive book selection (checkbox prompt) |
|
||||
| `-w, --workers` N | | `3` | Number of parallel download workers (1 = sequential) |
|
||||
|
||||
### --verbose
|
||||
@@ -86,6 +88,67 @@ Resolution order (CLI > config > default):
|
||||
|
||||
Set to `1` for behavior identical to the pre-parallelism sequential mode.
|
||||
|
||||
### --select
|
||||
|
||||
Launch an interactive book selection prompt before downloading:
|
||||
|
||||
```bash
|
||||
# Pick which books to download from a checkbox list
|
||||
librofm-downloader --select
|
||||
```
|
||||
|
||||
**Flow:**
|
||||
|
||||
1. Tool fetches your library and filters already-downloaded books
|
||||
2. A checkbox prompt appears — use **space** to toggle, arrows to navigate, **enter** to confirm
|
||||
3. A confirmation summary shows your selection
|
||||
4. Only selected books are downloaded
|
||||
|
||||
**Behavior notes:**
|
||||
|
||||
- Requires an interactive terminal (TTY). Non-interactive environments (cron, pipes) produce an error and exit
|
||||
- When `--select` is active, `--limit` is superseded — a notice is printed if both are specified
|
||||
- Books are downloaded in the order they appear in your library (selection order is preserved)
|
||||
|
||||
**Row format:**
|
||||
|
||||
```
|
||||
1. The Way of Kings — Brandon Sanderson [Stormlight Archive #1]
|
||||
2. Mistborn — Brandon Sanderson [Mistborn #1]
|
||||
3. Elantris — Brandon Sanderson
|
||||
```
|
||||
|
||||
Series info and number are shown when available.
|
||||
|
||||
### --rename-chapters
|
||||
|
||||
Rename extracted MP3 files with chapter titles from the download manifest:
|
||||
|
||||
```bash
|
||||
# Enable chapter renaming (overrides config)
|
||||
librofm-downloader --rename-chapters
|
||||
```
|
||||
|
||||
**Resolution order (CLI > config > default):**
|
||||
|
||||
1. **`--rename-chapters`** flag on the command line
|
||||
2. **`rename_chapters:`** field in `config.yaml`
|
||||
3. **Default: `true`**
|
||||
|
||||
Only applies when the download pipeline uses MP3 files (`m4b_mp3_fallback` fallback path or `mp3_only` mode). M4B files have built-in chapter metadata and are not affected.
|
||||
|
||||
**Example renaming:**
|
||||
|
||||
```
|
||||
# Before (raw ZIP extraction)
|
||||
01.mp3 02.mp3 03.mp3 04.mp3
|
||||
|
||||
# After (--rename-chapters, default)
|
||||
001 - Opening.mp3 002 - The Arrival.mp3 003 - Revelations.mp3 004 - Departure.mp3
|
||||
```
|
||||
|
||||
Files are zero-padded to match the widest track number (3 digits for 10-999 tracks, 2 for fewer).
|
||||
|
||||
## Exit codes
|
||||
|
||||
| Code | Meaning |
|
||||
|
||||
@@ -72,6 +72,7 @@ All non-credential settings. Safe to commit. **Optional** — if missing, built-
|
||||
| `output_dir` | `string` | `"./audiobooks"` | Base directory for downloaded files. Relative paths resolve from CWD. |
|
||||
| `download_extras` | `boolean` | `true` | Download PDF extras (e.g., maps) when available. |
|
||||
| `download_covers` | `boolean` | `true` | Download cover art (JPEG/PNG) when available. |
|
||||
| `rename_chapters` | `boolean` | `true` | Rename extracted MP3 files with chapter titles from the manifest. Only applies to MP3 pipeline (`m4b_mp3_fallback` fallback or `mp3_only`). |
|
||||
| `workers` | `integer` | `3` | Number of parallel download threads. Set to 1 for sequential mode. Must be ≥ 1. |
|
||||
|
||||
### Full example
|
||||
|
||||
@@ -136,3 +136,21 @@ Summary: 5 downloaded, 2 skipped, 0 failed
|
||||
- The ZIP file is deleted after extraction
|
||||
- Each part supports resume via `Range` headers
|
||||
- Parts are downloaded sequentially within each book
|
||||
|
||||
### Chapter renaming (MP3 only)
|
||||
|
||||
When `rename_chapters` is enabled (default), extracted MP3 files are renamed with chapter titles from the download manifest:
|
||||
|
||||
```
|
||||
# Before (raw extraction)
|
||||
01.mp3 02.mp3 03.mp3
|
||||
|
||||
# After (renamed)
|
||||
001 - Opening.mp3 002 - The Arrival.mp3 003 - Departure.mp3
|
||||
```
|
||||
|
||||
- Files are sorted naturally by numeric prefix before renaming
|
||||
- Zero-padding matches the widest track number
|
||||
- Blank or missing titles fall back to the original filename
|
||||
- Titles are sanitized (illegal characters stripped) via the same function used for path components
|
||||
- Disable in `config.yaml` with `rename_chapters: false`, or override per-run with `--rename-chapters` on the CLI
|
||||
@@ -10,8 +10,11 @@ No Docker. No JVM. Just Python and go.
|
||||
## Features
|
||||
|
||||
- **Full library sync** — fetches every audiobook in your Libro.fm account with automatic pagination
|
||||
- **Interactive book selection** — pick which books to download with `--select` (checkbox prompt)
|
||||
- **M4B + MP3 formats** — downloads M4B (single file) or MP3 (ZIP parts extracted) with automatic fallback
|
||||
- **Chapter renaming** — MP3 files renamed with chapter titles from the manifest (configurable)
|
||||
- **Resume support** — interrupted downloads pick up where they left off via `.partial` files
|
||||
- **Parallel downloads** — configurable worker count (`--workers N`, default 3) with graceful Ctrl+C drain
|
||||
- **Cover art & PDF extras** — optional download of cover images and accompanying PDFs
|
||||
- **Customizable output paths** — token-based patterns for organizing your library on disk
|
||||
- **TTY-aware progress** — rich progress bars in your terminal, clean log lines in cron jobs
|
||||
|
||||
+42
-14
@@ -16,13 +16,9 @@ pip install -e .
|
||||
|
||||
Requires **Python 3.11+**.
|
||||
|
||||
### From source
|
||||
For development (includes pytest):
|
||||
|
||||
```bash
|
||||
git clone https://github.com/AlexKucera/librofm-downloader.git
|
||||
cd librofm-downloader
|
||||
python -m venv .venv
|
||||
source .venv/bin/activate # or .venv\Scripts\activate on Windows
|
||||
pip install -e ".[dev]"
|
||||
```
|
||||
|
||||
@@ -63,6 +59,13 @@ librofm:
|
||||
|
||||
# Whether to download cover art when available
|
||||
download_covers: true
|
||||
|
||||
# Whether to rename MP3 chapter files with titles from the manifest
|
||||
# Only applies when format falls back to MP3 (m4b_mp3_fallback or mp3_only)
|
||||
rename_chapters: true
|
||||
|
||||
# Number of parallel download workers (1 = sequential)
|
||||
workers: 3
|
||||
```
|
||||
|
||||
### secrets.yaml
|
||||
@@ -91,21 +94,37 @@ This:
|
||||
2. Authenticates with Libro.fm via OAuth2 password grant
|
||||
3. Fetches your full library (all pages)
|
||||
4. Skips books already in `download_history.json` (XDG → CWD search)
|
||||
5. Downloads each new book with a progress bar
|
||||
6. Downloads each new book (3 parallel workers by default) with a progress bar
|
||||
7. Records successful downloads to history
|
||||
5. Downloads each new book with up to 3 parallel workers
|
||||
6. Records successful downloads to history
|
||||
|
||||
### Interactive selection
|
||||
|
||||
Pick which books to download from a checkbox list:
|
||||
|
||||
```bash
|
||||
librofm-downloader --select
|
||||
```
|
||||
|
||||
This:
|
||||
|
||||
1. Fetches your library and filters already-downloaded books
|
||||
2. Presents a checkbox prompt (space to toggle, enter to confirm)
|
||||
3. Downloads only the books you selected
|
||||
|
||||
> [!NOTE]
|
||||
> `--select` requires an interactive terminal (TTY). In non-interactive
|
||||
> environments (cron, pipes), the tool exits with an error.
|
||||
|
||||
When `--select` is active, `--limit` is superseded — you control exactly which books are downloaded.
|
||||
|
||||
### First run output (TTY)
|
||||
|
||||
```
|
||||
3 book(s) to download:
|
||||
|
||||
Author One - Book Title One ██████████████████████████ 100.0% 2.1 MB/s 00:01 45.2 MB
|
||||
✓ Book Title One
|
||||
Author Two - Another Book ██████████████████████████ 100.0% 1.8 MB/s 00:02 120.5 MB
|
||||
✓ Another Book
|
||||
Author Three - Third Book ██████████████████████████ 100.0% 2.3 MB/s 00:00 89.1 MB
|
||||
✓ Third Book
|
||||
Brandon Sanderson - The Way of Kings ██████████████████████████ 100.0% 2.1 MB/s 00:01 45.2 MB
|
||||
Author Two - Another Book ██████████████████████████ 100.0% 1.8 MB/s 00:02 120.5 MB
|
||||
Author Three - Third Book ██████████████████████████ 100.0% 2.3 MB/s 00:00 89.1 MB
|
||||
|
||||
Summary: 3 downloaded, 0 skipped, 0 failed
|
||||
```
|
||||
@@ -129,6 +148,14 @@ Completed: Author Two - Another Book
|
||||
Summary: 2 downloaded, 0 skipped, 0 failed
|
||||
```
|
||||
|
||||
### Interrupted downloads
|
||||
|
||||
Press **Ctrl+C** to gracefully stop:
|
||||
|
||||
- First press: in-flight downloads drain to completion, then summary prints
|
||||
- Second press: immediate hard exit
|
||||
- Partial downloads (`.partial` files) resume automatically on next run
|
||||
|
||||
## What gets downloaded?
|
||||
|
||||
Files land under your `output_dir` using this structure:
|
||||
@@ -147,6 +174,7 @@ audiobooks/
|
||||
|
||||
- Books with **cover art or PDF extras** get a subdirectory (`Author/Title/`)
|
||||
- Books without extras are flat files (`Author/Title.m4b`)
|
||||
- When using MP3 format, chapter files are renamed with titles from the manifest (e.g., `001 - Opening.mp3`, `002 - The Arrival.mp3`)
|
||||
- See [Path Patterns](path-patterns.md) for customization options
|
||||
|
||||
## Next steps
|
||||
|
||||
@@ -123,6 +123,31 @@ $ librofm-downloader
|
||||
- Switch to `m4b_mp3_fallback` to get the MP3 version instead
|
||||
- Accept that some books aren't available in M4B format
|
||||
|
||||
## Selection issues
|
||||
|
||||
### "--select requires an interactive terminal"
|
||||
|
||||
**Cause:** You ran `librofm-downloader --select` in a non-interactive environment (cron, piped, SSH without TTY allocation).
|
||||
|
||||
**Behavior:**
|
||||
- Tool exits immediately with exit code **1**
|
||||
- No downloads are attempted
|
||||
|
||||
**Fix options:**
|
||||
- Run in an interactive terminal (local shell, `ssh -t` for TTY allocation)
|
||||
- Use `--limit N` instead for non-interactive capped downloads
|
||||
|
||||
```bash
|
||||
# Non-interactive alternative: just download the first 5 new books
|
||||
librofm-downloader --limit 5
|
||||
```
|
||||
|
||||
### --limit seems ignored when using --select
|
||||
|
||||
**Behavior:** When `--select` is active, `--limit` is superseded — you pick exactly which books to download from the checkbox prompt. A notice is printed confirming this.
|
||||
|
||||
**Fix:** This is intentional. Use `--select` to choose books, or use `--limit` alone for automatic capping.
|
||||
|
||||
## History file problems
|
||||
|
||||
### "Corrupt history file download_history.json: ... Starting with empty history."
|
||||
@@ -226,6 +251,18 @@ Use `--limit` to process smaller batches:
|
||||
librofm-downloader --limit 5
|
||||
```
|
||||
|
||||
Or select specific books interactively:
|
||||
|
||||
```bash
|
||||
librofm-downloader --select
|
||||
```
|
||||
|
||||
Or limit to the first 5 new books:
|
||||
|
||||
```bash
|
||||
librofm-downloader --limit 5
|
||||
```
|
||||
|
||||
## Getting help
|
||||
|
||||
If none of the above covers your issue:
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "librofm-downloader"
|
||||
version = "1.1.0"
|
||||
version = "1.4.0"
|
||||
description = "Download owned audiobooks from your Libro.fm account"
|
||||
readme = "README.md"
|
||||
license = "MIT"
|
||||
|
||||
Reference in new issue
Block a user