feat(downloader): add MP3 fallback pipeline with ZIP download and format strategies (closes #6)
- Add fetch_download_manifest() to client for MP3 manifest endpoint - Add download_zip_part() for streaming ZIP download, .partial tracking, resume via Range header, auto-extraction and cleanup - Refactor download_book() with format_strategy param: m4b_mp3_fallback, mp3_only, m4b_only - Add --limit N CLI flag to cap downloads for testing - Wire config.format through CLI to download_book() - 12 new tests (122 total), all passing
This commit is contained in:
1 parent
8d6cf021c7
commit
3177aaf18e
9 files changed
+928
-23
No files matched your search
@@ -137,3 +137,42 @@ class LibroFmClient:
|
||||
resp.raise_for_status()
|
||||
data = resp.json()
|
||||
return data["m4b_url"]
|
||||
|
||||
def fetch_download_manifest(
|
||||
self,
|
||||
isbn: str,
|
||||
transport: httpx.BaseTransport | None = None,
|
||||
) -> dict:
|
||||
"""Fetch the MP3 download manifest for a given ISBN.
|
||||
|
||||
Args:
|
||||
isbn: The ISBN of the audiobook.
|
||||
transport: Optional httpx transport override for testing.
|
||||
|
||||
Returns:
|
||||
Dict with ``parts`` (list of {url, name}) and
|
||||
``tracks`` (list of {number, chapter_title}).
|
||||
|
||||
Raises:
|
||||
AuthError: If not authenticated.
|
||||
M4BUnavailableError: If the book has no MP3 format available (404).
|
||||
"""
|
||||
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("/api/v10/download-manifest", params={"isbn": isbn})
|
||||
|
||||
if resp.status_code == 404:
|
||||
raise M4BUnavailableError(f"MP3 manifest not available for ISBN {isbn}")
|
||||
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
Reference in new issue
Block a user