87 Commits
Author SHA1 Message Date
AlexKucera 94ce1dfeec Merge branch 'release/1.4.0' into main 2026-06-06 18:29:13 +02:00
AlexKucera 50d5a7b0bc Merge branch 'release/1.4.0' into main 2026-06-06 18:28:46 +02:00
AlexKucera 507fbc3204 docs: add 1.1-1.4 features to MkDocs and README
Cover parallel downloads, interactive selection (--select),
chapter renaming (--rename-chapters), XDG config paths,
Ctrl+C handling, and thread-safe history across all docs:
index, quickstart, configuration, cli-usage, format-strategies,
troubleshooting, and README.
2026-06-06 18:27:23 +02:00
AlexKucera e2fa3377f5 docs(changelog): reorganize entries by version tags
Restructure CHANGELOG.md to match git tags (1.0.0 through 1.4.0).
Remove Unreleased section (all changes are tagged). Sort entries
into Added/Fixed/Refactored/Documentation sections per version.
Add standard Keep a Changelog header.
2026-06-06 18:17:07 +02:00
AlexKucera 11d677fb24 Merge pull request #49 from AlexKucera/feature/chooseBooks
Enables interactive book selection via --select
2026-06-06 18:09:50 +02:00
AlexKucera b9d90b7618 fix(sync_run): show limit-bypass notice regardless of verbose
The --limit-superseded message was only printed when verbose=True,
so users running --select --limit 5 without -v got no indication
their flag was silently ignored. Make the notice unconditional.
2026-06-06 17:33:31 +02:00
AlexKucera 4e25fb27df fix(sync_run): check stdin not stdout for TTY guard
The --select TTY guard used sys.stdout.isatty(), but interactive
prompts read from stdin. This caused two failure modes:

- Redirecting stdout (e.g. | tee log.txt) blocked --select even
  though the keyboard was available
- With stdin piped in CI, stdout could still be a TTY, allowing
  the prompt to proceed and block forever on absent input
