From 631300e5a21531f72e8ff272cd5dc2db986d1fe1 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 16 Apr 2025 21:10:17 -0400 Subject: [PATCH] Add test to make sure it works --- src/meta.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/meta.rs b/src/meta.rs index 218fa80..becd863 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -23,7 +23,7 @@ pub mod coverart { song_filepath: &String, coverart_filepath: &String, ) -> Result, std::io::Error> { - let _coverart_path = std::path::Path::new(coverart_filepath); + let coverart_path = std::path::Path::new(coverart_filepath); match std::fs::File::open(song_filepath) { Ok(mut file) => { @@ -31,7 +31,32 @@ pub mod coverart { &mut file, lofty::config::ParseOptions::new(), ) { - Ok(flac_file) => { + Ok(mut flac_file) => { + let mut coverart_file = std::fs::File::open(coverart_path).unwrap(); + match lofty::picture::Picture::from_reader(&mut coverart_file) { + Ok(pic) => { + match lofty::picture::PictureInformation::from_picture(&pic) { + Ok(info) => { + flac_file.set_picture(0, pic, info); + Ok(Vec::new()) + } + Err(err) => Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + err.to_string(), + )), + } + } + Err(err) => Err(std::io::Error::new( + std::io::ErrorKind::InvalidData, + err.to_string(), + )), + } + + /* + let mut bytes: Vec = Vec::new(); + lofty::picture::Picture::from_flac_bytes(bytes, false, lofty::config::ParsingMode::BestAttempt); + flac_file.set_picture(0, picture, info); + let pictures = flac_file.pictures(); let res = pictures.to_vec(); if !res.is_empty() { @@ -40,6 +65,7 @@ pub mod coverart { } else { Ok(Vec::new()) } + */ } Err(err) => Err(std::io::Error::new( std::io::ErrorKind::InvalidData,