Verify OGG file properties using ffprobe.
(ffmpeg: str, path: Path)
| 402 | |
| 403 | |
| 404 | def verify_ogg(ffmpeg: str, path: Path) -> dict[str, str | int | float]: # noqa: DCT001 |
| 405 | """Verify OGG file properties using ffprobe.""" |
| 406 | ffprobe = shutil.which("ffprobe") |
| 407 | if not ffprobe: |
| 408 | # Try alongside ffmpeg |
| 409 | ffprobe_path = Path(ffmpeg).parent / "ffprobe" |
| 410 | if ffprobe_path.exists(): |
| 411 | ffprobe = str(ffprobe_path) |
| 412 | else: |
| 413 | ffprobe_path = Path(ffmpeg).parent / "ffprobe.exe" |
| 414 | if ffprobe_path.exists(): |
| 415 | ffprobe = str(ffprobe_path) |
| 416 | if not ffprobe: |
| 417 | return {"error": "ffprobe not found"} |
| 418 | |
| 419 | result = subprocess.run( |
| 420 | [ |
| 421 | ffprobe, |
| 422 | "-v", |
| 423 | "quiet", |
| 424 | "-print_format", |
| 425 | "json", |
| 426 | "-show_streams", |
| 427 | str(path), |
| 428 | ], |
| 429 | capture_output=True, |
| 430 | text=True, |
| 431 | ) |
| 432 | if result.returncode != 0: |
| 433 | return {"error": result.stderr[:200]} |
| 434 | |
| 435 | import json |
| 436 | |
| 437 | info = json.loads(result.stdout) |
| 438 | streams = info.get("streams", []) |
| 439 | if not streams: |
| 440 | return {"error": "no streams"} |
| 441 | s = streams[0] |
| 442 | return { |
| 443 | "codec": s.get("codec_name", "?"), |
| 444 | "sample_rate": int(s.get("sample_rate", 0)), |
| 445 | "channels": int(s.get("channels", 0)), |
| 446 | "duration": float(s.get("duration", 0)), |
| 447 | "size_kb": path.stat().st_size // 1024, |
| 448 | } |
| 449 | |
| 450 | |
| 451 | def main() -> None: |