h
This commit is contained in:
@@ -86,6 +86,11 @@ class Download_File(Cmdlet):
|
||||
alias="a",
|
||||
description="Download audio only (yt-dlp)",
|
||||
),
|
||||
CmdletArg(
|
||||
name="-magnet-id",
|
||||
type="string",
|
||||
description="(internal) AllDebrid magnet id used by provider selection hooks",
|
||||
),
|
||||
CmdletArg(
|
||||
name="format",
|
||||
type="string",
|
||||
@@ -3789,6 +3794,94 @@ class Download_File(Cmdlet):
|
||||
registry = self._load_provider_registry()
|
||||
|
||||
downloaded_count = 0
|
||||
|
||||
# Special-case: support selection-inserted magnet-id arg to drive provider downloads
|
||||
magnet_id_raw = parsed.get("magnet-id")
|
||||
if magnet_id_raw:
|
||||
try:
|
||||
magnet_id = int(str(magnet_id_raw).strip())
|
||||
except Exception:
|
||||
log(f"[download-file] invalid magnet-id: {magnet_id_raw}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
get_provider = registry.get("get_provider")
|
||||
provider_name = str(parsed.get("provider") or "alldebrid").strip().lower()
|
||||
provider_obj = None
|
||||
if get_provider is not None:
|
||||
try:
|
||||
provider_obj = get_provider(provider_name, config)
|
||||
except Exception:
|
||||
provider_obj = None
|
||||
|
||||
if provider_obj is None:
|
||||
log(f"[download-file] provider '{provider_name}' not available", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
SearchResult = registry.get("SearchResult")
|
||||
try:
|
||||
if SearchResult is not None:
|
||||
sr = SearchResult(
|
||||
table=provider_name,
|
||||
title=f"magnet-{magnet_id}",
|
||||
path=f"alldebrid:magnet:{magnet_id}",
|
||||
full_metadata={
|
||||
"magnet_id": magnet_id,
|
||||
"provider": provider_name,
|
||||
"provider_view": "files",
|
||||
},
|
||||
)
|
||||
else:
|
||||
sr = None
|
||||
except Exception:
|
||||
sr = None
|
||||
|
||||
def _on_emit(path: Path, file_url: str, relpath: str, metadata: Dict[str, Any]) -> None:
|
||||
title_hint = metadata.get("name") or relpath or f"magnet-{magnet_id}"
|
||||
self._emit_local_file(
|
||||
downloaded_path=path,
|
||||
source=file_url or f"alldebrid:magnet:{magnet_id}",
|
||||
title_hint=title_hint,
|
||||
tags_hint=None,
|
||||
media_kind_hint="file",
|
||||
full_metadata=metadata,
|
||||
progress=progress,
|
||||
config=config,
|
||||
provider_hint=provider_name,
|
||||
)
|
||||
|
||||
try:
|
||||
downloaded_extra = provider_obj.download_items(
|
||||
sr,
|
||||
final_output_dir,
|
||||
emit=_on_emit,
|
||||
progress=progress,
|
||||
quiet_mode=quiet_mode,
|
||||
path_from_result=self._path_from_download_result,
|
||||
config=config,
|
||||
)
|
||||
except TypeError:
|
||||
downloaded_extra = provider_obj.download_items(
|
||||
sr,
|
||||
final_output_dir,
|
||||
emit=_on_emit,
|
||||
progress=progress,
|
||||
quiet_mode=quiet_mode,
|
||||
path_from_result=self._path_from_download_result,
|
||||
)
|
||||
except Exception as exc:
|
||||
log(f"[download-file] failed to download magnet {magnet_id}: {exc}", file=sys.stderr)
|
||||
return 1
|
||||
|
||||
if downloaded_extra:
|
||||
debug(f"[download-file] AllDebrid magnet {magnet_id} emitted {downloaded_extra} files")
|
||||
return 0
|
||||
|
||||
log(
|
||||
f"[download-file] AllDebrid magnet {magnet_id} produced no downloads",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return 1
|
||||
|
||||
urls_downloaded, early_exit = self._process_explicit_urls(
|
||||
raw_urls=raw_url,
|
||||
final_output_dir=final_output_dir,
|
||||
|
||||
Reference in New Issue
Block a user