f
This commit is contained in:
48
MPV/format_probe.py
Normal file
48
MPV/format_probe.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[1]
|
||||
if str(REPO_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(REPO_ROOT))
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
args = list(sys.argv[1:] if argv is None else argv)
|
||||
if not args:
|
||||
payload: Dict[str, Any] = {
|
||||
"success": False,
|
||||
"stdout": "",
|
||||
"stderr": "",
|
||||
"error": "Missing url",
|
||||
"table": None,
|
||||
}
|
||||
print(json.dumps(payload, ensure_ascii=False))
|
||||
return 2
|
||||
|
||||
url = str(args[0] or "").strip()
|
||||
captured_stdout = io.StringIO()
|
||||
captured_stderr = io.StringIO()
|
||||
with contextlib.redirect_stdout(captured_stdout), contextlib.redirect_stderr(captured_stderr):
|
||||
from MPV.pipeline_helper import _run_op
|
||||
|
||||
payload = _run_op("ytdlp-formats", {"url": url})
|
||||
|
||||
noisy_stdout = captured_stdout.getvalue().strip()
|
||||
noisy_stderr = captured_stderr.getvalue().strip()
|
||||
if noisy_stdout:
|
||||
payload["stdout"] = "\n".join(filter(None, [str(payload.get("stdout") or "").strip(), noisy_stdout]))
|
||||
if noisy_stderr:
|
||||
payload["stderr"] = "\n".join(filter(None, [str(payload.get("stderr") or "").strip(), noisy_stderr]))
|
||||
|
||||
print(json.dumps(payload, ensure_ascii=False))
|
||||
return 0 if payload.get("success") else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user