This commit is contained in:
nose
2025-12-17 03:16:41 -08:00
parent 86918f2ae2
commit 5104689a53
10 changed files with 146 additions and 620 deletions

85
CLI.py
View File

@@ -822,7 +822,7 @@ def _create_cmdlet_cli():
shell_complete=_complete_search_provider,
),
query: str = typer.Argument(..., help="Search query (quote for spaces)"),
limit: int = typer.Option(50, "--limit", "-l", help="Maximum results to return"),
limit: int = typer.Option(36, "--limit", "-l", help="Maximum results to return"),
):
"""Search external providers (Typer wrapper around the cmdlet)."""
# Delegate to the existing cmdlet so behavior stays consistent.
@@ -917,17 +917,27 @@ def _create_cmdlet_cli():
prompt_text = "🜂🜄🜁🜃|"
# Prepare startup table (always attempt; fall back gracefully if import fails)
startup_table = ResultTable("Startup checks") if RESULT_TABLE_AVAILABLE else None
startup_table = ResultTable("*********<IGNITIO>*********<NOUSEMPEH>*********<RUGRAPOG>*********<OMEGHAU>*********") if RESULT_TABLE_AVAILABLE else None
if startup_table:
startup_table.set_no_choice(True).set_preserve_order(True)
def _add_startup_check(status: str, name: str, store_or_provider: str, detail: str = "") -> None:
def _add_startup_check(
status: str,
name: str,
*,
provider: str = "",
store: str = "",
files: int | str | None = None,
detail: str = "",
) -> None:
if startup_table is None:
return
row = startup_table.add_row()
row.add_column("Status", status)
row.add_column("Name", name)
row.add_column("Store/Provi", store_or_provider)
row.add_column("Provider", provider or "")
row.add_column("Store", store or "")
row.add_column("Files", "" if files is None else str(files))
row.add_column("Detail", detail or "")
def _has_store_subtype(cfg: dict, subtype: str) -> bool:
@@ -997,9 +1007,9 @@ def _create_cmdlet_cli():
except Exception:
mpv_path = None
_add_startup_check("ENABLED", "MPV", "N/A", mpv_path or "Available")
_add_startup_check("ENABLED", "MPV", detail=mpv_path or "Available")
except Exception as exc:
_add_startup_check("DISABLED", "MPV", "N/A", str(exc))
_add_startup_check("DISABLED", "MPV", detail=str(exc))
store_registry = None
@@ -1033,18 +1043,22 @@ def _create_cmdlet_cli():
if store_registry:
backend = store_registry[name_key]
total = getattr(backend, "total_count", None)
if total is None:
getter = getattr(backend, "get_total_count", None)
if callable(getter):
total = getter()
except Exception:
total = None
detail = (url_val + (" - " if url_val else "")) + "Connected"
if isinstance(total, int) and total >= 0:
detail += f" (Total: {total})"
detail = url_val
files = total if isinstance(total, int) and total >= 0 else None
else:
err = None
if store_registry:
err = store_registry.get_backend_error(instance_name) or store_registry.get_backend_error(name_key)
detail = (url_val + (" - " if url_val else "")) + (err or "Unavailable")
_add_startup_check(status, name_key, "hydrusnetwork", detail)
files = None
_add_startup_check(status, name_key, store="hydrusnetwork", files=files, detail=detail)
# Configured providers (dynamic): show any [provider=...] blocks.
# This complements store checks and avoids hardcoding per-provider rows.
@@ -1148,9 +1162,9 @@ def _create_cmdlet_cli():
client = AllDebridClient(api_key)
base_url = str(getattr(client, "base_url", "") or "").strip()
_add_startup_check("ENABLED", display, prov, base_url or "Connected")
_add_startup_check("ENABLED", display, provider=prov, detail=base_url or "Connected")
except Exception as exc:
_add_startup_check("DISABLED", display, prov, str(exc))
_add_startup_check("DISABLED", display, provider=prov, detail=str(exc))
continue
is_known = False
@@ -1167,7 +1181,7 @@ def _create_cmdlet_cli():
ok = bool(meta_availability.get(prov))
if not is_known:
_add_startup_check("UNKNOWN", display, prov, "Not registered")
_add_startup_check("UNKNOWN", display, provider=prov, detail="Not registered")
else:
# For non-login providers, include a lightweight URL reachability check.
detail = "Configured" if ok else "Not configured"
@@ -1178,7 +1192,7 @@ def _create_cmdlet_cli():
detail = ping_detail
else:
detail = (detail + " | " + ping_detail) if ping_detail else detail
_add_startup_check("ENABLED" if ok else "DISABLED", display, prov, detail)
_add_startup_check("ENABLED" if ok else "DISABLED", display, provider=prov, detail=detail)
already_checked.add(prov)
@@ -1196,7 +1210,7 @@ def _create_cmdlet_cli():
# If the provider isn't even import/dep available, show that first.
if not ok:
detail = ("Unavailable" + (f" | {ping_detail}" if ping_detail else ""))
_add_startup_check("ENABLED" if (ok and ping_ok) else "DISABLED", display, prov, detail)
_add_startup_check("ENABLED" if (ok and ping_ok) else "DISABLED", display, provider=prov, detail=detail)
already_checked.add(prov)
# Default file providers (no login): 0x0
@@ -1206,7 +1220,7 @@ def _create_cmdlet_cli():
detail = ping_detail
if not ok:
detail = ("Unavailable" + (f" | {ping_detail}" if ping_detail else ""))
_add_startup_check("ENABLED" if (ok and ping_ok) else "DISABLED", "0x0", "0x0", detail)
_add_startup_check("ENABLED" if (ok and ping_ok) else "DISABLED", "0x0", provider="0x0", detail=detail)
already_checked.add("0x0")
if _has_provider(config, "matrix"):
@@ -1225,7 +1239,7 @@ def _create_cmdlet_cli():
target = (target + (" " if target else "")) + f"room:{room_id}"
if provider.validate():
_add_startup_check("ENABLED", "Matrix", "matrix", target or "Connected")
_add_startup_check("ENABLED", "Matrix", provider="matrix", detail=target or "Connected")
else:
missing: list[str] = []
if not homeserver:
@@ -1235,9 +1249,9 @@ def _create_cmdlet_cli():
if not (matrix_conf.get("access_token") or matrix_conf.get("password")):
missing.append("access_token/password")
detail = "Not configured" + (f" ({', '.join(missing)})" if missing else "")
_add_startup_check("DISABLED", "Matrix", "matrix", detail)
_add_startup_check("DISABLED", "Matrix", provider="matrix", detail=detail)
except Exception as exc:
_add_startup_check("DISABLED", "Matrix", "matrix", str(exc))
_add_startup_check("DISABLED", "Matrix", provider="matrix", detail=str(exc))
if _has_store_subtype(config, "folder"):
# Folder local scan/index is performed by Store.Folder.__init__.
@@ -1255,17 +1269,26 @@ def _create_cmdlet_cli():
backend = store_registry[name_key]
scan_ok = bool(getattr(backend, "scan_ok", True))
scan_detail = str(getattr(backend, "scan_detail", "") or "")
stats = getattr(backend, "scan_stats", None)
files = None
if isinstance(stats, dict):
try:
total_db = stats.get("files_total_db")
if isinstance(total_db, (int, float)):
files = int(total_db)
except Exception:
files = None
status = "SCANNED" if scan_ok else "ERROR"
detail = (path_val + (" - " if path_val else "")) + (scan_detail or "Up to date")
_add_startup_check(status, name_key, "folder", detail)
_add_startup_check(status, name_key, store="folder", files=files, detail=detail)
else:
err = None
if store_registry:
err = store_registry.get_backend_error(instance_name) or store_registry.get_backend_error(name_key)
detail = (path_val + (" - " if path_val else "")) + (err or "Unavailable")
_add_startup_check("ERROR", name_key, "folder", detail)
_add_startup_check("ERROR", name_key, store="folder", detail=detail)
else:
_add_startup_check("SKIPPED", "Folder", "folder", "No folder stores configured")
_add_startup_check("SKIPPED", "Folder", store="folder", detail="No folder stores configured")
if _has_store_subtype(config, "debrid"):
# Debrid availability is validated by API.alldebrid.AllDebridClient.__init__.
@@ -1274,15 +1297,15 @@ def _create_cmdlet_cli():
api_key = get_debrid_api_key(config)
if not api_key:
_add_startup_check("DISABLED", "Debrid", "debrid", "Not configured")
_add_startup_check("DISABLED", "Debrid", store="debrid", detail="Not configured")
else:
from API.alldebrid import AllDebridClient
client = AllDebridClient(api_key)
base_url = str(getattr(client, "base_url", "") or "").strip()
_add_startup_check("ENABLED", "Debrid", "debrid", base_url or "Connected")
_add_startup_check("ENABLED", "Debrid", store="debrid", detail=base_url or "Connected")
except Exception as exc:
_add_startup_check("DISABLED", "Debrid", "debrid", str(exc))
_add_startup_check("DISABLED", "Debrid", store="debrid", detail=str(exc))
# Cookies are used by yt-dlp; keep this centralized utility.
try:
@@ -1290,11 +1313,11 @@ def _create_cmdlet_cli():
cookiefile = YtDlpTool(config).resolve_cookiefile()
if cookiefile is not None:
_add_startup_check("FOUND", "Cookies", "N/A", str(cookiefile))
_add_startup_check("FOUND", "Cookies", detail=str(cookiefile))
else:
_add_startup_check("MISSING", "Cookies", "N/A", "Not found")
_add_startup_check("MISSING", "Cookies", detail="Not found")
except Exception as exc:
_add_startup_check("ERROR", "Cookies", "N/A", str(exc))
_add_startup_check("ERROR", "Cookies", detail=str(exc))
if startup_table is not None and startup_table.rows:
print()
@@ -1579,11 +1602,11 @@ def _execute_pipeline(tokens: list):
if hash_val != 'N/A':
hash_display = str(hash_val)
title_display = str(title_val)
print(f" -> hash:{hash_display}, title:{title_display}")
debug(f" -> hash:{hash_display}, title:{title_display}")
else:
print(f" -> title:{title_val}")
debug(f" -> title:{title_val}")
else:
print(" -> [source_index out of range]")
debug(" -> [source_index out of range]")
if resolved_list is not None:
debug(f"[debug] resolved_len={len(resolved_list)}")
except Exception as e: