19104f94cd
Per sub-project-2 plan Task 3 / spec §5.1. Parses ffprobe JSON into a Probe (streams + format); subprocess runner injectable so tests never shell out. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
35 lines
765 B
Python
35 lines
765 B
Python
"""ffprobe wrapper -> parsed streams/format. Subprocess runner is injectable."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import subprocess
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Probe:
|
|
streams: list
|
|
format: dict
|
|
|
|
|
|
def _default_runner(args) -> str:
|
|
return subprocess.run(args, capture_output=True, text=True, check=True).stdout
|
|
|
|
|
|
def probe_file(path, *, runner=_default_runner) -> Probe:
|
|
out = runner(
|
|
[
|
|
"ffprobe",
|
|
"-v",
|
|
"quiet",
|
|
"-print_format",
|
|
"json",
|
|
"-show_format",
|
|
"-show_streams",
|
|
str(path),
|
|
]
|
|
)
|
|
data = json.loads(out)
|
|
return Probe(streams=data.get("streams", []), format=data.get("format", {}))
|