df
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
Some checks failed
smoke-mm / Install & smoke test mm --help (push) Has been cancelled
This commit is contained in:
@@ -95,12 +95,18 @@ class AllDebrid(Provider):
|
||||
return None
|
||||
|
||||
# Quiet mode when download-file is mid-pipeline.
|
||||
quiet = bool(self.config.get("_quiet_background_output")) if isinstance(self.config, dict) else False
|
||||
quiet = (
|
||||
bool(self.config.get("_quiet_background_output"))
|
||||
if isinstance(self.config, dict)
|
||||
else False
|
||||
)
|
||||
|
||||
unlocked_url = target
|
||||
try:
|
||||
unlocked = client.unlock_link(target)
|
||||
if isinstance(unlocked, str) and unlocked.strip().startswith(("http://", "https://")):
|
||||
if isinstance(unlocked, str) and unlocked.strip().startswith(
|
||||
("http://", "https://")
|
||||
):
|
||||
unlocked_url = unlocked.strip()
|
||||
except Exception as exc:
|
||||
# Fall back to the raw link, but warn.
|
||||
@@ -136,7 +142,11 @@ class AllDebrid(Provider):
|
||||
try:
|
||||
if downloaded_path.exists():
|
||||
size = downloaded_path.stat().st_size
|
||||
if size > 0 and size <= 250_000 and downloaded_path.suffix.lower() not in (".html", ".htm"):
|
||||
if (
|
||||
size > 0
|
||||
and size <= 250_000
|
||||
and downloaded_path.suffix.lower() not in (".html", ".htm")
|
||||
):
|
||||
head = downloaded_path.read_bytes()[:512]
|
||||
try:
|
||||
text = head.decode("utf-8", errors="ignore").lower()
|
||||
@@ -147,7 +157,10 @@ class AllDebrid(Provider):
|
||||
downloaded_path.unlink()
|
||||
except Exception:
|
||||
pass
|
||||
log("[alldebrid] Download returned HTML page (not file bytes). Try again or check AllDebrid link status.", file=sys.stderr)
|
||||
log(
|
||||
"[alldebrid] Download returned HTML page (not file bytes). Try again or check AllDebrid link status.",
|
||||
file=sys.stderr,
|
||||
)
|
||||
return None
|
||||
except Exception:
|
||||
pass
|
||||
@@ -160,7 +173,9 @@ class AllDebrid(Provider):
|
||||
return None
|
||||
|
||||
@staticmethod
|
||||
def _flatten_files(items: Any, *, _prefix: Optional[List[str]] = None) -> Iterable[Dict[str, Any]]:
|
||||
def _flatten_files(
|
||||
items: Any, *, _prefix: Optional[List[str]] = None
|
||||
) -> Iterable[Dict[str, Any]]:
|
||||
"""Flatten AllDebrid magnet file tree into file dicts, preserving relative paths.
|
||||
|
||||
API commonly returns:
|
||||
@@ -185,17 +200,17 @@ class AllDebrid(Provider):
|
||||
if not isinstance(node, dict):
|
||||
continue
|
||||
|
||||
children = node.get('e') or node.get('children')
|
||||
children = node.get("e") or node.get("children")
|
||||
if isinstance(children, list):
|
||||
folder_name = node.get('n') or node.get('name')
|
||||
folder_name = node.get("n") or node.get("name")
|
||||
next_prefix = prefix
|
||||
if isinstance(folder_name, str) and folder_name.strip():
|
||||
next_prefix = prefix + [folder_name.strip()]
|
||||
yield from AllDebrid._flatten_files(children, _prefix=next_prefix)
|
||||
continue
|
||||
|
||||
name = node.get('n') or node.get('name')
|
||||
link = node.get('l') or node.get('link')
|
||||
name = node.get("n") or node.get("name")
|
||||
link = node.get("l") or node.get("link")
|
||||
if isinstance(name, str) and name.strip() and isinstance(link, str) and link.strip():
|
||||
rel_parts = prefix + [name.strip()]
|
||||
relpath = "/".join([p for p in rel_parts if p])
|
||||
@@ -253,10 +268,15 @@ class AllDebrid(Provider):
|
||||
except Exception:
|
||||
magnet_status = {}
|
||||
|
||||
magnet_name = str(magnet_status.get('filename') or magnet_status.get('name') or magnet_status.get('hash') or f"magnet-{magnet_id}")
|
||||
status_code = magnet_status.get('statusCode')
|
||||
status_text = str(magnet_status.get('status') or "").strip() or "unknown"
|
||||
ready = status_code == 4 or bool(magnet_status.get('ready'))
|
||||
magnet_name = str(
|
||||
magnet_status.get("filename")
|
||||
or magnet_status.get("name")
|
||||
or magnet_status.get("hash")
|
||||
or f"magnet-{magnet_id}"
|
||||
)
|
||||
status_code = magnet_status.get("statusCode")
|
||||
status_text = str(magnet_status.get("status") or "").strip() or "unknown"
|
||||
ready = status_code == 4 or bool(magnet_status.get("ready"))
|
||||
|
||||
if not ready:
|
||||
return [
|
||||
@@ -280,18 +300,23 @@ class AllDebrid(Provider):
|
||||
|
||||
try:
|
||||
files_result = client.magnet_links([magnet_id])
|
||||
magnet_files = files_result.get(str(magnet_id), {}) if isinstance(files_result, dict) else {}
|
||||
file_tree = magnet_files.get('files', []) if isinstance(magnet_files, dict) else []
|
||||
magnet_files = (
|
||||
files_result.get(str(magnet_id), {}) if isinstance(files_result, dict) else {}
|
||||
)
|
||||
file_tree = magnet_files.get("files", []) if isinstance(magnet_files, dict) else []
|
||||
except Exception as exc:
|
||||
log(f"[alldebrid] Failed to list files for magnet {magnet_id}: {exc}", file=sys.stderr)
|
||||
log(
|
||||
f"[alldebrid] Failed to list files for magnet {magnet_id}: {exc}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
file_tree = []
|
||||
|
||||
results: List[SearchResult] = []
|
||||
for file_node in self._flatten_files(file_tree):
|
||||
file_name = str(file_node.get('n') or file_node.get('name') or '').strip()
|
||||
file_url = str(file_node.get('l') or file_node.get('link') or '').strip()
|
||||
relpath = str(file_node.get('_relpath') or file_name or '').strip()
|
||||
file_size = file_node.get('s') or file_node.get('size')
|
||||
file_name = str(file_node.get("n") or file_node.get("name") or "").strip()
|
||||
file_url = str(file_node.get("l") or file_node.get("link") or "").strip()
|
||||
relpath = str(file_node.get("_relpath") or file_name or "").strip()
|
||||
file_size = file_node.get("s") or file_node.get("size")
|
||||
if not file_name or not file_url:
|
||||
continue
|
||||
|
||||
@@ -356,16 +381,21 @@ class AllDebrid(Provider):
|
||||
continue
|
||||
|
||||
try:
|
||||
magnet_id = int(magnet.get('id'))
|
||||
magnet_id = int(magnet.get("id"))
|
||||
except Exception:
|
||||
continue
|
||||
|
||||
magnet_name = str(magnet.get('filename') or magnet.get('name') or magnet.get('hash') or f"magnet-{magnet_id}")
|
||||
magnet_name = str(
|
||||
magnet.get("filename")
|
||||
or magnet.get("name")
|
||||
or magnet.get("hash")
|
||||
or f"magnet-{magnet_id}"
|
||||
)
|
||||
magnet_name_lower = magnet_name.lower()
|
||||
|
||||
status_text = str(magnet.get('status') or "").strip() or "unknown"
|
||||
status_code = magnet.get('statusCode')
|
||||
ready = status_code == 4 or bool(magnet.get('ready'))
|
||||
status_text = str(magnet.get("status") or "").strip() or "unknown"
|
||||
status_code = magnet.get("statusCode")
|
||||
ready = status_code == 4 or bool(magnet.get("ready"))
|
||||
|
||||
if wanted_id is not None:
|
||||
if magnet_id != wanted_id:
|
||||
@@ -375,7 +405,7 @@ class AllDebrid(Provider):
|
||||
|
||||
size_bytes: Optional[int] = None
|
||||
try:
|
||||
size_val = magnet.get('size')
|
||||
size_val = magnet.get("size")
|
||||
if isinstance(size_val, (int, float)):
|
||||
size_bytes = int(size_val)
|
||||
elif isinstance(size_val, str) and size_val.isdigit():
|
||||
@@ -392,7 +422,8 @@ class AllDebrid(Provider):
|
||||
annotations=["folder"],
|
||||
media_kind="folder",
|
||||
size_bytes=size_bytes,
|
||||
tag={"alldebrid", "folder", str(magnet_id)} | ({"ready"} if ready else {"not-ready"}),
|
||||
tag={"alldebrid", "folder", str(magnet_id)}
|
||||
| ({"ready"} if ready else {"not-ready"}),
|
||||
columns=[
|
||||
("Folder", magnet_name),
|
||||
("ID", str(magnet_id)),
|
||||
|
||||
Reference in New Issue
Block a user