dfslkjelf
This commit is contained in:
@@ -36,11 +36,13 @@ class Download_File(Cmdlet):
|
||||
super().__init__(
|
||||
name="download-file",
|
||||
summary="Download files via HTTP or provider handlers",
|
||||
usage="download-file <url> [options] OR @N | download-file [options]",
|
||||
usage="download-file <url> [-path DIR] [options] OR @N | download-file [-path DIR] [options]",
|
||||
alias=["dl-file", "download-http"],
|
||||
arg=[
|
||||
CmdletArg(name="output", type="string", alias="o", description="Output directory (overrides defaults)"),
|
||||
SharedArgs.URL,
|
||||
SharedArgs.PATH,
|
||||
# Prefer -path for output directory to match other cmdlets; keep -output for backwards compatibility.
|
||||
CmdletArg(name="-output", type="string", alias="o", description="(deprecated) Output directory (use -path instead)"),
|
||||
|
||||
],
|
||||
detail=["Download files directly via HTTP without yt-dlp processing.", "For streaming sites, use download-media."],
|
||||
@@ -50,10 +52,6 @@ class Download_File(Cmdlet):
|
||||
|
||||
def run(self, result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
"""Main execution method."""
|
||||
stage_ctx = pipeline_context.get_stage_context()
|
||||
in_pipeline = stage_ctx is not None and getattr(stage_ctx, "total_stages", 1) > 1
|
||||
if in_pipeline and isinstance(config, dict):
|
||||
config["_quiet_background_output"] = True
|
||||
return self._run_impl(result, args, config)
|
||||
|
||||
def _run_impl(self, result: Any, args: Sequence[str], config: Dict[str, Any]) -> int:
|
||||
@@ -169,7 +167,47 @@ class Download_File(Cmdlet):
|
||||
log(f"Error processing {url}: {e}", file=sys.stderr)
|
||||
|
||||
# 2) Provider item downloads (piped results)
|
||||
# Expand provider "folder" rows into their contained files when possible (e.g., AllDebrid magnets).
|
||||
expanded_items: List[Any] = []
|
||||
for item in piped_items:
|
||||
try:
|
||||
table = get_field(item, "table")
|
||||
media_kind = get_field(item, "media_kind")
|
||||
full_metadata = get_field(item, "full_metadata")
|
||||
target = get_field(item, "path") or get_field(item, "url")
|
||||
|
||||
if str(table or "").lower() == "alldebrid" and str(media_kind or "").lower() == "folder":
|
||||
magnet_id = None
|
||||
if isinstance(full_metadata, dict):
|
||||
magnet_id = full_metadata.get("magnet_id")
|
||||
if magnet_id is None and isinstance(target, str) and target.lower().startswith("alldebrid:magnet:"):
|
||||
try:
|
||||
magnet_id = int(target.split(":")[-1])
|
||||
except Exception:
|
||||
magnet_id = None
|
||||
|
||||
if magnet_id is not None and get_search_provider is not None:
|
||||
provider = get_search_provider("alldebrid", config)
|
||||
if provider is not None:
|
||||
try:
|
||||
files = provider.search("*", limit=10_000, filters={"view": "files", "magnet_id": int(magnet_id)})
|
||||
except Exception:
|
||||
files = []
|
||||
|
||||
# If the magnet isn't ready, provider.search returns a single not-ready folder row.
|
||||
if files and len(files) == 1 and getattr(files[0], "media_kind", "") == "folder":
|
||||
detail = getattr(files[0], "detail", "")
|
||||
log(f"[download-file] AllDebrid magnet {magnet_id} not ready ({detail or 'unknown'})", file=sys.stderr)
|
||||
else:
|
||||
for sr in files:
|
||||
expanded_items.append(sr.to_dict() if hasattr(sr, "to_dict") else sr)
|
||||
continue
|
||||
|
||||
expanded_items.append(item)
|
||||
except Exception:
|
||||
expanded_items.append(item)
|
||||
|
||||
for item in expanded_items:
|
||||
try:
|
||||
table = get_field(item, "table")
|
||||
title = get_field(item, "title")
|
||||
@@ -226,8 +264,12 @@ class Download_File(Cmdlet):
|
||||
from cmdlet.search_provider import CMDLET as _SEARCH_PROVIDER_CMDLET
|
||||
# Use plain title text (LibGen mirrors can be finicky with fielded query prefixes).
|
||||
fallback_query = title_text
|
||||
exec_fn = getattr(_SEARCH_PROVIDER_CMDLET, "exec", None)
|
||||
if not callable(exec_fn):
|
||||
log("[download-file] search-provider cmdlet unavailable; cannot run LibGen fallback search", file=sys.stderr)
|
||||
continue
|
||||
|
||||
ret = _SEARCH_PROVIDER_CMDLET.exec(
|
||||
ret = exec_fn(
|
||||
None,
|
||||
["-provider", "libgen", "-query", fallback_query],
|
||||
config,
|
||||
@@ -243,7 +285,10 @@ class Download_File(Cmdlet):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return int(ret)
|
||||
try:
|
||||
return int(ret) # type: ignore[arg-type]
|
||||
except Exception:
|
||||
return 1
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -259,7 +304,14 @@ class Download_File(Cmdlet):
|
||||
log("[download-file] Refusing to download LibGen landing page (expected provider to resolve file link)", file=sys.stderr)
|
||||
continue
|
||||
debug(f"[download-file] Provider item looks like direct URL, downloading: {target}")
|
||||
result_obj = _download_direct_file(target, final_output_dir, quiet=quiet_mode)
|
||||
# Use provider title as filename hint so multiple items don't overwrite as downloaded_file.bin
|
||||
suggested_name = str(title).strip() if title is not None else None
|
||||
result_obj = _download_direct_file(
|
||||
target,
|
||||
final_output_dir,
|
||||
quiet=quiet_mode,
|
||||
suggested_filename=suggested_name,
|
||||
)
|
||||
file_path = None
|
||||
if hasattr(result_obj, "path"):
|
||||
file_path = getattr(result_obj, "path")
|
||||
@@ -301,7 +353,7 @@ class Download_File(Cmdlet):
|
||||
|
||||
def _resolve_output_dir(self, parsed: Dict[str, Any], config: Dict[str, Any]) -> Optional[Path]:
|
||||
"""Resolve the output directory from storage location or config."""
|
||||
output_dir_arg = parsed.get("output")
|
||||
output_dir_arg = parsed.get("path") or parsed.get("output")
|
||||
if output_dir_arg:
|
||||
try:
|
||||
out_path = Path(str(output_dir_arg)).expanduser()
|
||||
|
||||
Reference in New Issue
Block a user