move ffprobe stuff to its own crate/module
This commit is contained in:
parent
e9cf51e291
commit
12b0b687ae
9
Cargo.lock
generated
9
Cargo.lock
generated
|
@ -366,6 +366,14 @@ version = "2.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ffprobe"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filetime"
|
name = "filetime"
|
||||||
version = "0.2.22"
|
version = "0.2.22"
|
||||||
|
@ -668,6 +676,7 @@ dependencies = [
|
||||||
"ascii_reduce",
|
"ascii_reduce",
|
||||||
"bytes",
|
"bytes",
|
||||||
"clap",
|
"clap",
|
||||||
|
"ffprobe",
|
||||||
"html-escape",
|
"html-escape",
|
||||||
"id3",
|
"id3",
|
||||||
"infer",
|
"infer",
|
||||||
|
|
|
@ -25,8 +25,6 @@ clap = { version = "4", features = ["derive"] }
|
||||||
# useful for when storing music files on mp3 players with broken unicode support
|
# useful for when storing music files on mp3 players with broken unicode support
|
||||||
ascii_reduce = { path = "./modules/ascii_reduce" }
|
ascii_reduce = { path = "./modules/ascii_reduce" }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# transcode presets & format handlers
|
# transcode presets & format handlers
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
|
|
||||||
|
@ -41,6 +39,7 @@ bytes = "1"
|
||||||
id3 = { version = "1", optional = true }
|
id3 = { version = "1", optional = true }
|
||||||
metaflac = { version = "0.2", optional = true }
|
metaflac = { version = "0.2", optional = true }
|
||||||
taglib = { path = "./modules/taglib", optional = true }
|
taglib = { path = "./modules/taglib", optional = true }
|
||||||
|
ffprobe = { path = "./modules/ffprobe" }
|
||||||
|
|
||||||
# for genhtml command
|
# for genhtml command
|
||||||
html-escape = { version = "0.2", optional = true }
|
html-escape = { version = "0.2", optional = true }
|
||||||
|
|
|
@ -42,6 +42,13 @@
|
||||||
"
|
"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
postFixup = ''
|
||||||
|
wrapProgram $out/bin/some-script \
|
||||||
|
--set PATH ${lib.makeBinPath [
|
||||||
|
pkgs.ffmpeg
|
||||||
|
]}
|
||||||
|
'';
|
||||||
|
|
||||||
postPatch = ''
|
postPatch = ''
|
||||||
substituteInPlace src/meta.rs --replace 'ffmpeg' '${pkgs.ffmpeg}/bin/ffmpeg'
|
substituteInPlace src/meta.rs --replace 'ffmpeg' '${pkgs.ffmpeg}/bin/ffmpeg'
|
||||||
substituteInPlace src/meta.rs --replace 'ffprobe' '${pkgs.ffmpeg}/bin/ffprobe'
|
substituteInPlace src/meta.rs --replace 'ffprobe' '${pkgs.ffmpeg}/bin/ffprobe'
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
include!(concat!(env!("OUT_DIR"), "/codegen.rs"));
|
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 {
|
pub fn reduce(input: String) -> String {
|
||||||
if input.is_ascii() {
|
if input.is_ascii() {
|
||||||
return input;
|
return input;
|
||||||
|
|
8
modules/ffprobe/Cargo.toml
Normal file
8
modules/ffprobe/Cargo.toml
Normal 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"
|
|
@ -1,13 +1,13 @@
|
||||||
pub mod errors;
|
pub mod errors;
|
||||||
mod ffprobe_output;
|
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
mod ffprobe_output;
|
||||||
|
|
||||||
use std::{convert::Into, path::Path, process::Command};
|
use std::{convert::Into, path::Path, process::Command};
|
||||||
|
|
||||||
use self::errors::{AnalyzeError, FFProbeError};
|
use self::errors::{AnalyzeError, FFProbeError};
|
||||||
|
|
||||||
fn extract(path: &Path) -> Result<ffprobe_output::FFProbeOutput, AnalyzeError> {
|
fn extract(path: &Path, ffprobe_command: Option<&str>) -> Result<ffprobe_output::FFProbeOutput, AnalyzeError> {
|
||||||
let output = Command::new(crate::meta::FFPROBE)
|
let output = Command::new(ffprobe_command.unwrap_or("ffprobe"))
|
||||||
.args([
|
.args([
|
||||||
"-v",
|
"-v",
|
||||||
"quiet",
|
"quiet",
|
||||||
|
@ -39,8 +39,8 @@ fn extract(path: &Path) -> Result<ffprobe_output::FFProbeOutput, AnalyzeError> {
|
||||||
Ok(ffprobe_out.unwrap())
|
Ok(ffprobe_out.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn analyze(path: &Path) -> Result<types::FFProbeData, AnalyzeError> {
|
pub fn analyze(path: &Path, ffprobe_command: Option<&str>) -> Result<types::FFProbeData, AnalyzeError> {
|
||||||
let raw_data = extract(path)?;
|
let raw_data = extract(path, ffprobe_command)?;
|
||||||
|
|
||||||
let mut data = types::FFProbeData {
|
let mut data = types::FFProbeData {
|
||||||
tags: raw_data.format.tags.into(),
|
tags: raw_data.format.tags.into(),
|
0
modules/ffprobe/src/meta.rs
Normal file
0
modules/ffprobe/src/meta.rs
Normal file
|
@ -7,11 +7,8 @@ use string_error::into_err;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
types::{AudioFileInfo, ReplayGainData, ReplayGainRawData, Tags},
|
types::{AudioFileInfo, ReplayGainData, ReplayGainRawData, Tags},
|
||||||
utils::formats::{AudioFormatError, BoxedError, FormatHandler},
|
utils::format_detection::{detect_format, FileFormat},
|
||||||
utils::{
|
utils::formats::{AudioFormatError, BoxedError, FormatHandler}, meta,
|
||||||
ffprobe,
|
|
||||||
format_detection::{detect_format, FileFormat},
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -36,7 +33,7 @@ pub struct GenericFFMpegAudioFormat {
|
||||||
|
|
||||||
impl GenericFFMpegAudioFormat {
|
impl GenericFFMpegAudioFormat {
|
||||||
fn analyze(&mut self) -> Result<(), BoxedError> {
|
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 {
|
if let Err(err) = output {
|
||||||
return Err(into_err(format!("{}", err)));
|
return Err(into_err(format!("{}", err)));
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
pub mod ffprobe;
|
|
||||||
pub mod format_detection;
|
pub mod format_detection;
|
||||||
#[cfg(feature = "replaygain")]
|
#[cfg(feature = "replaygain")]
|
||||||
pub mod replaygain;
|
pub mod replaygain;
|
||||||
|
|
Loading…
Reference in a new issue