feat: ffprobe wrapper (tools.probe)
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>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""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", {}))
|
||||
Reference in New Issue
Block a user