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:
+58
-26
@@ -74,34 +74,9 @@ def ping_url(url: str, timeout: float = 3.0) -> tuple[bool, str]:
|
||||
|
||||
def provider_display_name(key: str) -> str:
|
||||
label = (key or "").strip()
|
||||
lower = label.lower()
|
||||
if lower == "openlibrary":
|
||||
return "OpenLibrary"
|
||||
if lower == "alldebrid":
|
||||
return "AllDebrid"
|
||||
if lower == "youtube":
|
||||
return "YouTube"
|
||||
return label[:1].upper() + label[1:] if label else "Provider"
|
||||
|
||||
|
||||
def default_provider_ping_targets(provider_key: str) -> list[str]:
|
||||
provider = (provider_key or "").strip().lower()
|
||||
if provider == "openlibrary":
|
||||
return ["https://openlibrary.org"]
|
||||
if provider == "youtube":
|
||||
return ["https://www.youtube.com"]
|
||||
if provider == "bandcamp":
|
||||
return ["https://bandcamp.com"]
|
||||
if provider == "libgen":
|
||||
try:
|
||||
from Provider.libgen import MIRRORS
|
||||
|
||||
return [str(url).rstrip("/") + "/json.php" for url in (MIRRORS or []) if str(url).strip()]
|
||||
except ImportError:
|
||||
return []
|
||||
return []
|
||||
|
||||
|
||||
def ping_first(urls: list[str]) -> tuple[bool, str]:
|
||||
for url in urls:
|
||||
ok, detail = ping_url(url)
|
||||
@@ -109,4 +84,61 @@ def ping_first(urls: list[str]) -> tuple[bool, str]:
|
||||
return True, detail
|
||||
if urls:
|
||||
return ping_url(urls[0])
|
||||
return False, "No ping target"
|
||||
return False, "No ping target"
|
||||
|
||||
|
||||
def collect_plugin_startup_checks(config: dict) -> list[dict[str, Any]]:
|
||||
provider_cfg = config.get("provider") if isinstance(config, dict) else None
|
||||
if not isinstance(provider_cfg, dict) or not provider_cfg:
|
||||
return []
|
||||
|
||||
try:
|
||||
from ProviderCore.registry import get_plugin_class
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
checks: list[dict[str, Any]] = []
|
||||
for plugin_name in provider_cfg.keys():
|
||||
plugin_key = str(plugin_name or "").strip().lower()
|
||||
if not plugin_key:
|
||||
continue
|
||||
|
||||
plugin_class = None
|
||||
try:
|
||||
plugin_class = get_plugin_class(plugin_key)
|
||||
except Exception:
|
||||
plugin_class = None
|
||||
|
||||
if plugin_class is None:
|
||||
checks.append(
|
||||
{
|
||||
"status": "UNKNOWN",
|
||||
"name": provider_display_name(plugin_key),
|
||||
"plugin": plugin_key,
|
||||
"detail": "Not registered",
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
plugin = plugin_class(config)
|
||||
summary = plugin.status_summary()
|
||||
except Exception as exc:
|
||||
summary = {
|
||||
"status": "DISABLED",
|
||||
"name": provider_display_name(plugin_key),
|
||||
"plugin": plugin_key,
|
||||
"detail": str(exc),
|
||||
}
|
||||
|
||||
checks.append(
|
||||
{
|
||||
"status": str(summary.get("status") or "UNKNOWN"),
|
||||
"name": str(summary.get("name") or provider_display_name(plugin_key)),
|
||||
"plugin": str(summary.get("plugin") or plugin_key),
|
||||
"detail": str(summary.get("detail") or ""),
|
||||
"files": summary.get("files"),
|
||||
}
|
||||
)
|
||||
|
||||
return checks
|
||||
Reference in New Issue
Block a user