From 000639b0f8ce30cc3f42817e482b17fded174940 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sat, 19 Apr 2025 21:19:01 +0000 Subject: [PATCH] added_types (#26) Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/26 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.toml | 2 +- src/meta.rs | 171 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/types.rs | 4 ++ 3 files changed, 176 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7a557c4..b818012 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.1.20" +version = "0.1.30" edition = "2024" rust-version = "1.86" diff --git a/src/meta.rs b/src/meta.rs index 59e6957..c73da04 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -211,6 +211,12 @@ pub mod metadata { types::Type::Track => { vb.set_track(pre_value.parse().unwrap()); } + types::Type::TrackCount => { + vb.set_track_total(pre_value.parse().unwrap()); + } + types::Type::DiscCount => { + vb.set_disk_total(pre_value.parse().unwrap()); + } }; Ok(value.to_owned()) @@ -510,6 +516,56 @@ mod tests { } }; } + + #[test] + fn test_get_track_total() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match get_meta(types::Type::TrackCount, &filepath) { + Ok(track_total) => { + let found = track_total == "3"; + assert!(found, "Meta information was not found {:?}", track_total); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + + #[test] + fn test_get_disc_total() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match get_meta(types::Type::DiscCount, &filepath) { + Ok(disc_total) => { + let found = disc_total == "1"; + assert!(found, "Meta information was not found {:?}", disc_total); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } } mod set { @@ -879,6 +935,121 @@ mod tests { } }; } + + #[test] + fn test_set_track_total() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); + + let temp_file = tempfile::tempdir().expect("Could not create test directory"); + let test_dir = String::from(temp_file.path().to_str().unwrap()); + let test_filename = String::from("track08.flac"); + let new_filepath = test_dir + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::TrackCount, &filepath) { + Ok(track_total) => { + let found = track_total == "3"; + assert!(found, "Meta information was not found {:?}", track_total); + let new_track_total = String::from("5"); + + match set_meta( + types::Type::TrackCount, + &new_filepath, + &new_track_total, + ) { + Ok(m) => { + assert_eq!( + new_track_total, m, + "New track does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + + #[test] + fn test_set_disc_total() { + let filename = util::get_filename(1); + let dir = String::from(util::TESTFILEDIRECTORY); + + let temp_file = tempfile::tempdir().expect("Could not create test directory"); + let test_dir = String::from(temp_file.path().to_str().unwrap()); + let test_filename = String::from("track08.flac"); + let new_filepath = test_dir + "/" + &test_filename; + + match file_exists(&dir, &filename) { + Ok(_) => { + let filepath = get_full_path(&dir, &filename).unwrap(); + + match util::copy_file(&filepath, &new_filepath) { + Ok(_o) => match get_meta(types::Type::DiscCount, &filepath) { + Ok(disc_total) => { + let found = disc_total == "1"; + assert!(found, "Meta information was not found {:?}", disc_total); + let new_disc_total = String::from("2"); + + match set_meta( + types::Type::DiscCount, + &new_filepath, + &new_disc_total, + ) { + Ok(m) => { + assert_eq!( + new_disc_total, m, + "New disc_total does not match {:?}", + m + ); + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + } + } + Err(err) => { + assert!(false, "Error: {:?}", err); + } + }, + Err(err) => { + assert!( + false, + "Error: {:?} source {:?} destination {:?}", + err, filepath, new_filepath + ); + } + }; + } + Err(err) => { + assert!(false, "Error: File does not exist {:?}", err.to_string()); + } + }; + } + #[test] fn test_set_genre() { let filename = util::get_filename(1); diff --git a/src/types.rs b/src/types.rs index c2bf9a9..26dbca1 100644 --- a/src/types.rs +++ b/src/types.rs @@ -7,6 +7,8 @@ pub enum Type { Date, Track, Disc, + TrackCount, + DiscCount, } pub mod access { @@ -21,6 +23,8 @@ pub mod access { super::Type::Date => Ok("DATE".to_owned()), super::Type::Track => Ok("TRACKNUMBER".to_owned()), super::Type::Disc => Ok("DISCNUMBER".to_owned()), + super::Type::TrackCount => Ok("TRACKCOUNT".to_owned()), + super::Type::DiscCount => Ok("DISCCOUNT".to_owned()), } } }