From 9e30c6db00de8165ff72d099f5a4e621815bfbc2 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:06:30 -0400 Subject: [PATCH 01/14] tsk-44: Added imghdr crate --- Cargo.lock | 7 +++++++ Cargo.toml | 1 + 2 files changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b44e374..a52551b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -83,10 +83,17 @@ dependencies = [ name = "icarus_meta" version = "0.4.0" dependencies = [ + "imghdr", "lofty", "tempfile", ] +[[package]] +name = "imghdr" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8b35f3ad95576ac81603375dfe47a0450b70a368aa34d2b6e5bb0a0d7f02428" + [[package]] name = "libc" version = "0.2.177" diff --git a/Cargo.toml b/Cargo.toml index eecf12d..8557167 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ rust-version = "1.90" [dependencies] lofty = { version = "0.22.4" } +imghdr = { version = "0.7.0" } [dev-dependencies] tempfile = { version = "3.23.0" } -- 2.43.0 From 580d73eeb88490ab8c1bbada63e82a0a7580435f Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:19:37 -0400 Subject: [PATCH 02/14] tsk-44: Added detection module --- src/detection/coverart.rs | 20 ++++++++++++++++++++ src/detection/mod.rs | 1 + src/lib.rs | 1 + 3 files changed, 22 insertions(+) create mode 100644 src/detection/coverart.rs create mode 100644 src/detection/mod.rs diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs new file mode 100644 index 0000000..cdb5a99 --- /dev/null +++ b/src/detection/coverart.rs @@ -0,0 +1,20 @@ +/// Gets the file type of a CoverArt given it's path +pub fn file_type(filepath: &str) -> Result { + match imghdr::from_file(filepath) { + Ok(Some(imghdr::Type::Jpeg)) => { + Ok(String::from("jpeg")) + } + Ok(Some(imghdr::Type::Png)) => { + Ok(String::from("png")) + } + Ok(None) => { + Err(std::io::Error::other("Image file not supported")) + } + Err(err) => { + Err(err) + } + _ => { + Err(std::io::Error::other("Image file not supported")) + } + } +} diff --git a/src/detection/mod.rs b/src/detection/mod.rs new file mode 100644 index 0000000..165fc86 --- /dev/null +++ b/src/detection/mod.rs @@ -0,0 +1 @@ +pub mod coverart; diff --git a/src/lib.rs b/src/lib.rs index bbf790d..16f20a3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,4 @@ +pub mod detection; pub mod meta; pub mod properties; pub mod types; -- 2.43.0 From 3055371248f5407b043a642914eb8200af80eeb1 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:24:08 -0400 Subject: [PATCH 03/14] tsk-44: cargo update --- Cargo.lock | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a52551b..80c2a7f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,9 +10,9 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" [[package]] name = "bitflags" -version = "2.9.4" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2261d10cca569e4643e526d8dc2e62e433cc8aba21ab764233731f8d369bf394" +checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" [[package]] name = "byteorder" @@ -22,9 +22,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cfg-if" -version = "1.0.3" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[package]] name = "crc32fast" @@ -69,14 +69,14 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", "libc", "r-efi", - "wasi", + "wasip2", ] [[package]] @@ -214,9 +214,9 @@ checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe" [[package]] name = "syn" -version = "2.0.106" +version = "2.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" +checksum = "2a26dbd934e5451d21ef060c018dae56fc073894c5a7896f882928a76e6d081b" dependencies = [ "proc-macro2", "quote", @@ -242,15 +242,6 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" -[[package]] -name = "wasi" -version = "0.14.7+wasi-0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "883478de20367e224c0090af9cf5f9fa85bed63a95c1abf3afc5c083ebc06e8c" -dependencies = [ - "wasip2", -] - [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" -- 2.43.0 From ab15fbcd1f1e7ea41b23fea503f4fa33d984c326 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:33:45 -0400 Subject: [PATCH 04/14] tsk-44: Adding test --- src/detection/coverart.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index cdb5a99..b978e67 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -18,3 +18,22 @@ pub fn file_type(filepath: &str) -> Result { } } } + +#[cfg(test)] +mod tests { + #[test] + fn test_coverart_file_type() { + let directory = String::from(crate::test_util::util::TESTFILEDIRECTORY); + let filename = String::from("Sample Tracks 3.png"); + let filepath = format!("{directory}/{filename}"); + + match super::file_type(&filepath) { + Ok(filetype) => { + assert_eq!(filetype, "png", "The file type of the CoverArt should have been png"); + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } + } +} -- 2.43.0 From 4df6855ca4d23b955433932181b1a49c33c23af9 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:54:21 -0400 Subject: [PATCH 05/14] tsk-44: Added rand crate --- Cargo.lock | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 60 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 80c2a7f..d3d03be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,6 +85,7 @@ version = "0.4.0" dependencies = [ "imghdr", "lofty", + "rand", "tempfile", ] @@ -169,6 +170,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" +[[package]] +name = "ppv-lite86" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" +dependencies = [ + "zerocopy", +] + [[package]] name = "proc-macro2" version = "1.0.101" @@ -193,6 +203,35 @@ version = "5.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom", +] + [[package]] name = "rustix" version = "1.1.2" @@ -271,3 +310,23 @@ name = "wit-bindgen" version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + +[[package]] +name = "zerocopy" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0894878a5fa3edfd6da3f88c4805f4c8558e2b996227a3d864f47fe11e38282c" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.8.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d2b8d9c68ad2b9e4340d7832716a4d21a22a1154777ad56ea55c51a9cf3831" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 8557167..157e4f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ rust-version = "1.90" [dependencies] lofty = { version = "0.22.4" } imghdr = { version = "0.7.0" } +rand = { version = "0.9.2" } [dev-dependencies] tempfile = { version = "3.23.0" } -- 2.43.0 From ff3171d9e7ba81ed6b33f32b0da20b56b861326b Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:54:36 -0400 Subject: [PATCH 06/14] tsk-44: Updating tests --- src/lib.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 16f20a3..97c6803 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,6 +7,8 @@ pub mod test_util { pub mod util { use std::io::{self, Write}; + use rand::Rng; + // Function to save a Vec to a file pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> { let file = std::path::Path::new(file_path); @@ -44,6 +46,25 @@ pub mod test_util { } } + pub fn generate_filename() -> Result { + let mut filename = String::from("track-"); + let length = 20; + let characters = "abcdef0123456789"; + let amount_of_characters = characters.len() - 1; + let mut rng = rand::rng(); + + for _ in 0..length { + let index = rng.random_range(0..=amount_of_characters); + let random_c = characters.chars().nth(index); + + if let Some(c) = random_c { + filename.push(c); + } + } + + Ok(format!("{filename}.flac")) + } + fn path_buf( directory: &String, filename: &String, -- 2.43.0 From bfb7df2d030ccc74254d619bfe4ad79d9d17af68 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:54:51 -0400 Subject: [PATCH 07/14] tsk-44: Test changes --- src/meta.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/meta.rs b/src/meta.rs index b3e4174..b2488cd 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -544,7 +544,7 @@ mod tests { 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 test_filename = util::generate_filename().unwrap(); let new_filepath = test_dir + "/" + &test_filename; match file_exists(&dir, &filename) { @@ -597,7 +597,7 @@ mod tests { 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 test_filename = util::generate_filename().unwrap(); let new_filepath = test_dir + "/" + &test_filename; match file_exists(&dir, &filename) { @@ -806,7 +806,7 @@ mod tests { 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 test_filename = util::generate_filename().unwrap(); let new_filepath = test_dir + "/" + &test_filename; match file_exists(&dir, &filename) { @@ -907,7 +907,7 @@ mod tests { 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 test_filename = util::generate_filename().unwrap(); let new_filepath = test_dir + "/" + &test_filename; match file_exists(&dir, &filename) { @@ -1021,7 +1021,7 @@ mod tests { 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 test_filename = util::generate_filename().unwrap(); let new_filepath = test_dir + "/" + &test_filename; match file_exists(&dir, &filename) { -- 2.43.0 From b96451bee56d040140a171ac95bd4e5d97b970b0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:55:07 -0400 Subject: [PATCH 08/14] tsk-44: Code formatting --- src/detection/coverart.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index b978e67..6bd5d01 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -1,21 +1,11 @@ /// Gets the file type of a CoverArt given it's path pub fn file_type(filepath: &str) -> Result { match imghdr::from_file(filepath) { - Ok(Some(imghdr::Type::Jpeg)) => { - Ok(String::from("jpeg")) - } - Ok(Some(imghdr::Type::Png)) => { - Ok(String::from("png")) - } - Ok(None) => { - Err(std::io::Error::other("Image file not supported")) - } - Err(err) => { - Err(err) - } - _ => { - Err(std::io::Error::other("Image file not supported")) - } + Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from("jpeg")), + Ok(Some(imghdr::Type::Png)) => Ok(String::from("png")), + Ok(None) => Err(std::io::Error::other("Image file not supported")), + Err(err) => Err(err), + _ => Err(std::io::Error::other("Image file not supported")), } } @@ -29,7 +19,10 @@ mod tests { match super::file_type(&filepath) { Ok(filetype) => { - assert_eq!(filetype, "png", "The file type of the CoverArt should have been png"); + assert_eq!( + filetype, "png", + "The file type of the CoverArt should have been png" + ); } Err(err) => { assert!(false, "Error: {err:?}"); -- 2.43.0 From 2019269ded62f0b97430ce9ad122217000e65705 Mon Sep 17 00:00:00 2001 From: phoenix Date: Mon, 20 Oct 2025 20:57:54 -0400 Subject: [PATCH 09/14] tsk-44: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d3d03be..77eebfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.4.0" +version = "0.4.1" dependencies = [ "imghdr", "lofty", diff --git a/Cargo.toml b/Cargo.toml index 157e4f0..25441fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.4.0" +version = "0.4.1" edition = "2024" rust-version = "1.90" -- 2.43.0 From f20b16e59f6a2dc74a118ef3727de17c7be77acf Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 12:08:55 -0400 Subject: [PATCH 10/14] tsk-44: Added function to get CoverArt type from data --- src/detection/coverart.rs | 30 ++++++++++++++++++++++++++++++ src/lib.rs | 19 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index 6bd5d01..3a7e91d 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -9,6 +9,16 @@ pub fn file_type(filepath: &str) -> Result { } } +/// Gets the file type of a CoverArt given it's data +pub fn file_type_from_data(data: &Vec) -> Result { + match imghdr::from_bytes(data) { + Some(imghdr::Type::Jpeg) => Ok(String::from("jpeg")), + Some(imghdr::Type::Png) => Ok(String::from("png")), + None => Err(std::io::Error::other("Image file not supported")), + _ => Err(std::io::Error::other("Image file not supported")), + } +} + #[cfg(test)] mod tests { #[test] @@ -29,4 +39,24 @@ mod tests { } } } + + #[test] + fn test_coverart_file_type_from_data() { + let directory = String::from(crate::test_util::util::TESTFILEDIRECTORY); + let filename = String::from("Sample Tracks 3.png"); + let filepath = format!("{directory}/{filename}"); + let data = crate::test_util::util::get_data_from_file(&filepath).unwrap(); + + match super::file_type_from_data(&data) { + Ok(filetype) => { + assert_eq!( + filetype, "png", + "The file type of the CoverArt should have been png" + ); + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } + } } diff --git a/src/lib.rs b/src/lib.rs index 97c6803..9440697 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ pub mod types; pub mod test_util { pub mod util { - use std::io::{self, Write}; + use std::io::{self, Read, Write}; use rand::Rng; @@ -39,6 +39,23 @@ pub mod test_util { std::fs::copy(src_path, dest_path) } + pub fn get_data_from_file(source_path: &str) -> Result, std::io::Error> { + match std::fs::File::open(source_path) { + Ok(mut file) => { + let mut data: Vec = Vec::new(); + match file.read_to_end(&mut data) { + Ok(_) => { + Ok(data) + } + Err(err) => Err(err) + } + } + Err(err) => { + Err(err) + } + } + } + pub fn file_exists(directory: &String, filename: &String) -> Result { match path_buf(directory, filename) { Ok(pf) => Ok(pf.exists()), -- 2.43.0 From 54001860cae81d9bbc02f24f31881f53221be21a Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 12:09:58 -0400 Subject: [PATCH 11/14] tsk-44: Function name change --- src/detection/coverart.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index 3a7e91d..e5d86de 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -1,5 +1,5 @@ /// Gets the file type of a CoverArt given it's path -pub fn file_type(filepath: &str) -> Result { +pub fn file_type_from_filepath(filepath: &str) -> Result { match imghdr::from_file(filepath) { Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from("jpeg")), Ok(Some(imghdr::Type::Png)) => Ok(String::from("png")), @@ -27,7 +27,7 @@ mod tests { let filename = String::from("Sample Tracks 3.png"); let filepath = format!("{directory}/{filename}"); - match super::file_type(&filepath) { + match super::file_type_from_filepath(&filepath) { Ok(filetype) => { assert_eq!( filetype, "png", -- 2.43.0 From 9243c75aac37f51e0c9c967a62f4ade8a8f8c4ce Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 12:10:08 -0400 Subject: [PATCH 12/14] tsk-44: Code formatting --- src/lib.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 9440697..dd4820b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -44,15 +44,11 @@ pub mod test_util { Ok(mut file) => { let mut data: Vec = Vec::new(); match file.read_to_end(&mut data) { - Ok(_) => { - Ok(data) - } - Err(err) => Err(err) + Ok(_) => Ok(data), + Err(err) => Err(err), } } - Err(err) => { - Err(err) - } + Err(err) => Err(err), } } -- 2.43.0 From 87a0f799ccd664dd45f37e13f2a10a05fb6eba11 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 12:10:22 -0400 Subject: [PATCH 13/14] tsk-44: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 77eebfe..896c873 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.4.1" +version = "0.4.2" dependencies = [ "imghdr", "lofty", diff --git a/Cargo.toml b/Cargo.toml index 25441fa..398a1e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.4.1" +version = "0.4.2" edition = "2024" rust-version = "1.90" -- 2.43.0 From 1547021c873e4f1bf3df9da6102cde93e03bc5db Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 12:16:05 -0400 Subject: [PATCH 14/14] tsk-44: Code formatting --- src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 46c8512..dd4820b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,6 @@ pub mod test_util { use rand::Rng; - // Function to save a Vec to a file pub fn save_bytes_to_file(bytes: &[u8], file_path: &String) -> io::Result<()> { let file = std::path::Path::new(file_path); -- 2.43.0