refactor(download): remove ProviderCore/download.py, move sanitize_filename to SYS.utils, replace callers to use API.HTTP.HTTPClient
This commit is contained in:
@@ -18,7 +18,7 @@ import requests
|
||||
|
||||
from API.HTTP import HTTPClient
|
||||
from ProviderCore.base import Provider, SearchResult
|
||||
from ProviderCore.download import download_file, sanitize_filename
|
||||
from SYS.utils import sanitize_filename
|
||||
from SYS.cli_syntax import get_field, get_free_text, parse_query
|
||||
from SYS.logger import debug, log
|
||||
from SYS.utils import unique_path
|
||||
@@ -1541,21 +1541,25 @@ class OpenLibrary(Provider):
|
||||
except Exception:
|
||||
pass
|
||||
out_path = unique_path(output_dir / f"{safe_title}.pdf")
|
||||
ok = download_file(
|
||||
pdf_url,
|
||||
out_path,
|
||||
session=self._session,
|
||||
progress_callback=(
|
||||
(
|
||||
lambda downloaded, total, label:
|
||||
progress_callback("bytes", downloaded, total, label)
|
||||
) if progress_callback is not None else None
|
||||
),
|
||||
)
|
||||
if ok:
|
||||
return out_path
|
||||
log("[openlibrary] Direct download failed", file=sys.stderr)
|
||||
return None
|
||||
try:
|
||||
with HTTPClient(timeout=30.0) as client:
|
||||
path = client.download(
|
||||
pdf_url,
|
||||
str(out_path),
|
||||
chunk_size=1024 * 256,
|
||||
progress_callback=(
|
||||
(lambda downloaded, total: progress_callback("bytes", downloaded, total, safe_title))
|
||||
if progress_callback is not None
|
||||
else None
|
||||
),
|
||||
)
|
||||
if path and path.exists():
|
||||
return path
|
||||
log("[openlibrary] Direct download failed", file=sys.stderr)
|
||||
return None
|
||||
except Exception:
|
||||
log("[openlibrary] Direct download failed", file=sys.stderr)
|
||||
return None
|
||||
|
||||
# 2) Borrow flow (credentials required).
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user