Filled out function
Some checks failed
Rust Build / Check (pull_request) Successful in 32s
Rust Build / Test Suite (pull_request) Successful in 44s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Failing after 37s
Rust Build / build (pull_request) Successful in 46s

Add tests
This commit is contained in:
2025-04-14 21:21:45 -04:00
parent 62b8bdd46b
commit 583ea6846f

View File

@@ -1,4 +1,4 @@
use lofty::file::AudioFile;
use lofty::{file::AudioFile, tag::Accessor};
use crate::types;
@@ -46,6 +46,61 @@ pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Er
}
}
pub fn set_meta(
t: types::Type,
filepath: &String,
value: &String,
) -> Result<String, std::io::Error> {
match std::fs::File::open(filepath) {
Ok(mut content) => {
match lofty::flac::FlacFile::read_from(&mut content, lofty::config::ParseOptions::new())
{
Ok(mut flac_file) => match flac_file.vorbis_comments_mut() {
Some(vb) => {
match t {
types::Type::Album => {
vb.set_album(value.clone());
}
types::Type::AlbumArtist => {
vb.insert(get_type(t).unwrap(), value.clone());
}
types::Type::Artist => {
vb.set_artist(value.clone());
}
types::Type::Date => {
vb.insert(get_type(t).unwrap(), value.clone());
}
types::Type::Disc => {
vb.set_disk(value.clone().parse().unwrap());
}
types::Type::Genre => {
vb.set_genre(value.clone());
}
types::Type::Title => {
vb.set_title(value.clone());
}
types::Type::Track => {
vb.set_track(value.clone().parse().unwrap());
}
};
Ok(value.clone())
}
None => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"No tags found",
)),
},
Err(err) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
err.to_string(),
)),
}
}
Err(err) => Err(err),
}
}
#[cfg(test)]
mod tests {
use util::{file_exists, get_full_path};