This commit is contained in:
2026-01-31 23:22:30 -08:00
parent ed44d69ef1
commit 753cdfb196
6 changed files with 454 additions and 35 deletions

View File

@@ -1229,10 +1229,63 @@ class Add_File(Cmdlet):
hash_hint = get_field(result, "hash") or get_field(result, "file_hash") or getattr(pipe_obj, "hash", None)
return candidate, hash_hint, None
downloaded_path, hash_hint, tmp_dir = Add_File._maybe_download_alldebrid_result(
result,
pipe_obj,
config,
)
if downloaded_path:
pipe_obj.path = str(downloaded_path)
return downloaded_path, hash_hint, tmp_dir
debug(f"No resolution path matched. result type={type(result).__name__}")
log("File path could not be resolved")
return None, None, None
@staticmethod
def _normalize_provider_key(value: Optional[Any]) -> Optional[str]:
if value is None:
return None
try:
normalized = str(value).strip().lower()
except Exception:
return None
if not normalized:
return None
if "." in normalized:
normalized = normalized.split(".", 1)[0]
return normalized
@staticmethod
def _maybe_download_alldebrid_result(
result: Any,
pipe_obj: models.PipeObject,
config: Dict[str, Any],
) -> Tuple[Optional[Path], Optional[str], Optional[Path]]:
provider_key = None
for source in (
pipe_obj.provider,
get_field(result, "provider"),
get_field(result, "table"),
):
candidate = Add_File._normalize_provider_key(source)
if candidate:
provider_key = candidate
break
if provider_key != "alldebrid":
return None, None, None
try:
from Provider.alldebrid import AllDebrid
except Exception:
return None, None, None
try:
return AllDebrid.download_for_pipe_result(result, pipe_obj, config)
except Exception as exc:
debug(f"[add-file] AllDebrid download helper failed: {exc}")
return None, None, None
@staticmethod
def _download_provider_source(
pipe_obj: models.PipeObject,

View File

@@ -554,6 +554,7 @@ class Download_File(Cmdlet):
dict) else None,
progress=progress,
config=config,
provider_hint=provider_key
)
downloaded_count += 1
@@ -2594,7 +2595,14 @@ class Download_File(Cmdlet):
parsed = parse_cmdlet_args(args, self)
# Resolve URLs from -url or positional arguments
url_candidates = parsed.get("url") or [a for a in parsed.get("args", []) if isinstance(a, str) and (a.startswith("http") or "://" in a)]
url_candidates = parsed.get("url") or [
a for a in parsed.get("args", [])
if isinstance(a, str) and (
a.startswith("http") or "://" in a or ":" in a
or "🧲" in a
and not a.startswith("-")
)
]
raw_url = normalize_url_list(url_candidates)
quiet_mode = bool(config.get("_quiet_background_output")) if isinstance(config, dict) else False
@@ -2618,7 +2626,7 @@ class Download_File(Cmdlet):
s_val = str(value or "").strip().lower()
except Exception:
return False
return s_val.startswith(("http://", "https://"))
return s_val.startswith(("http://", "https://", "magnet:", "torrent:", "alldebrid:", "alldebrid🧲"))
def _extract_selection_args(item: Any) -> tuple[Optional[List[str]], Optional[str]]:
selection_args: Optional[List[str]] = None
@@ -2786,9 +2794,15 @@ class Download_File(Cmdlet):
and (not parsed.get("path")) and (not parsed.get("output"))):
candidate = str(raw_url[0] or "").strip()
low = candidate.lower()
looks_like_url = low.startswith(("http://", "https://", "ftp://"))
looks_like_url = low.startswith((
"http://", "https://", "ftp://", "magnet:", "torrent:",
"alldebrid:", "alldebrid🧲"
))
looks_like_provider = (
":" in candidate and not candidate.startswith(("http:", "https:", "ftp:", "ftps:", "file:"))
":" in candidate and not candidate.startswith((
"http:", "https:", "ftp:", "ftps:", "file:",
"alldebrid:"
))
)
looks_like_windows_path = (
(len(candidate) >= 2 and candidate[1] == ":")