use crate::command::BackgroundCommand;
use anyhow::Context;
use std::{env::current_exe, ffi::OsStr, path::PathBuf};
use std::{
path::Path,
process::{Command, Stdio},
};
pub fn ffprobe_path() -> PathBuf {
let default = Path::new("ffprobe").to_path_buf();
match ffprobe_sidecar_path() {
Ok(sidecar_path) => match sidecar_path.exists() {
true => sidecar_path,
false => default,
},
Err(_) => default,
}
}
pub fn ffprobe_sidecar_path() -> anyhow::Result<PathBuf> {
let mut path = current_exe()?
.parent()
.context("Can't get parent of current_exe")?
.join("ffprobe");
if cfg!(windows) {
path.set_extension("exe");
}
Ok(path)
}
pub fn ffprobe_version() -> anyhow::Result<String> {
ffprobe_version_with_path(ffprobe_path())
}
pub fn ffprobe_version_with_path<S: AsRef<OsStr>>(path: S) -> anyhow::Result<String> {
let output = Command::new(&path)
.arg("-version")
.create_no_window()
.output()?;
Ok(String::from_utf8(output.stdout)?)
}
pub fn ffprobe_is_installed() -> bool {
Command::new(ffprobe_path())
.create_no_window()
.arg("-version")
.stderr(Stdio::null())
.stdout(Stdio::null())
.status()
.map(|s| s.success())
.unwrap_or_else(|_| false)
}