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:
@@ -17,6 +17,7 @@ Protocol (user-data properties):
|
||||
|
||||
This helper is intentionally minimal: one request at a time, last-write-wins.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
MEDEIA_MPV_HELPER_VERSION = "2025-12-19"
|
||||
@@ -72,8 +73,6 @@ READY_PROP = "user-data/medeia-pipeline-ready"
|
||||
|
||||
OBS_ID_REQUEST = 1001
|
||||
|
||||
|
||||
|
||||
|
||||
def _run_pipeline(pipeline_text: str, *, seeds: Any = None) -> Dict[str, Any]:
|
||||
# Import after sys.path fix.
|
||||
@@ -181,7 +180,13 @@ def _run_op(op: str, data: Any) -> Dict[str, Any]:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
cmd = [py, str((_repo_root() / "CLI.py").resolve()), "pipeline", "--pipeline", pipeline_text]
|
||||
cmd = [
|
||||
py,
|
||||
str((_repo_root() / "CLI.py").resolve()),
|
||||
"pipeline",
|
||||
"--pipeline",
|
||||
pipeline_text,
|
||||
]
|
||||
if seeds is not None:
|
||||
try:
|
||||
cmd.extend(["--seeds-json", json.dumps(seeds, ensure_ascii=False)])
|
||||
@@ -265,7 +270,7 @@ def _run_op(op: str, data: Any) -> Dict[str, Any]:
|
||||
name = None
|
||||
if isinstance(instance_cfg, dict):
|
||||
name = instance_cfg.get("NAME") or instance_cfg.get("name")
|
||||
candidate = (str(name or instance_key or "").strip())
|
||||
candidate = str(name or instance_key or "").strip()
|
||||
if candidate:
|
||||
seen.add(candidate)
|
||||
choices = sorted(seen)
|
||||
@@ -419,7 +424,11 @@ def _run_op(op: str, data: Any) -> Dict[str, Any]:
|
||||
if dump and dump != "0" and isinstance(info, dict):
|
||||
h = hashlib.sha1(url.encode("utf-8", errors="replace")).hexdigest()[:10]
|
||||
out_path = _repo_root() / "Log" / f"ytdlp-probe-{h}.json"
|
||||
out_path.write_text(json.dumps(info, ensure_ascii=False, indent=2), encoding="utf-8", errors="replace")
|
||||
out_path.write_text(
|
||||
json.dumps(info, ensure_ascii=False, indent=2),
|
||||
encoding="utf-8",
|
||||
errors="replace",
|
||||
)
|
||||
_append_helper_log(f"[ytdlp-formats] wrote probe json: {out_path}")
|
||||
except Exception:
|
||||
pass
|
||||
@@ -610,7 +619,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
if debug_enabled:
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG,
|
||||
format='[%(name)s] %(levelname)s: %(message)s',
|
||||
format="[%(name)s] %(levelname)s: %(message)s",
|
||||
stream=sys.stderr,
|
||||
)
|
||||
for noisy in ("httpx", "httpcore", "httpcore.http11", "httpcore.connection"):
|
||||
@@ -628,13 +637,17 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
# Ensure single helper instance per ipc.
|
||||
_lock_fh = _acquire_ipc_lock(str(args.ipc))
|
||||
if _lock_fh is None:
|
||||
_append_helper_log(f"[helper] another instance already holds lock for ipc={args.ipc}; exiting")
|
||||
_append_helper_log(
|
||||
f"[helper] another instance already holds lock for ipc={args.ipc}; exiting"
|
||||
)
|
||||
return 0
|
||||
|
||||
try:
|
||||
_append_helper_log(f"[helper] version={MEDEIA_MPV_HELPER_VERSION} started ipc={args.ipc}")
|
||||
try:
|
||||
_append_helper_log(f"[helper] file={Path(__file__).resolve()} cwd={Path.cwd().resolve()}")
|
||||
_append_helper_log(
|
||||
f"[helper] file={Path(__file__).resolve()} cwd={Path.cwd().resolve()}"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
@@ -651,6 +664,7 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
# Route SYS.logger output into the helper log file so diagnostics are not
|
||||
# lost in mpv's console/terminal output.
|
||||
try:
|
||||
|
||||
class _HelperLogStream:
|
||||
def __init__(self) -> None:
|
||||
self._pending = ""
|
||||
@@ -726,7 +740,9 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
last_connect_error = f"{type(exc).__name__}: {exc}"
|
||||
|
||||
if time.time() > connect_deadline:
|
||||
_append_helper_log(f"[helper] failed to connect ipc={args.ipc} error={last_connect_error or 'timeout'}")
|
||||
_append_helper_log(
|
||||
f"[helper] failed to connect ipc={args.ipc} error={last_connect_error or 'timeout'}"
|
||||
)
|
||||
return 2
|
||||
|
||||
# Keep trying.
|
||||
@@ -789,31 +805,50 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
# can read immediately without waiting for a request/response cycle (which may timeout).
|
||||
try:
|
||||
startup_choices_payload = _run_op("store-choices", None)
|
||||
startup_choices = startup_choices_payload.get("choices") if isinstance(startup_choices_payload, dict) else None
|
||||
startup_choices = (
|
||||
startup_choices_payload.get("choices")
|
||||
if isinstance(startup_choices_payload, dict)
|
||||
else None
|
||||
)
|
||||
if isinstance(startup_choices, list):
|
||||
preview = ", ".join(str(x) for x in startup_choices[:50])
|
||||
_append_helper_log(f"[helper] startup store-choices count={len(startup_choices)} items={preview}")
|
||||
|
||||
_append_helper_log(
|
||||
f"[helper] startup store-choices count={len(startup_choices)} items={preview}"
|
||||
)
|
||||
|
||||
# Publish to a cached property for Lua to read without IPC request.
|
||||
try:
|
||||
cached_json = json.dumps({"success": True, "choices": startup_choices}, ensure_ascii=False)
|
||||
client.send_command_no_wait(["set_property_string", "user-data/medeia-store-choices-cached", cached_json])
|
||||
_append_helper_log(f"[helper] published store-choices to user-data/medeia-store-choices-cached")
|
||||
cached_json = json.dumps(
|
||||
{"success": True, "choices": startup_choices}, ensure_ascii=False
|
||||
)
|
||||
client.send_command_no_wait(
|
||||
["set_property_string", "user-data/medeia-store-choices-cached", cached_json]
|
||||
)
|
||||
_append_helper_log(
|
||||
f"[helper] published store-choices to user-data/medeia-store-choices-cached"
|
||||
)
|
||||
except Exception as exc:
|
||||
_append_helper_log(f"[helper] failed to publish store-choices: {type(exc).__name__}: {exc}")
|
||||
_append_helper_log(
|
||||
f"[helper] failed to publish store-choices: {type(exc).__name__}: {exc}"
|
||||
)
|
||||
else:
|
||||
_append_helper_log("[helper] startup store-choices unavailable")
|
||||
except Exception as exc:
|
||||
_append_helper_log(f"[helper] startup store-choices failed: {type(exc).__name__}: {exc}")
|
||||
|
||||
|
||||
# Also publish config temp directory if available
|
||||
try:
|
||||
from config import load_config
|
||||
|
||||
cfg = load_config()
|
||||
temp_dir = cfg.get("temp", "").strip() or os.getenv("TEMP") or "/tmp"
|
||||
if temp_dir:
|
||||
client.send_command_no_wait(["set_property_string", "user-data/medeia-config-temp", temp_dir])
|
||||
_append_helper_log(f"[helper] published config temp to user-data/medeia-config-temp={temp_dir}")
|
||||
client.send_command_no_wait(
|
||||
["set_property_string", "user-data/medeia-config-temp", temp_dir]
|
||||
)
|
||||
_append_helper_log(
|
||||
f"[helper] published config temp to user-data/medeia-config-temp={temp_dir}"
|
||||
)
|
||||
except Exception as exc:
|
||||
_append_helper_log(f"[helper] failed to publish config temp: {type(exc).__name__}: {exc}")
|
||||
|
||||
@@ -854,7 +889,9 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
if "quic" in lower_prefix and "DEBUG:" in text:
|
||||
continue
|
||||
# Suppress progress-bar style lines (keep true errors).
|
||||
if ("ETA" in text or "%" in text) and ("ERROR:" not in text and "WARNING:" not in text):
|
||||
if ("ETA" in text or "%" in text) and (
|
||||
"ERROR:" not in text and "WARNING:" not in text
|
||||
):
|
||||
# Typical yt-dlp progress bar line.
|
||||
if text.lstrip().startswith("["):
|
||||
continue
|
||||
@@ -966,7 +1003,9 @@ def main(argv: Optional[list[str]] = None) -> int:
|
||||
try:
|
||||
# IMPORTANT: don't wait for a response here; waiting would consume
|
||||
# async events and can drop/skip property-change notifications.
|
||||
client.send_command_no_wait(["set_property_string", RESPONSE_PROP, json.dumps(resp, ensure_ascii=False)])
|
||||
client.send_command_no_wait(
|
||||
["set_property_string", RESPONSE_PROP, json.dumps(resp, ensure_ascii=False)]
|
||||
)
|
||||
except Exception:
|
||||
# If posting results fails, there's nothing more useful to do.
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user