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:
+35
-25
@@ -67,6 +67,7 @@ from SYS.config import load_config, reload_config # noqa: E402
|
||||
from SYS.logger import set_debug, debug, set_thread_stream # noqa: E402
|
||||
from SYS.repl_queue import enqueue_repl_command # noqa: E402
|
||||
from SYS.utils import format_bytes # noqa: E402
|
||||
from ProviderCore.registry import get_plugin, get_plugin_class # noqa: E402
|
||||
|
||||
REQUEST_PROP = "user-data/medeia-pipeline-request"
|
||||
RESPONSE_PROP = "user-data/medeia-pipeline-response"
|
||||
@@ -936,39 +937,36 @@ def _run_op(op: str, data: Any) -> Dict[str, Any]:
|
||||
"table": None,
|
||||
}
|
||||
|
||||
cfg = load_config() or {}
|
||||
plugin = get_plugin("ytdlp", cfg)
|
||||
if plugin is None or not hasattr(plugin, "list_url_formats"):
|
||||
return {
|
||||
"success": False,
|
||||
"stdout": "",
|
||||
"stderr": "",
|
||||
"error": "yt-dlp plugin unavailable",
|
||||
"table": None,
|
||||
}
|
||||
|
||||
try:
|
||||
from tool.ytdlp import list_formats, is_browseable_format # noqa: WPS433
|
||||
formats = plugin.list_url_formats(
|
||||
url,
|
||||
no_playlist=True,
|
||||
timeout_seconds=25,
|
||||
)
|
||||
except Exception as exc:
|
||||
return {
|
||||
"success": False,
|
||||
"stdout": "",
|
||||
"stderr": "",
|
||||
"error": f"yt-dlp tool unavailable: {type(exc).__name__}: {exc}",
|
||||
"error": f"yt-dlp plugin probe failed: {type(exc).__name__}: {exc}",
|
||||
"table": None,
|
||||
}
|
||||
|
||||
cookiefile = None
|
||||
try:
|
||||
from tool.ytdlp import YtDlpTool # noqa: WPS433
|
||||
|
||||
cfg = load_config() or {}
|
||||
cookie_path = YtDlpTool(cfg).resolve_cookiefile()
|
||||
if cookie_path is not None:
|
||||
cookiefile = str(cookie_path)
|
||||
except Exception:
|
||||
cookiefile = None
|
||||
|
||||
def _format_bytes(n: Any) -> str:
|
||||
"""Format bytes using centralized utility."""
|
||||
return format_bytes(n)
|
||||
|
||||
formats = list_formats(
|
||||
url,
|
||||
no_playlist=True,
|
||||
cookiefile=cookiefile,
|
||||
timeout_seconds=25,
|
||||
)
|
||||
|
||||
if formats is None:
|
||||
return {
|
||||
"success": False,
|
||||
@@ -990,9 +988,10 @@ def _run_op(op: str, data: Any) -> Dict[str, Any]:
|
||||
},
|
||||
}
|
||||
|
||||
browseable = [f for f in formats if is_browseable_format(f)]
|
||||
if browseable:
|
||||
formats = browseable
|
||||
try:
|
||||
formats = plugin.filter_picker_formats(formats)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Debug: dump a short summary of the format list to the helper log.
|
||||
try:
|
||||
@@ -2040,8 +2039,19 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
|
||||
# Publish yt-dlp supported domains for Lua menu filtering
|
||||
try:
|
||||
from tool.ytdlp import _build_supported_domains
|
||||
domains = sorted(list(_build_supported_domains()))
|
||||
plugin_class = get_plugin_class("ytdlp")
|
||||
domains = []
|
||||
if plugin_class is not None:
|
||||
domains = sorted(
|
||||
{
|
||||
str(value).strip().lower()
|
||||
for value in plugin_class.url_patterns()
|
||||
if isinstance(value, str)
|
||||
and str(value).strip()
|
||||
and "://" not in str(value)
|
||||
and not str(value).strip().endswith(":")
|
||||
}
|
||||
)
|
||||
if domains:
|
||||
# We join them into a space-separated string for Lua to parse easily
|
||||
domains_str = " ".join(domains)
|
||||
|
||||
Reference in New Issue
Block a user