extract more info using ffprobe for album art detection
This commit is contained in:
parent
321d89706f
commit
96117c2faf
|
@ -3,6 +3,18 @@ use serde::Deserialize;
|
|||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct FFProbeOutput {
|
||||
pub format: FFProbeOutputFormat,
|
||||
pub streams: Vec<FFProbeOutputStream>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct FFProbeOutputStream {
|
||||
pub index: u8,
|
||||
pub channels: Option<u8>,
|
||||
pub duration: String,
|
||||
pub codec_name: String,
|
||||
pub codec_type: String,
|
||||
pub height: Option<u16>,
|
||||
pub width: Option<u16>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{convert::Into, path::Path, process::Command};
|
|||
|
||||
use self::errors::{AnalyzeError, FFProbeError};
|
||||
|
||||
pub fn analyze(path: &Path) -> Result<types::FFProbeData, AnalyzeError> {
|
||||
fn extract(path: &Path) -> Result<ffprobe_output::FFProbeOutput, AnalyzeError> {
|
||||
let output = Command::new(crate::meta::FFPROBE)
|
||||
.args([
|
||||
"-v",
|
||||
|
@ -14,6 +14,7 @@ pub fn analyze(path: &Path) -> Result<types::FFProbeData, AnalyzeError> {
|
|||
"-print_format",
|
||||
"json",
|
||||
"-show_format",
|
||||
"-show_streams",
|
||||
path.to_str().unwrap(),
|
||||
])
|
||||
.output();
|
||||
|
@ -35,9 +36,26 @@ pub fn analyze(path: &Path) -> Result<types::FFProbeData, AnalyzeError> {
|
|||
let ffprobe_out: serde_json::Result<ffprobe_output::FFProbeOutput> =
|
||||
serde_json::from_str(output.as_str());
|
||||
|
||||
let ffprobe_out = ffprobe_out.unwrap();
|
||||
|
||||
Ok(types::FFProbeData {
|
||||
tags: ffprobe_out.format.tags.into(),
|
||||
})
|
||||
Ok(ffprobe_out.unwrap())
|
||||
}
|
||||
|
||||
pub fn analyze(path: &Path) -> Result<types::FFProbeData, AnalyzeError> {
|
||||
let raw_data = extract(path)?;
|
||||
|
||||
let mut data = types::FFProbeData {
|
||||
tags: raw_data.format.tags.into(),
|
||||
album_art: None,
|
||||
};
|
||||
|
||||
for stream in raw_data.streams.into_iter() {
|
||||
if stream.codec_type == "video" {
|
||||
data.album_art = Some(types::FFProbeAlbumArt {
|
||||
codec_name: stream.codec_name,
|
||||
height: stream.height.unwrap(),
|
||||
width: stream.width.unwrap(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Ok(data)
|
||||
}
|
||||
|
|
|
@ -21,7 +21,15 @@ impl From<ffprobe_output::FFProbeOutputTags> for FFProbeTags {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct FFProbeAlbumArt {
|
||||
pub codec_name: String,
|
||||
pub height: u16,
|
||||
pub width: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct FFProbeData {
|
||||
pub tags: FFProbeTags,
|
||||
pub album_art: Option<FFProbeAlbumArt>,
|
||||
}
|
||||
|
|
|
@ -6,17 +6,21 @@ use lazy_static::lazy_static;
|
|||
|
||||
use super::{BoxedError, FormatHandler};
|
||||
|
||||
#[cfg(feature = "mp3_extractor")]
|
||||
mod id3;
|
||||
#[cfg(feature = "flac_extractor")]
|
||||
mod flac;
|
||||
#[cfg(feature = "taglib_extractor")]
|
||||
mod taglib;
|
||||
#[cfg(feature = "ffprobe_extractor")]
|
||||
mod ffprobe;
|
||||
#[cfg(feature = "flac_extractor")]
|
||||
mod flac;
|
||||
#[cfg(feature = "mp3_extractor")]
|
||||
mod id3;
|
||||
#[cfg(feature = "taglib_extractor")]
|
||||
mod taglib;
|
||||
|
||||
|
||||
#[cfg(not(any(feature = "mp3_extractor", feature = "flac_extractor", feature = "taglib_extractor", feature = "ffprobe_extractor")))]
|
||||
#[cfg(not(any(
|
||||
feature = "mp3_extractor",
|
||||
feature = "flac_extractor",
|
||||
feature = "taglib_extractor",
|
||||
feature = "ffprobe_extractor"
|
||||
)))]
|
||||
compile_error!("at least one extractor feature must be enabled");
|
||||
|
||||
type NewHandlerFuncReturn = Result<Box<dyn FormatHandler>, BoxedError>;
|
||||
|
|
Loading…
Reference in a new issue