This commit is contained in:
2026-01-17 02:36:06 -08:00
parent 3a7c443004
commit c6fd6b4224
9 changed files with 440 additions and 226 deletions

View File

@@ -266,6 +266,22 @@ def _fetch_torrent_bytes(target: str) -> Optional[bytes]:
return None
_ALD_MAGNET_PREFIX = "alldebrid:magnet:"
def _parse_alldebrid_magnet_id(target: str) -> Optional[int]:
candidate = str(target or "").strip()
if not candidate:
return None
if not candidate.lower().startswith(_ALD_MAGNET_PREFIX):
return None
try:
magnet_id_raw = candidate[len(_ALD_MAGNET_PREFIX):].strip()
return int(magnet_id_raw)
except Exception:
return None
def resolve_magnet_spec(target: str) -> Optional[str]:
"""Resolve a magnet/hash/torrent URL into a magnet/hash string."""
candidate = str(target or "").strip()
@@ -558,14 +574,14 @@ class AllDebrid(TableProviderMixin, Provider):
1. User runs: search-file -provider alldebrid "ubuntu"
2. Results show magnet folders and (optionally) files
3. User selects a row: @1
4. Selection metadata routes to download-file with -magnet-id
5. download-file calls provider.download_items() with magnet_id
4. Selection metadata routes to download-file with -url alldebrid:magnet:<id>
5. download-file invokes provider.download_items() via provider URL handling
6. Provider fetches files, unlocks locked URLs, and downloads
"""
# Magnet URIs should be routed through this provider.
TABLE_AUTO_STAGES = {"alldebrid": ["download-file"]}
AUTO_STAGE_USE_SELECTION_ARGS = True
URL = ("magnet:",)
URL = ("magnet:", "alldebrid:magnet:")
URL_DOMAINS = ()
@classmethod
@@ -631,6 +647,19 @@ class AllDebrid(TableProviderMixin, Provider):
return resolve_magnet_spec(str(target)) if isinstance(target, str) else None
def handle_url(self, url: str, *, output_dir: Optional[Path] = None) -> Tuple[bool, Optional[Path]]:
magnet_id = _parse_alldebrid_magnet_id(url)
if magnet_id is not None:
return True, {
"action": "download_items",
"path": f"{_ALD_MAGNET_PREFIX}{magnet_id}",
"title": f"magnet-{magnet_id}",
"metadata": {
"magnet_id": magnet_id,
"provider": "alldebrid",
"provider_view": "files",
},
}
spec = resolve_magnet_spec(url)
if not spec:
return False, None
@@ -1180,8 +1209,8 @@ class AllDebrid(TableProviderMixin, Provider):
"provider": "alldebrid",
"provider_view": "files",
# Selection metadata for table system
"_selection_args": ["-magnet-id", str(magnet_id)],
"_selection_action": ["download-file", "-provider", "alldebrid", "-magnet-id", str(magnet_id)],
"_selection_args": ["-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
"_selection_action": ["download-file", "-provider", "alldebrid", "-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
}
results.append(
@@ -1295,8 +1324,8 @@ class AllDebrid(TableProviderMixin, Provider):
"provider_view": "folders",
"magnet_name": magnet_name,
# Selection metadata: allow @N expansion to drive downloads directly
"_selection_args": ["-magnet-id", str(magnet_id)],
"_selection_action": ["download-file", "-provider", "alldebrid", "-magnet-id", str(magnet_id)],
"_selection_args": ["-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
"_selection_action": ["download-file", "-provider", "alldebrid", "-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
},
)
)
@@ -1585,7 +1614,7 @@ try:
1. Explicit _selection_action (full command args)
2. Explicit _selection_args (URL-specific args)
3. Magic routing based on provider_view (files vs folders)
4. Magnet ID routing for folder-type rows
4. Magnet ID routing for folder-type rows (via alldebrid:magnet:<id>)
5. Direct URL for file rows
This ensures that selector overrides all pre-codes and gives users full power.
@@ -1612,7 +1641,7 @@ try:
# Folder rows: use magnet_id to fetch and download all files
magnet_id = metadata.get("magnet_id")
if magnet_id is not None:
return ["-magnet-id", str(magnet_id)]
return ["-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"]
# Fallback: try direct URL
if row.path: