"""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", {}))
