update and cleanup repo
This commit is contained in:
@@ -10,7 +10,7 @@ from pathlib import Path
|
||||
from typing import Any, Dict, Iterable, List, Optional, Callable, Tuple
|
||||
from urllib.parse import urlparse
|
||||
|
||||
from API.HTTP import HTTPClient, _download_direct_file
|
||||
from API.HTTP import HTTPClient, download_direct_file
|
||||
from plugins.alldebrid.api import AllDebridClient, parse_magnet_or_hash, is_torrent_file
|
||||
from PluginCore.base import Provider, SearchResult
|
||||
from SYS.plugin_helpers import TablePluginMixin
|
||||
@@ -197,47 +197,14 @@ def refresh_alldebrid_hoster_cache(*, force: bool = False) -> None:
|
||||
|
||||
|
||||
def _get_debrid_api_key(config: Dict[str, Any]) -> Optional[str]:
|
||||
"""Read AllDebrid API key from config.
|
||||
|
||||
Preferred formats:
|
||||
- config.conf provider block:
|
||||
[provider=alldebrid]
|
||||
api_key=...
|
||||
-> config["provider"]["alldebrid"]["api_key"]
|
||||
|
||||
- plugin-style debrid block:
|
||||
config["plugin"]["debrid"]["all-debrid"]["api_key"]
|
||||
|
||||
Falls back to some legacy keys if present.
|
||||
"""
|
||||
# 1) provider block: [provider=alldebrid]
|
||||
provider = config.get("provider")
|
||||
if isinstance(provider, dict):
|
||||
entry = provider.get("alldebrid")
|
||||
if isinstance(entry, dict):
|
||||
for k in ("api_key", "apikey", "API_KEY", "APIKEY"):
|
||||
val = entry.get(k)
|
||||
if isinstance(val, str) and val.strip():
|
||||
return val.strip()
|
||||
if isinstance(entry, str) and entry.strip():
|
||||
return entry.strip()
|
||||
|
||||
# 2) plugin debrid block
|
||||
"""Read the canonical AllDebrid API key from config."""
|
||||
try:
|
||||
from SYS.config import get_debrid_api_key
|
||||
|
||||
key = get_debrid_api_key(config, service="All-debrid")
|
||||
return key.strip() if key else None
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Legacy fallback (kept permissive so older configs still work)
|
||||
for legacy_key in ("alldebrid_api_key", "AllDebrid", "all_debrid_api_key"):
|
||||
val = config.get(legacy_key)
|
||||
if isinstance(val, str) and val.strip():
|
||||
return val.strip()
|
||||
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def _consume_bencoded_value(data: bytes, pos: int) -> int:
|
||||
@@ -399,8 +366,8 @@ def _build_queued_magnet_item(
|
||||
|
||||
metadata: Dict[str, Any] = {
|
||||
"magnet_id": magnet_id,
|
||||
"provider": "alldebrid",
|
||||
"provider_view": "files",
|
||||
"plugin": "alldebrid",
|
||||
"plugin_view": "files",
|
||||
"magnet_spec": magnet_spec,
|
||||
"source_url": magnet_spec,
|
||||
"status": status_label,
|
||||
@@ -412,7 +379,6 @@ def _build_queued_magnet_item(
|
||||
|
||||
return {
|
||||
"table": "alldebrid",
|
||||
"provider": "alldebrid",
|
||||
"plugin": "alldebrid",
|
||||
"path": f"{_ALD_MAGNET_PREFIX}{magnet_id}",
|
||||
"title": title,
|
||||
@@ -539,7 +505,7 @@ def download_magnet(
|
||||
output_dir = target_path
|
||||
|
||||
try:
|
||||
result_obj = _download_direct_file(
|
||||
result_obj = download_direct_file(
|
||||
file_url,
|
||||
output_dir,
|
||||
quiet=quiet_mode,
|
||||
@@ -800,8 +766,8 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
"title": f"magnet-{magnet_id}",
|
||||
"metadata": {
|
||||
"magnet_id": magnet_id,
|
||||
"provider": "alldebrid",
|
||||
"provider_view": "files",
|
||||
"plugin": "alldebrid",
|
||||
"plugin_view": "files",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -952,7 +918,7 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
pipe_progress = None
|
||||
|
||||
try:
|
||||
dl_res = _download_direct_file(
|
||||
dl_res = download_direct_file(
|
||||
unlocked_url,
|
||||
Path(output_dir),
|
||||
quiet=quiet,
|
||||
@@ -965,7 +931,7 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
downloaded_path = Path(str(downloaded_path))
|
||||
except DownloadError as exc:
|
||||
log(
|
||||
f"[alldebrid] _download_direct_file rejected URL ({exc}); no further fallback", file=sys.stderr
|
||||
f"[alldebrid] download_direct_file rejected URL ({exc}); no further fallback", file=sys.stderr
|
||||
)
|
||||
return None
|
||||
|
||||
@@ -1360,7 +1326,7 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
suggested_name = rel_path_obj.name or file_name or f"file-{file_idx}"
|
||||
|
||||
try:
|
||||
result_obj = _download_direct_file(
|
||||
result_obj = download_direct_file(
|
||||
file_url,
|
||||
target_path,
|
||||
quiet=quiet_mode,
|
||||
@@ -1482,8 +1448,8 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
full_metadata={
|
||||
"magnet": magnet_status,
|
||||
"magnet_id": magnet_id,
|
||||
"provider": "alldebrid",
|
||||
"provider_view": "files",
|
||||
"plugin": "alldebrid",
|
||||
"plugin_view": "files",
|
||||
"magnet_name": magnet_name,
|
||||
},
|
||||
)
|
||||
@@ -1535,8 +1501,8 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
"magnet_name": magnet_name,
|
||||
"relpath": relpath,
|
||||
"file": file_node,
|
||||
"provider": "alldebrid",
|
||||
"provider_view": "files",
|
||||
"plugin": "alldebrid",
|
||||
"plugin_view": "files",
|
||||
# Selection metadata for table system
|
||||
"_selection_args": ["-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
"_selection_action": ["download-file", "-plugin", "alldebrid", "-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
@@ -1649,8 +1615,8 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
full_metadata={
|
||||
"magnet": magnet,
|
||||
"magnet_id": magnet_id,
|
||||
"provider": "alldebrid",
|
||||
"provider_view": "folders",
|
||||
"plugin": "alldebrid",
|
||||
"plugin_view": "folders",
|
||||
"magnet_name": magnet_name,
|
||||
# Selection metadata: allow @N expansion to drive downloads directly
|
||||
"_selection_args": ["-url", f"{_ALD_MAGNET_PREFIX}{magnet_id}"],
|
||||
@@ -1752,7 +1718,7 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
table = Table(f"AllDebrid Files: {title}")._perseverance(True)
|
||||
table.set_table("alldebrid")
|
||||
try:
|
||||
table.set_table_metadata({"provider": "alldebrid", "view": "files", "magnet_id": magnet_id})
|
||||
table.set_table_metadata({"plugin": "alldebrid", "view": "files", "magnet_id": magnet_id})
|
||||
except Exception:
|
||||
pass
|
||||
table.set_source_command("download-file", ["-plugin", "alldebrid"])
|
||||
@@ -1844,7 +1810,7 @@ class AllDebrid(TablePluginMixin, Provider):
|
||||
"Magnet": magnet_name or None,
|
||||
"Magnet ID": magnet_id,
|
||||
"Relative Path": relpath or None,
|
||||
"View": str(meta.get("provider_view") or meta.get("view") or (table_metadata or {}).get("view") or "").strip() or None,
|
||||
"View": str(meta.get("plugin_view") or meta.get("view") or (table_metadata or {}).get("view") or "").strip() or None,
|
||||
"Direct Url": direct_url or None,
|
||||
"Selection Url": selection_url or None,
|
||||
},
|
||||
@@ -1942,7 +1908,7 @@ try:
|
||||
if table_name:
|
||||
metadata.setdefault("table", table_name)
|
||||
metadata.setdefault("source", table_name)
|
||||
metadata.setdefault("provider", table_name)
|
||||
metadata.setdefault("plugin", table_name)
|
||||
|
||||
ext = payload.get("ext")
|
||||
if not ext and isinstance(path_val, str):
|
||||
@@ -2003,8 +1969,8 @@ try:
|
||||
cols.append(metadata_column("ready", "Ready"))
|
||||
if _has_metadata(rows, "relpath"):
|
||||
cols.append(metadata_column("relpath", "File Path"))
|
||||
if _has_metadata(rows, "provider_view"):
|
||||
cols.append(metadata_column("provider_view", "View"))
|
||||
if _has_metadata(rows, "plugin_view"):
|
||||
cols.append(metadata_column("plugin_view", "View"))
|
||||
if _has_metadata(rows, "size"):
|
||||
cols.append(metadata_column("size", "Size"))
|
||||
return cols
|
||||
@@ -2016,7 +1982,7 @@ try:
|
||||
Selection precedence:
|
||||
1. Explicit _selection_action (full command args)
|
||||
2. Explicit _selection_args (URL-specific args)
|
||||
3. Magic routing based on provider_view (files vs folders)
|
||||
3. Magic routing based on plugin_view (files vs folders)
|
||||
4. Magnet ID routing for folder-type rows (via alldebrid:magnet:<id>)
|
||||
5. Direct URL for file rows
|
||||
|
||||
@@ -2035,7 +2001,7 @@ try:
|
||||
return [str(x) for x in args if x is not None]
|
||||
|
||||
# Magic routing by view type
|
||||
view = metadata.get("provider_view") or metadata.get("view") or ""
|
||||
view = metadata.get("plugin_view") or metadata.get("view") or ""
|
||||
if view == "files":
|
||||
# File rows: pass direct URL for immediate download
|
||||
if row.path:
|
||||
|
||||
Reference in New Issue
Block a user