From ccf6ee08b41ebd4ae3bd56bd8a43b8bc6ee624c5 Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 4 Jul 2025 16:06:06 -0400 Subject: [PATCH] Added code to get duration from a flac file --- src/properties.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/properties.rs b/src/properties.rs index 1989cfd..90ed30b 100644 --- a/src/properties.rs +++ b/src/properties.rs @@ -1,9 +1,23 @@ +use lofty::file::AudioFile; #[derive(Debug, Default, Clone)] pub struct Duration { pub val: i32 } -pub fn get_duration(song_path: &String) -> Duration { - Duration::default() +pub fn get_duration(song_path: &String) -> Result { + match std::fs::File::open(song_path) { + Ok(mut content) => match lofty::flac::FlacFile::read_from(&mut content, lofty::config::ParseOptions::new(),) { + Ok(flac_file) => { + let properties = flac_file.properties(); + Ok(properties.duration()) + } + Err(err) => { + Err(std::io::Error::other(err.to_string())) + } + } + Err(err) => { + Err(err) + } + } }