re
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
@@ -319,6 +319,18 @@ class Download_File(Cmdlet):
|
||||
except Exception:
|
||||
provider_name = None
|
||||
|
||||
# Heuristic: LibGen often uses landing pages like edition.php/file.php.
|
||||
# These should never be treated as direct file URLs.
|
||||
if not provider_name:
|
||||
try:
|
||||
p = urlparse(str(url))
|
||||
h = (p.hostname or "").strip().lower()
|
||||
path = (p.path or "").strip().lower()
|
||||
if "libgen" in h and any(x in path for x in ("/edition.php", "/file.php", "/ads.php", "/get.php", "/series.php")):
|
||||
provider_name = "libgen"
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if provider_name and get_provider is not None and SearchResult is not None:
|
||||
# OpenLibrary URLs should be handled by the OpenLibrary provider.
|
||||
if provider_name == "openlibrary":
|
||||
@@ -391,11 +403,19 @@ class Download_File(Cmdlet):
|
||||
progress.clear_status()
|
||||
|
||||
if downloaded_path:
|
||||
tags_hint: Optional[List[str]] = None
|
||||
try:
|
||||
sr_tags = getattr(sr, "tag", None)
|
||||
if isinstance(sr_tags, set) and sr_tags:
|
||||
tags_hint = sorted([str(t) for t in sr_tags if t])
|
||||
except Exception:
|
||||
tags_hint = None
|
||||
|
||||
self._emit_local_file(
|
||||
downloaded_path=Path(downloaded_path),
|
||||
source=str(url),
|
||||
title_hint=title_hint,
|
||||
tags_hint=None,
|
||||
tags_hint=tags_hint,
|
||||
media_kind_hint="book",
|
||||
full_metadata=sr.full_metadata,
|
||||
provider_hint="openlibrary",
|
||||
@@ -472,14 +492,42 @@ class Download_File(Cmdlet):
|
||||
except Exception:
|
||||
downloaded_path = None
|
||||
|
||||
# Refuse to fall back to direct-download for LibGen landing pages.
|
||||
# This prevents saving HTML (e.g. edition.php) as a bogus file.
|
||||
if (not downloaded_path) and str(provider_name).lower() == "libgen":
|
||||
raise DownloadError("LibGen URL did not resolve to a downloadable file")
|
||||
|
||||
if downloaded_path:
|
||||
tags_hint: Optional[List[str]] = None
|
||||
full_md: Optional[Dict[str, Any]] = None
|
||||
title_hint = Path(str(downloaded_path)).stem
|
||||
media_kind_hint = "file"
|
||||
|
||||
if str(provider_name).lower() == "libgen":
|
||||
media_kind_hint = "book"
|
||||
try:
|
||||
sr_tags = getattr(sr, "tag", None)
|
||||
if isinstance(sr_tags, set) and sr_tags:
|
||||
tags_hint = sorted([str(t) for t in sr_tags if t])
|
||||
except Exception:
|
||||
tags_hint = None
|
||||
|
||||
try:
|
||||
if isinstance(getattr(sr, "full_metadata", None), dict):
|
||||
full_md = sr.full_metadata
|
||||
t = str(full_md.get("title") or "").strip()
|
||||
if t:
|
||||
title_hint = t
|
||||
except Exception:
|
||||
full_md = None
|
||||
|
||||
self._emit_local_file(
|
||||
downloaded_path=Path(downloaded_path),
|
||||
source=str(url),
|
||||
title_hint=Path(str(downloaded_path)).stem,
|
||||
tags_hint=None,
|
||||
media_kind_hint="file",
|
||||
full_metadata=None,
|
||||
title_hint=title_hint,
|
||||
tags_hint=tags_hint,
|
||||
media_kind_hint=media_kind_hint,
|
||||
full_metadata=full_md,
|
||||
provider_hint=str(provider_name),
|
||||
progress=progress,
|
||||
config=config,
|
||||
@@ -600,6 +648,7 @@ class Download_File(Cmdlet):
|
||||
# If this looks like a provider item and providers are available, prefer provider.download()
|
||||
downloaded_path: Optional[Path] = None
|
||||
attempted_provider_download = False
|
||||
provider_sr = None
|
||||
if table and get_search_provider and SearchResult:
|
||||
provider = get_search_provider(str(table), config)
|
||||
if provider is not None:
|
||||
@@ -612,6 +661,7 @@ class Download_File(Cmdlet):
|
||||
)
|
||||
debug(f"[download-file] Downloading provider item via {table}: {sr.title}")
|
||||
downloaded_path = provider.download(sr, final_output_dir)
|
||||
provider_sr = sr
|
||||
|
||||
# OpenLibrary: if provider download failed, do NOT try to download the OpenLibrary page HTML.
|
||||
if downloaded_path is None and attempted_provider_download and str(table or "").lower() == "openlibrary":
|
||||
@@ -693,6 +743,30 @@ class Download_File(Cmdlet):
|
||||
log(f"Cannot download item (no provider handler / unsupported target): {title or target}", file=sys.stderr)
|
||||
continue
|
||||
|
||||
# Allow providers to add/enrich tags and metadata during download.
|
||||
if str(table or "").lower() == "libgen" and provider_sr is not None:
|
||||
try:
|
||||
sr_tags = getattr(provider_sr, "tag", None)
|
||||
if tags_list is None and isinstance(sr_tags, set) and sr_tags:
|
||||
tags_list = sorted([str(t) for t in sr_tags if t])
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
sr_md = getattr(provider_sr, "full_metadata", None)
|
||||
if isinstance(sr_md, dict) and sr_md:
|
||||
full_metadata = sr_md
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
if isinstance(full_metadata, dict):
|
||||
t = str(full_metadata.get("title") or "").strip()
|
||||
if t:
|
||||
title = t
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
self._emit_local_file(
|
||||
downloaded_path=downloaded_path,
|
||||
source=str(target) if target else None,
|
||||
|
||||
Reference in New Issue
Block a user