| 1 | use std::path::{Path, PathBuf}; |
| 2 | use std::process::Command; |
| 3 | |
| 4 | pub fn root() -> PathBuf { |
| 5 | match std::env::var_os("EC_FIXTURES") { |
| 6 | Some(dir) => PathBuf::from(dir), |
| 7 | None => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures"), |
| 8 | } |
| 9 | } |
| 10 | |
| 11 | pub fn fixture(rel: &str) -> PathBuf { |
| 12 | let path = root().join(rel); |
| 13 | if !path.exists() { |
| 14 | panic!("missing fixture {rel}: run scripts/fixtures.sh"); |
| 15 | } |
| 16 | path |
| 17 | } |
| 18 | |
| 19 | pub fn fixtures(dir: &str, ext: &str) -> Vec<PathBuf> { |
| 20 | let mut found: Vec<PathBuf> = std::fs::read_dir(root().join(dir)) |
| 21 | .expect("fixture directory") |
| 22 | .map(|entry| entry.expect("fixture entry").path()) |
| 23 | .filter(|path| path.extension().is_some_and(|e| e == ext)) |
| 24 | .collect(); |
| 25 | found.sort(); |
| 26 | assert!(!found.is_empty(), "no .{ext} fixtures in {dir}"); |
| 27 | found |
| 28 | } |
| 29 | |
| 30 | pub fn ffmpeg_path() -> PathBuf { |
| 31 | let path = match std::env::var_os("EC_FFMPEG") { |
| 32 | Some(path) => PathBuf::from(path), |
| 33 | None => { |
| 34 | PathBuf::from(std::env::var_os("HOME").expect("HOME")).join(".cache/ec-ffmpeg/ffmpeg") |
| 35 | } |
| 36 | }; |
| 37 | if !path.is_file() { |
| 38 | panic!("ffmpeg not found at {}", path.display()); |
| 39 | } |
| 40 | path |
| 41 | } |
| 42 | |
| 43 | pub fn ffprobe_path() -> PathBuf { |
| 44 | ffmpeg_path().with_file_name("ffprobe") |
| 45 | } |
| 46 | |
| 47 | pub fn ffmpeg() -> Command { |
| 48 | Command::new(ffmpeg_path()) |
| 49 | } |
| 50 | |
| 51 | pub fn ffprobe() -> Command { |
| 52 | Command::new(ffprobe_path()) |
| 53 | } |