huge refactor of the entire codebase, with the goal of improving maintainability, readability, and extensibility. This commit includes changes to almost every file in the project, including:
This commit is contained in:
+72
-19
@@ -351,7 +351,7 @@ def _dispatch_alldebrid_magnet_search(
|
||||
if callable(exec_fn):
|
||||
exec_fn(
|
||||
None,
|
||||
["-provider", "alldebrid", f"ID={magnet_id}"],
|
||||
["-plugin", "alldebrid", f"ID={magnet_id}"],
|
||||
config,
|
||||
)
|
||||
except Exception:
|
||||
@@ -493,7 +493,7 @@ def download_magnet(
|
||||
|
||||
def expand_folder_item(
|
||||
item: Any,
|
||||
get_search_provider: Optional[Callable[[str, Dict[str, Any]], Any]],
|
||||
get_search_plugin: Optional[Callable[[str, Dict[str, Any]], Any]],
|
||||
config: Dict[str, Any],
|
||||
) -> Tuple[List[Any], Optional[str]]:
|
||||
table = getattr(item, "table", None) if not isinstance(item, dict) else item.get("table")
|
||||
@@ -517,15 +517,15 @@ def expand_folder_item(
|
||||
except Exception:
|
||||
magnet_id = None
|
||||
|
||||
if magnet_id is None or get_search_provider is None:
|
||||
if magnet_id is None or get_search_plugin is None:
|
||||
return [], None
|
||||
|
||||
provider = get_search_provider("alldebrid", config) if get_search_provider else None
|
||||
if provider is None:
|
||||
plugin = get_search_plugin("alldebrid", config) if get_search_plugin else None
|
||||
if plugin is None:
|
||||
return [], None
|
||||
|
||||
try:
|
||||
files = provider.search("*", limit=10_000, filters={"view": "files", "magnet_id": int(magnet_id)})
|
||||
files = plugin.search("*", limit=10_000, filters={"view": "files", "magnet_id": int(magnet_id)})
|
||||
except Exception:
|
||||
files = []
|
||||
|
||||
@@ -609,7 +609,7 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
- Drill-down: Selecting a folder row (@N) fetches and displays all files
|
||||
|
||||
SELECTION FLOW:
|
||||
1. User runs: search-file -provider alldebrid "ubuntu"
|
||||
1. User runs: search-file -plugin alldebrid "ubuntu"
|
||||
2. Results show magnet folders and (optionally) files
|
||||
3. User selects a row: @1
|
||||
4. Selection metadata routes to download-file with -url alldebrid:magnet:<id>
|
||||
@@ -619,7 +619,7 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
# Magnet URIs should be routed through this provider.
|
||||
TABLE_AUTO_STAGES = {"alldebrid": ["download-file"]}
|
||||
AUTO_STAGE_USE_SELECTION_ARGS = True
|
||||
URL = ("magnet:", "alldebrid:magnet:", "alldebrid:", "alldebrid🧲")
|
||||
URL = ("magnet:", "alldebrid:magnet:", "alldebrid:", "alldebrid🧲", "alldebrid.com")
|
||||
URL_DOMAINS = ()
|
||||
|
||||
def extract_query_arguments(self, query: str) -> Tuple[str, Dict[str, Any]]:
|
||||
@@ -949,12 +949,10 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def download_for_pipe_result(
|
||||
cls,
|
||||
def resolve_pipe_result_download(
|
||||
self,
|
||||
result: Any,
|
||||
pipe_obj: Optional[PipeObject],
|
||||
config: Dict[str, Any],
|
||||
) -> Tuple[Optional[Path], Optional[str], Optional[Path]]:
|
||||
"""Download a remote provider result on behalf of add-file."""
|
||||
|
||||
@@ -1026,8 +1024,7 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
|
||||
download_dir = Path(tempfile.mkdtemp(prefix="add-file-alldebrid-"))
|
||||
try:
|
||||
provider = cls(config)
|
||||
downloaded_path = provider.download(search_result, download_dir)
|
||||
downloaded_path = self.download(search_result, download_dir)
|
||||
if not downloaded_path:
|
||||
shutil.rmtree(download_dir, ignore_errors=True)
|
||||
return None, None, None
|
||||
@@ -1049,6 +1046,62 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
log(f"[alldebrid] add-file download failed: {exc}", file=sys.stderr)
|
||||
shutil.rmtree(download_dir, ignore_errors=True)
|
||||
return None, None, None
|
||||
|
||||
def status_summary(self) -> Dict[str, Any]:
|
||||
try:
|
||||
api_key = _get_debrid_api_key(self.config)
|
||||
if not api_key:
|
||||
return {
|
||||
"status": "DISABLED",
|
||||
"name": self.label,
|
||||
"plugin": self.name,
|
||||
"detail": "Not configured",
|
||||
}
|
||||
client = AllDebridClient(api_key)
|
||||
base_url = str(getattr(client, "base_url", "") or "").strip()
|
||||
return {
|
||||
"status": "ENABLED",
|
||||
"name": self.label,
|
||||
"plugin": self.name,
|
||||
"detail": base_url or "Connected",
|
||||
}
|
||||
except Exception as exc:
|
||||
return {
|
||||
"status": "DISABLED",
|
||||
"name": self.label,
|
||||
"plugin": self.name,
|
||||
"detail": str(exc),
|
||||
}
|
||||
|
||||
def resolve_url(self, url: str, **_kwargs: Any) -> str:
|
||||
target = str(url or "").strip()
|
||||
if not target.startswith(("http://", "https://")):
|
||||
return target
|
||||
|
||||
try:
|
||||
parsed = urlparse(target)
|
||||
host = str(parsed.netloc or "").lower()
|
||||
path = str(parsed.path or "")
|
||||
except Exception:
|
||||
return target
|
||||
|
||||
if host != "alldebrid.com" or not path.startswith("/f/"):
|
||||
return target
|
||||
|
||||
api_key = _get_debrid_api_key(self.config)
|
||||
if not api_key:
|
||||
return target
|
||||
|
||||
try:
|
||||
client = AllDebridClient(str(api_key))
|
||||
unlocked = client.unlock_link(target)
|
||||
if isinstance(unlocked, str) and unlocked.strip():
|
||||
return unlocked.strip()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return target
|
||||
|
||||
def download_items(
|
||||
self,
|
||||
result: SearchResult,
|
||||
@@ -1413,7 +1466,7 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
"provider_view": "files",
|
||||
# Selection metadata for table system
|
||||
"_selection_args": ["-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
"_selection_action": ["download-file", "-provider", "alldebrid", "-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
"_selection_action": ["download-file", "-plugin", "alldebrid", "-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
}
|
||||
|
||||
results.append(
|
||||
@@ -1528,7 +1581,7 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
"magnet_name": magnet_name,
|
||||
# Selection metadata: allow @N expansion to drive downloads directly
|
||||
"_selection_args": ["-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
"_selection_action": ["download-file", "-provider", "alldebrid", "-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
"_selection_action": ["download-file", "-plugin", "alldebrid", "-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
},
|
||||
)
|
||||
)
|
||||
@@ -1629,7 +1682,7 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
table.set_table_metadata({"provider": "alldebrid", "view": "files", "magnet_id": magnet_id})
|
||||
except Exception:
|
||||
pass
|
||||
table.set_source_command("download-file", ["-provider", "alldebrid"])
|
||||
table.set_source_command("download-file", ["-plugin", "alldebrid"])
|
||||
|
||||
results_payload: List[Dict[str, Any]] = []
|
||||
for r in files or []:
|
||||
@@ -1662,7 +1715,7 @@ class AllDebrid(TableProviderMixin, Provider):
|
||||
|
||||
|
||||
try:
|
||||
from SYS.result_table_adapters import register_provider
|
||||
from SYS.result_table_adapters import register_plugin
|
||||
from SYS.result_table_api import ColumnSpec, ResultModel, metadata_column, title_column
|
||||
|
||||
def _as_payload(item: Any) -> Dict[str, Any]:
|
||||
@@ -1853,7 +1906,7 @@ try:
|
||||
return ["-title", row.title or ""]
|
||||
|
||||
|
||||
register_provider(
|
||||
register_plugin(
|
||||
"alldebrid",
|
||||
_adapter,
|
||||
columns=_columns_factory,
|
||||
|
||||
Reference in New Issue
Block a user