2026-06-06 17:30:48 +02:00
AlexKucera 77712951d0 docs(orchestrator): fix raw_books type annotation and changelog prose
The raw_books parameter accepts list[dict | Book] since the
selector wiring (issue #48), but the annotation still said
list[dict]. Also restore the missing opening sentence of the
selector changelog entry that was truncated.
2026-06-06 17:28:44 +02:00
AlexKucera fa1543e3d7 feat(sync_run): wire --select into download pipeline
Replace select_mode stub with real selection pipeline:
- TTY guard: non-interactive terminals get fatal_error exit
- Convert filtered dicts to Books via from_library_row()
- Call select_books(), pass selected Books to orchestrator
- Orchestrator accepts pre-converted Book objects (isinstance check)
- --limit bypassed when --select is active, with verbose note
- Remove "[not implemented]" from --select help text

Closes #48
2026-06-06 12:13:56 +02:00
AlexKucera 0d555e4628 Merge remote-tracking branch 'origin/feature/chooseBooks' into feature/chooseBooks 2026-06-06 11:55:16 +02:00
AlexKucera 37f10f9b49 feat(selector): add interactive book selection module
New selector.py with select_books() and _format_row().
Questionary checkbox prompt, all unchecked by default,
confirmation summary + y/N, original order preservation,
Ctrl+C propagation via unsafe_ask(). 9 tests.

Closes #47
2026-06-06 11:55:08 +02:00
AlexKucera 922e7fe6bb feat(selector): add interactive book selection module
New selector.py with select_books() and _format_row().
Questionary checkbox prompt, all unchecked by default,
confirmation summary + y/N, original order preservation,
Ctrl+C propagation via unsafe_ask(). 9 tests.

Closes #47
2026-06-06 11:53:03 +02:00
AlexKucera 48ec81d92d Merge pull request #46 from AlexKucera/feature/rename-mp3
Adds MP3 Chapter Renaming and Refactors Core Architecture
1.3.0
2026-06-06 09:52:08 +02:00
AlexKucera 8619b400f2 docs(downloader): note rename_chapters param shadowing
Add inline comment in _finalize_download() explaining that the
rename_chapters bool param shadows the module-level rename_chapters()
function. This is safe because the actual call is delegated to
_rename_and_log(), which has its own clean scope.
2026-06-06 09:32:15 +02:00
AlexKucera 8acea390e6 fix(downloader): correct resume progress and avoid httpx private API
Two bugs found by code review:

1. Progress bar exceeds 100% on resumed downloads because
   Content-Length from a Range response covers only remaining
   bytes. Now adds resume_from for the true total.

2. session.transport reached into httpx.Client._transport, a
   private attribute that may break on httpx upgrades. Transport
   is now stored at construction time instead.
2026-06-06 09:28:33 +02:00
AlexKucera 2466ef5fa8 fix(downloader): add missing Callable import
Callable was used in string annotations but never imported,
causing NameError with typing.get_type_hints().
2026-06-06 09:04:48 +02:00
AlexKucera 1fcf8c6644 refactor(sync-run): consolidate SyncRunResult via composition
SyncRunResult now wraps OrchestratorResult instead of duplicating
its 6 fields. Delegating properties preserve the public interface,
eliminating field-by-field copy code in the bridge between
orchestrator and sync_run.

Closes #45
2026-06-06 08:14:48 +02:00
AlexKucera 5cc3fce0a3 refactor(sync-run): add DI seams and extract helpers
Add 4 injectable parameters (session, history, reporter,
download_all_fn) to sync_run() with backward-compatible defaults.
Extract _print_verbose_config() and _resolve_history_path() helpers.
Refactor _make_download_fn() to take explicit params instead of
closing over enclosing scope.

Tests can now pass fakes via parameters instead of mock.patch.

Closes #44
2026-06-05 22:28:37 +02:00
AlexKucera a66c98d973 refactor(tests): reorganize test files to match production modules (#43)
Delete 13 duplicate path test classes from test_downloader.py
(already exist in test_path.py). Move 2 sync_run integration
classes from test_progress.py to test_sync_run.py. Remove
duplicate TestParallelProgressCallbackWiring class. Rescue orphaned
3-book interleaved plain text test with proper class wrapper.

Net -469 test lines. Each test file now tests exactly one module.
2026-06-05 19:48:46 +02:00
AlexKucera bf7e47422f refactor(downloader): extract _finalize_download() from format branches
The three format-strategy blocks in download_book() each duplicated
the same post-download success logic: rename chapters (MP3 only),
download accompanying files, and return a DownloadResult. Extract
a single _finalize_download() helper so each branch reduces to:
attempt download → return _finalize_download(...).

Adding a new format strategy now requires only the download attempt
plus one call to the existing success helper.

Closes #42
2026-06-05 19:12:09 +02:00
AlexKucera fcdba333d1 refactor(downloader): extract _stream_to_file() helper
Eliminate the ~30-line duplicated chunked-download loop across
download_m4b(), download_zip_part(), _download_cover(), and
_download_pdf() by extracting a shared _stream_to_file() private
helper. Each caller is now a thin wrapper that delegates streaming
to the helper then performs its own post-processing step.

5 new TDD tests covering fresh download, resume, cancel mid-stream,
progress callback with content-length, and HTTP error propagation.
224 total tests pass. Net -22 lines in downloader.py.

Closes #41
2026-06-05 19:05:23 +02:00
AlexKucera d55fa9acbb chore(gitnexus): update code intelligence stats
The GitNexus index was regenerated to reflect recent code modifications.
2026-06-05 18:53:03 +02:00
AlexKucera bcc1f7efee refactor(history): relocate _write_history() function (#40)
Move the `_write_history()` function from `downloader.py` to `history.py`. This refactoring separates persistence logic from download orchestration, ensuring `downloader.py` focuses solely on its core responsibility.
2026-06-05 18:52:50 +02:00
AlexKuceraandClaude Opus 4.6 2930d163b2 refactor(reporters): remove cancel_event from progress reporters
Thread cancel_event explicitly through the parameter chain
(sync_run closure → download_book() → streaming calls) instead of
stashing it on reporter objects as shared state. Remove the
cancel_event attribute from both PlainTextReporter and
ProgressReporter — cancellation is not a reporting concern.

Closes #39

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-05 18:45:27 +02:00
AlexKucera caca930c7c refactor(session): expose public transport property on LibroFmSession
Add @property transport getter that returns the underlying httpx
transport, replacing the single call site in downloader.py that
reached through session._client._transport. Encapsulates private
attribute access behind a public interface. 2 new tests.

Closes #38
2026-06-05 18:36:03 +02:00
AlexKucera de4c08cfd0 refactor(session): excise deprecated client.py shim and test_client.py
Remove the 32-line re-export shim (Issue #27 leftover) and its 588-line
duplicate test file. Migrate 4 unique rate-limiter tests into
test_session.py. Zero production imports of client.py confirmed.
Net: -337 lines dead code, 425→413 tests collected.

Closes #37
2026-06-05 18:32:57 +02:00
AlexKucera a8ff0b2134 test(downloader): add rename_chapters pipeline integration tests (Issue #35)
Add 4 end-to-end integration tests proving rename_chapters() fires
correctly through the full download pipeline for each format strategy,
and is properly suppressed when disabled.

Closes #35
2026-06-05 17:55:58 +02:00
AlexKucera a415fc37f5 feat(downloader): wire rename_chapters into download pipeline
_download_mp3() returns (output_dir, tracks) tuple so manifest
track data flows to callers. download_book() accepts rename_chapters
kwarg; after MP3 extraction succeeds, calls rename_chapters() via
_rename_and_log() helper which also reports to user via reporter.

Both PlainTextReporter and RichProgressReporter show visible feedback:
'Renamed N chapter(s) for Book → example.mp3'. sync_run.py closure
threads resolved_rename_chapters flag through to download_book().

6 new integration tests covering all format strategies and edge cases.
~229 total tests. Closes #34.
2026-06-05 17:47:10 +02:00
AlexKucera af5ad4953c feat(config): add rename_chapters field, CLI flag, and 3-layer resolution
Add rename_chapters boolean config field following the established
pattern from download_extras/download_covers. Config defaults to
True; YAML supports explicit false; --rename-chapters CLI flag forces
True overriding config. Threaded through sync_run() with resolved value
ready for pipeline wiring in slice 3.

Closes #33
2026-06-05 17:15:16 +02:00
AlexKuceraandClaude Opus 4.6 b6df4e3a9b feat(downloader): add rename_chapters for MP3 chapter title renaming
Add standalone rename_chapters(output_dir, tracks, book_title) -> int
function that renames extracted MP3 files to include chapter titles
from the Libro.fm download manifest. Features: natural sort by numeric
prefix, auto zero-padding from track count, null/blank title fallback
to "Chapter N", sanitization via existing sanitize(). 11 tests, all
passing. Closes #32.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-05 15:26:04 +02:00
AlexKucera c96dd3cce3 Merge branch 'feature/improve-codebase' into develop 2026-06-05 14:52:49 +02:00
AlexKucera f371152166 refactor(cli): extract sync_run pipeline and slim CLI to adapter (#31)
Move entire download pipeline from cli.run() into standalone
sync_run() in new sync_run.py module. Introduce SyncRunResult
frozen dataclass as public return type with fatal_error field
for exit-code translation. Slim cli.py from 252→65 lines to a
thin argparse→exit adapter that only calls sync_run().

Migrate 35 pipeline tests from test_cli.py to test_sync_run.py
(43 total). CLI tests now only patch sync_run (no internal
collaborators). Add select_mode stub for ADR #6 branch point.
Update test_progress.py patch targets to sync_run module.
374 tests pass.
2026-06-05 14:52:00 +02:00
AlexKucera 1f46467f2c refactor(progress): return bound callable from start_download (#30)
start_download(book) now returns a per-book bound callable
instead of raw task_id. Task identity is fully internal to
progress.py — no caller ever sees or passes task_id.

- Orchestrator: removed closure pattern, now threads
  progress_cb = start_download(book) directly
- downloader: download_book() accepts optional progress= kwarg,
  uses it when provided (falls back to reporter.update)
- cli.py: forwards progress kwarg through _download_fn
- Public update() drops task_id param; bound callable calls
  _progress.update(task_id_internal) directly

382 tests pass (+11 new), 6/6 AC met.
2026-06-05 11:58:04 +02:00
AlexKuceraandClaude Opus 4.6 9ac581e5b7 refactor(downloader): shrink download_book to 4 domain params
Replace 9-parameter signature (book, client, output_base, history,
format_strategy, config, transport, progress, cancel_event) with
4 domain-aligned parameters (book, session, plan, reporter) that
return a frozen DownloadResult dataclass.

Key changes:
- Add DownloadResult(status, path, format, error) frozen dataclass
- Add format_strategy field to OutputPlan
- Move history writing from download_book() to caller (cli closure)
- Remove config param from download_accompanying_files()
- Wire cancel_event through reporter.cancel_event attribute
- Extract transport from session._client._transport

Closes #29

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-05 07:34:01 +02:00
AlexKucera 0ee8186361 feat(path): add OutputPlan dataclass for centralized path resolution
Introduce frozen OutputPlan dataclass carrying all resolved file paths
(audio, partial, cover, PDF) for a single Book. Add resolve_output_plan()
function that centralizes every path computation so download functions
receive pre-resolved Paths instead of computing them inline.

Refactor download_book() to consume plan.audio_path (eliminating
duplicated sanitize(title).m4b logic), download_accompanying_files() to
accept an OutputPlan instead of raw output_dir, and _download_cover/_download_pdf
to accept optional expected_path parameter.

Closes #28
2026-06-04 15:47:33 +02:00
AlexKucera fe7642be7c Restored CONTEXT.md
Subagents overwrote this with wrong artefacts.
2026-06-04 15:31:24 +02:00
AlexKucera cbb8992acc docs(changelog): add #27 session rename to Unreleased 2026-06-04 15:27:33 +02:00
AlexKucera 006a7561ce refactor(session): rename LibroFmClient → LibroFmSession
Relocate API client from client.py to session.py with constructor
injection. Transport is now passed once at construction time
instead of per-method, eliminating 5 redundant httpx.Client
creations per session lifecycle.

- New session.py: LibroFmSession with shared _client, transport
  injected at construction, auth headers set once after
  authenticate()
- Old client.py: deprecated re-export shim (LibroFmClient alias)
- All endpoint signatures slimmed to ≤3 params (removed
  transport= from authenticate/fetch_library/fetch_m4b_url/
  fetch_download_manifest/fetch_pdf_extra_url)
- Updated all source imports (cli.py, downloader.py) and test
  files (test_client, test_downloader, test_cli, test_progress)
- 17 new TDD tests in test_session.py

Closes #27
2026-06-04 15:27:11 +02:00
AlexKucera fb219be248 refactor: extract book.py and path.py from downloader monolith
Move Book dataclass + from_library_row() into dedicated book.py.
Extract sanitize/resolve_path/needs_subdirectory into path.py.
Hard-cut import migration across 7 source+test files. 79 new tests.

Closes #26
2026-06-04 14:18:40 +02:00
AlexKucera 323fbf76fd docs(prd): Introduce PRD for module depth & domain alignment
This document outlines a plan to refactor the codebase to address shallow modules and leaky interfaces. It defines new deep module boundaries to improve testability, maintainability, and extensibility for future development.
2026-06-04 13:47:08 +02:00
AlexKucera ef876fb912 Merge branch 'feature/parallel-downloads' into develop 1.2.0 2026-06-04 13:44:27 +02:00
AlexKucera 75a6eb61ea fix(progress): wire task_id through parallel progress callback
In parallel download mode, all progress updates went to the same
(most recently started) bar because task_id was never threaded from
start_download() to the update callback. Create per-book closure in
orchestrator that binds task_id, pass through cli._download_fn as
optional kwarg. 3 new regression tests. 259 total.
2026-06-04 13:26:38 +02:00
AlexKucera 83254750e6 cleanup: moved config to ~/.config/librofm-downloader 2026-06-04 13:12:43 +02:00
AlexKucera 3dcae24d34 fix(orchestrator): Ctrl+C hangs and threading shutdown traceback
Python ThreadPoolExecutor workers cannot be killed when blocked in HTTP
I/O. Previous approach of waiting for graceful cancellation via
shutdown(wait=True) caused infinite hangs, and re-raising KeyboardInterrupt
still triggered Python's _python_exit thread-join cleanup on exit.

Replace with hard-exit strategy: first Ctrl+C marks all unfinished books
(active + pending) as cancelled, prints summary, returns partial result
with interrupted=True. CLI then calls os._exit(130) to bypass thread
cleanup entirely. Second Ctrl+C hard-exits immediately.

Also fixes: books_with_index[idx][0] returning int index instead of
Book object (AttributeError on summary), empty CancelledError reason
strings, missing cancel_event wiring through download_book->download_m4b
call chain, and corrupted test body from earlier edit collision.

256 tests pass.
2026-06-04 13:10:10 +02:00
AlexKucera b7cae793df docs(gitnexus): update GitNexus index stats
Refreshes the project's GitNexus code intelligence index statistics
in documentation to accurately reflect the current codebase.
This update incorporates recent development, likely from the parallel
downloads feature, which increased symbols, relationships, and
execution flows. Also adds a missing newline to CLAUDE.md.
2026-06-04 12:18:27 +02:00
AlexKucera ae1458a725 docs: prioritize source installation in quick start
Update quick start guides (README, MkDocs) to recommend installing from source via `git clone` and `venv`. This ensures users access the latest development features and promotes a consistent setup. The "Just pip install" phrase was also broadened to "Just Python".
2026-06-04 12:18:13 +02:00
AlexKuceraandClaude Opus 4.6 2a1a404350 fix(cli): remove redundant per-book verbose print in parallel downloads
The _download_fn closure printed ⬇ title, authors, and narrators for
every book inside the parallel download loop. This was fine for
sequential mode but became redundant when rich ProgressReporter bars
were added — causing a triple-display: progress bars at 0%, then full
book details with expanded narrators, then live progress updates.

Progress bars already convey author+title, so the extra block was pure
noise. Verbose mode still shows config, paths, auth status, summary,
and the done separator.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-06-04 11:32:16 +02:00
AlexKucera 722413a45b fix(cli): wire verbose flag through entry point
Extract argparse into main() and point console script at it.
The -v/--verbose flag was dead because the entry point called
run() directly, bypassing the __main__ argparse block entirely.
2026-06-04 11:20:02 +02:00
AlexKucera c4ee24bb28 fix(merge): resolve develop merge conflict leftovers
Remove duplicate load_config stub that was injected into
_resolve_config_file's docstring in config.py (SyntaxError
on import). Add workers attribute to 3 TestCLIHistoryResolution
mocks — develop added workers resolution in cli.py but the
existing tests didn't mock it, causing TypeError.
2026-06-04 11:10:32 +02:00
AlexKucera 44fc544a3e Merge branch 'develop' into feature/parallel-downloads 2026-06-04 11:04:19 +02:00