This commit is contained in:
2026-01-12 17:55:04 -08:00
parent e45138568f
commit d0a68da1f5
8 changed files with 318 additions and 553 deletions

View File

@@ -262,13 +262,14 @@ class MPV:
def send(self,
command: Dict[str,
Any] | List[Any],
silent: bool = False) -> Optional[Dict[str,
silent: bool = False,
wait: bool = True) -> Optional[Dict[str,
Any]]:
client = self.client(silent=bool(silent))
try:
if not client.connect():
return None
return client.send_command(command)
return client.send_command(command, wait=wait)
except Exception as exc:
if not silent:
debug(f"MPV IPC error: {exc}")
@@ -627,7 +628,8 @@ class MPV:
# Ensure uosc.conf is available at the location uosc expects.
try:
src_uosc_conf = repo_root / "MPV" / "LUA" / "uosc" / "uosc.conf"
# Source uosc.conf is located within the bundled scripts.
src_uosc_conf = repo_root / "MPV" / "portable_config" / "scripts" / "uosc" / "uosc.conf"
dst_uosc_conf = portable_config_dir / "script-opts" / "uosc.conf"
if src_uosc_conf.exists():
# Only seed a default config if the user doesn't already have one.
@@ -639,16 +641,8 @@ class MPV:
cmd: List[str] = [
"mpv",
f"--config-dir={str(portable_config_dir)}",
# Allow mpv to auto-load scripts from <config-dir>/scripts/ (e.g., thumbfast).
"--load-scripts=yes",
"--osc=no",
"--load-console=no",
"--load-commands=no",
"--load-select=no",
"--load-context-menu=no",
"--load-positioning=no",
"--load-stats-overlay=no",
"--load-auto-profiles=no",
"--ytdl=yes",
f"--input-ipc-server={self.ipc_path}",
"--idle=yes",
@@ -656,14 +650,21 @@ class MPV:
]
# uosc and other scripts are expected to be auto-loaded from portable_config/scripts.
# We keep the back-compat fallback only if the user hasn't installed uosc.lua there.
# If --load-scripts=yes is set (standard), mpv will already pick up the loader shim
# at scripts/uosc.lua. We only add a manual --script fallback if that file is missing.
try:
uosc_entry = portable_config_dir / "scripts" / "uosc.lua"
if not uosc_entry.exists() and self.lua_script_path:
lua_dir = Path(self.lua_script_path).resolve().parent
uosc_main = lua_dir / "uosc" / "scripts" / "uosc" / "main.lua"
if uosc_main.exists():
cmd.append(f"--script={str(uosc_main)}")
# Check different possible source locations for uosc core.
uosc_paths = [
portable_config_dir / "scripts" / "uosc" / "scripts" / "uosc" / "main.lua",
lua_dir / "uosc" / "scripts" / "uosc" / "main.lua"
]
for p in uosc_paths:
if p.exists():
cmd.append(f"--script={str(p)}")
break
except Exception:
pass
@@ -1002,12 +1003,14 @@ class MPVIPCClient:
def send_command(self,
command_data: Dict[str,
Any] | List[Any]) -> Optional[Dict[str,
Any] | List[Any],
wait: bool = True) -> Optional[Dict[str,
Any]]:
"""Send a command to mpv and get response.
Args:
command_data: Command dict (e.g. {"command": [...]}) or list (e.g. ["loadfile", ...])
wait: If True, wait for the command response.
Returns:
Response dict with 'error' key (value 'success' on success), or None on error.
@@ -1030,6 +1033,7 @@ class MPVIPCClient:
if "request_id" not in request:
request["request_id"] = int(_time.time() * 1000) % 100000
rid = request["request_id"]
payload = json.dumps(request) + "\n"
# Debug: log the command being sent
@@ -1040,6 +1044,9 @@ class MPVIPCClient:
# Send command
self._write_payload(payload)
if not wait:
return {"error": "success", "request_id": rid, "async": True}
# Receive response
# We need to read lines until we find the one with matching request_id
# or until timeout/error. MPV might send events in between.