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>
This commit is contained in:
AlexKuceraandClaude Opus 4.6 committed 2026-06-05 07:34:01 +02:00
1 parent 0ee8186361
commit 9ac581e5b7
11 files changed
+492 -174

No files matched your search

+2
View File
@@ -19,6 +19,7 @@ class PlainTextReporter:
def __init__(self, stdout: TextIO | None = None) -> None:
self._out: TextIO = stdout or sys.stdout
self.cancel_event: threading.Event | None = None
def start_download(self, book, total_bytes: int = 0) -> None:
"""Log download start with author, title, and file size."""
@@ -91,6 +92,7 @@ class ProgressReporter:
# Per-book identity mapping for concurrent downloads
self._tasks: dict[int, object] = {} # task_id -> book
self._book_ids: dict[int, int] = {} # id(book) -> task_id
self.cancel_event: threading.Event | None = None
def start_download(self, book, total_bytes: int = 0) -> int:
"""Start a progress bar for this book's download.