feat(downloader): add PDF extras and cover art download (closes #7)

Add accompanying file download pipeline: PDF extras via new
client.fetch_pdf_extra_url() endpoint, cover art from existing
book.cover_url, both using streaming .partial -> atomic rename pattern.

Config toggles (download_extras, download_covers) control which files
are downloaded. Failures log warnings only -- never mark a book as
failed. Wired into all 3 format strategy paths in download_book().

Output structure: books with extras create subdirectories containing
audio + PDFs + cover; books without extras output audio as leaf file.
12 new tests (134 total), 11/11 acceptance criteria met.
This commit is contained in:
AlexKucera committed 2026-06-03 14:00:55 +02:00
1 parent 2a0b43aca9
commit aceaece504
8 files changed
+639 -3

No files matched your search

+37
View File
@@ -176,3 +176,40 @@ class LibroFmClient:
resp.raise_for_status()
return resp.json()
def fetch_pdf_extra_url(
self,
isbn: str,
filename: str,
transport: httpx.BaseTransport | None = None,
) -> str:
"""Fetch the PDF extra download URL for a given ISBN and filename.
Args:
isbn: The ISBN of the audiobook.
filename: The name of the PDF file to fetch.
transport: Optional httpx transport override for testing.
Returns:
The CDN URL string for the PDF file.
Raises:
AuthError: If not authenticated.
"""
if not self._access_token:
raise AuthError("Not authenticated. Call authenticate() first.")
headers = {**self.DEFAULT_HEADERS, "Authorization": f"Bearer {self._access_token}"}
client = httpx.Client(
base_url=self._base_url,
headers=headers,
timeout=self._timeout,
transport=transport,
)
resp = client.get(f"/api/v10/library/{isbn}/pdf_extra_url", params={"filename": filename})
resp.raise_for_status()
data = resp.json()
return data["pdf_url"]