move ffprobe stuff to its own crate/module

This commit is contained in:
chaos 2023-10-30 22:49:09 +00:00
parent e9cf51e291
commit 12b0b687ae
No known key found for this signature in database
12 changed files with 41 additions and 14 deletions

9
Cargo.lock generated
View file

@ -366,6 +366,14 @@ version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
[[package]]
name = "ffprobe"
version = "0.1.0"
dependencies = [
"serde",
"serde_json",
]
[[package]]
name = "filetime"
version = "0.2.22"
@ -668,6 +676,7 @@ dependencies = [
"ascii_reduce",
"bytes",
"clap",
"ffprobe",
"html-escape",
"id3",
"infer",

View file

@ -25,8 +25,6 @@ clap = { version = "4", features = ["derive"] }
# useful for when storing music files on mp3 players with broken unicode support
ascii_reduce = { path = "./modules/ascii_reduce" }
# transcode presets & format handlers
lazy_static = "1"
@ -41,6 +39,7 @@ bytes = "1"
id3 = { version = "1", optional = true }
metaflac = { version = "0.2", optional = true }
taglib = { path = "./modules/taglib", optional = true }
ffprobe = { path = "./modules/ffprobe" }
# for genhtml command
html-escape = { version = "0.2", optional = true }

View file

@ -42,6 +42,13 @@
"
'';
postFixup = ''
wrapProgram $out/bin/some-script \
--set PATH ${lib.makeBinPath [
pkgs.ffmpeg
]}
'';
postPatch = ''
substituteInPlace src/meta.rs --replace 'ffmpeg' '${pkgs.ffmpeg}/bin/ffmpeg'
substituteInPlace src/meta.rs --replace 'ffprobe' '${pkgs.ffmpeg}/bin/ffprobe'

View file

@ -1,5 +1,13 @@
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
#[cfg(test)]
mod tests {
#[test]
fn test() {
assert_eq!(crate::reduce("öwo owö 😊".to_string()), "owo owo ");
}
}
pub fn reduce(input: String) -> String {
if input.is_ascii() {
return input;

View file

@ -0,0 +1,8 @@
[package]
name = "ffprobe"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0.0", features = ["derive"] }
serde_json = "1.0"

View file

@ -1,13 +1,13 @@
pub mod errors;
mod ffprobe_output;
pub mod types;
mod ffprobe_output;
use std::{convert::Into, path::Path, process::Command};
use self::errors::{AnalyzeError, FFProbeError};
fn extract(path: &Path) -> Result<ffprobe_output::FFProbeOutput, AnalyzeError> {
let output = Command::new(crate::meta::FFPROBE)
fn extract(path: &Path, ffprobe_command: Option<&str>) -> Result<ffprobe_output::FFProbeOutput, AnalyzeError> {
let output = Command::new(ffprobe_command.unwrap_or("ffprobe"))
.args([
"-v",
"quiet",
@ -39,8 +39,8 @@ fn extract(path: &Path) -> Result<ffprobe_output::FFProbeOutput, AnalyzeError> {
Ok(ffprobe_out.unwrap())
}
pub fn analyze(path: &Path) -> Result<types::FFProbeData, AnalyzeError> {
let raw_data = extract(path)?;
pub fn analyze(path: &Path, ffprobe_command: Option<&str>) -> Result<types::FFProbeData, AnalyzeError> {
let raw_data = extract(path, ffprobe_command)?;
let mut data = types::FFProbeData {
tags: raw_data.format.tags.into(),

View file

View file

@ -7,11 +7,8 @@ use string_error::into_err;
use crate::{
types::{AudioFileInfo, ReplayGainData, ReplayGainRawData, Tags},
utils::formats::{AudioFormatError, BoxedError, FormatHandler},
utils::{
ffprobe,
format_detection::{detect_format, FileFormat},
},
utils::format_detection::{detect_format, FileFormat},
utils::formats::{AudioFormatError, BoxedError, FormatHandler}, meta,
};
#[derive(Default)]
@ -36,7 +33,7 @@ pub struct GenericFFMpegAudioFormat {
impl GenericFFMpegAudioFormat {
fn analyze(&mut self) -> Result<(), BoxedError> {
let output = ffprobe::analyze(&self.path);
let output = ffprobe::analyze(&self.path, Some(meta::FFPROBE));
if let Err(err) = output {
return Err(into_err(format!("{}", err)));

View file

@ -1,4 +1,3 @@
pub mod ffprobe;
pub mod format_detection;
#[cfg(feature = "replaygain")]
pub mod replaygain;