From 13bc89cd98b0662ec02312ee0037451696f96f57 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 19:48:41 -0400 Subject: [PATCH 01/15] tsk-45: Added infer crate --- Cargo.lock | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + 2 files changed, 119 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 896c873..b985de0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,12 +14,29 @@ version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3" +[[package]] +name = "bumpalo" +version = "3.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" + [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" +[[package]] +name = "cfb" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38f2da7a0a2c4ccf0065be06397cc26a81f4e528be095826eee9d4adbb8c60f" +dependencies = [ + "byteorder", + "fnv", + "uuid", +] + [[package]] name = "cfg-if" version = "1.0.4" @@ -67,6 +84,12 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "getrandom" version = "0.3.4" @@ -84,6 +107,7 @@ name = "icarus_meta" version = "0.4.2" dependencies = [ "imghdr", + "infer", "lofty", "rand", "tempfile", @@ -95,6 +119,25 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8b35f3ad95576ac81603375dfe47a0450b70a368aa34d2b6e5bb0a0d7f02428" +[[package]] +name = "infer" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a588916bfdfd92e71cacef98a63d9b1f0d74d6599980d11894290e7ddefffcf7" +dependencies = [ + "cfb", +] + +[[package]] +name = "js-sys" +version = "0.3.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + [[package]] name = "libc" version = "0.2.177" @@ -245,6 +288,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + [[package]] name = "simd-adler32" version = "0.3.7" @@ -281,6 +330,16 @@ version = "1.0.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" +[[package]] +name = "uuid" +version = "1.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f87b8aa10b915a06587d0dec516c282ff295b475d94abf425d62b57710070a2" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + [[package]] name = "wasip2" version = "1.0.1+wasi-0.2.4" @@ -290,6 +349,65 @@ dependencies = [ "wit-bindgen", ] +[[package]] +name = "wasm-bindgen" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" +dependencies = [ + "bumpalo", + "log", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" +dependencies = [ + "unicode-ident", +] + [[package]] name = "windows-link" version = "0.2.1" diff --git a/Cargo.toml b/Cargo.toml index 398a1e5..4734751 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" } +infer = { version = "0.19.0" } rand = { version = "0.9.2" } [dev-dependencies] -- 2.43.0 From fa5203013c369ae10696c26552d4ef63bf3e558b Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 20:02:19 -0400 Subject: [PATCH 02/15] tsk-45: Adding functionality for itdentifying Song --- src/detection/song.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/detection/song.rs diff --git a/src/detection/song.rs b/src/detection/song.rs new file mode 100644 index 0000000..03563a6 --- /dev/null +++ b/src/detection/song.rs @@ -0,0 +1,15 @@ + + +pub fn file_type_from_filepath(filepath: &str) -> Result { + match infer::get_from_path(filepath) { + Ok(Some(kind)) => { + Ok(String::new()) + } + Ok(None) => { + Err(std::io::Error::other("File type not determined")) + } + Err(err) => { + Err(err) + } + } +} -- 2.43.0 From fef43b9799ef324787fe52766b1fa3981b949439 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 20:08:41 -0400 Subject: [PATCH 03/15] tsk-45: Some changes --- src/detection/coverart.rs | 14 ++++++++++---- src/detection/mod.rs | 8 ++++++++ src/detection/song.rs | 4 ++++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index e5d86de..fc5cc39 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -1,8 +1,8 @@ /// Gets the file type of a CoverArt given it's path 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")), + Ok(Some(imghdr::Type::Jpeg)) => Ok(String::from(constants::JPEG_TYPE)), + Ok(Some(imghdr::Type::Png)) => Ok(String::from(constants::PNG_TYPE)), Ok(None) => Err(std::io::Error::other("Image file not supported")), Err(err) => Err(err), _ => Err(std::io::Error::other("Image file not supported")), @@ -12,13 +12,19 @@ pub fn file_type_from_filepath(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")), + Some(imghdr::Type::Jpeg) => Ok(String::from(constants::JPEG_TYPE)), + Some(imghdr::Type::Png) => Ok(String::from(constants::PNG_TYPE)), None => Err(std::io::Error::other("Image file not supported")), _ => Err(std::io::Error::other("Image file not supported")), } } +pub mod constants { + pub const PNG_TYPE: &str = "png"; + pub const JPEG_TYPE: &str = "jpeg"; + pub const JPG_TYPE: &str = "jpg"; +} + #[cfg(test)] mod tests { #[test] diff --git a/src/detection/mod.rs b/src/detection/mod.rs index 165fc86..b1ecbb7 100644 --- a/src/detection/mod.rs +++ b/src/detection/mod.rs @@ -1 +1,9 @@ pub mod coverart; +pub mod song; + +pub struct FileType { + pub mime: String +} + +pub enum FileTypeDef { +} diff --git a/src/detection/song.rs b/src/detection/song.rs index 03563a6..ed0099e 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -13,3 +13,7 @@ pub fn file_type_from_filepath(filepath: &str) -> Result } } } + +pub mod constants { + pub const FLAC_TYPE: &str = "flac"; +} -- 2.43.0 From 250a009fad91a4f60fdd05848694da5230ac19ca Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 20:21:07 -0400 Subject: [PATCH 04/15] tsk-45: More changes --- src/detection/coverart.rs | 6 ++++-- src/detection/mod.rs | 6 ++---- src/detection/song.rs | 14 ++++++++++---- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index fc5cc39..e3d757b 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -19,12 +19,14 @@ pub fn file_type_from_data(data: &Vec) -> Result { } } + pub mod constants { pub const PNG_TYPE: &str = "png"; pub const JPEG_TYPE: &str = "jpeg"; pub const JPG_TYPE: &str = "jpg"; } + #[cfg(test)] mod tests { #[test] @@ -36,7 +38,7 @@ mod tests { match super::file_type_from_filepath(&filepath) { Ok(filetype) => { assert_eq!( - filetype, "png", + filetype, super::constants::PNG_TYPE, "The file type of the CoverArt should have been png" ); } @@ -56,7 +58,7 @@ mod tests { match super::file_type_from_data(&data) { Ok(filetype) => { assert_eq!( - filetype, "png", + filetype, super::constants::PNG_TYPE, "The file type of the CoverArt should have been png" ); } diff --git a/src/detection/mod.rs b/src/detection/mod.rs index b1ecbb7..df4b487 100644 --- a/src/detection/mod.rs +++ b/src/detection/mod.rs @@ -2,8 +2,6 @@ pub mod coverart; pub mod song; pub struct FileType { - pub mime: String -} - -pub enum FileTypeDef { + pub mime: String, + pub file_type: String, } diff --git a/src/detection/song.rs b/src/detection/song.rs index ed0099e..a6ca378 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -1,9 +1,15 @@ - - -pub fn file_type_from_filepath(filepath: &str) -> Result { +pub fn file_type_from_filepath(filepath: &str) -> Result { match infer::get_from_path(filepath) { Ok(Some(kind)) => { - Ok(String::new()) + let mime = kind.mime_type(); + if mime == "audio/x-flac" { + Ok(crate::detection::FileType { + mime: String::from(mime), + file_type: String::from(constants::FLAC_TYPE) + }) + } else { + Err(std::io::Error::other("Unsupported file type")) + } } Ok(None) => { Err(std::io::Error::other("File type not determined")) -- 2.43.0 From 25c85212cad649c6c2473d20fb0fb9a4cbdfe6d0 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 20:28:50 -0400 Subject: [PATCH 05/15] tsk-45: Changed types of functions --- src/detection/coverart.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index e3d757b..86e2176 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -1,8 +1,9 @@ /// Gets the file type of a CoverArt given it's path -pub fn file_type_from_filepath(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(constants::JPEG_TYPE)), - Ok(Some(imghdr::Type::Png)) => Ok(String::from(constants::PNG_TYPE)), + Ok(Some(imghdr::Type::Jpeg)) => Ok(crate::detection::FileType {mime: String::from("image/jpeg"), file_type: String::from(constants::JPEG_TYPE)}), + Ok(Some(imghdr::Type::Png)) => Ok(crate::detection::FileType {mime: String::from("image/png"), + file_type: String::from(constants::PNG_TYPE)}), Ok(None) => Err(std::io::Error::other("Image file not supported")), Err(err) => Err(err), _ => Err(std::io::Error::other("Image file not supported")), @@ -10,10 +11,11 @@ pub fn file_type_from_filepath(filepath: &str) -> Result } /// Gets the file type of a CoverArt given it's data -pub fn file_type_from_data(data: &Vec) -> Result { +pub fn file_type_from_data(data: &Vec) -> Result { match imghdr::from_bytes(data) { - Some(imghdr::Type::Jpeg) => Ok(String::from(constants::JPEG_TYPE)), - Some(imghdr::Type::Png) => Ok(String::from(constants::PNG_TYPE)), + Some(imghdr::Type::Jpeg) => Ok(crate::detection::FileType {mime: String::from("image/jpeg"), file_type: String::from(constants::JPEG_TYPE)}), + Some(imghdr::Type::Png) => Ok(crate::detection::FileType {mime: String::from("image/png"), + file_type: String::from(constants::PNG_TYPE)}), None => Err(std::io::Error::other("Image file not supported")), _ => Err(std::io::Error::other("Image file not supported")), } @@ -38,7 +40,7 @@ mod tests { match super::file_type_from_filepath(&filepath) { Ok(filetype) => { assert_eq!( - filetype, super::constants::PNG_TYPE, + filetype.file_type, super::constants::PNG_TYPE, "The file type of the CoverArt should have been png" ); } @@ -58,7 +60,7 @@ mod tests { match super::file_type_from_data(&data) { Ok(filetype) => { assert_eq!( - filetype, super::constants::PNG_TYPE, + filetype.file_type, super::constants::PNG_TYPE, "The file type of the CoverArt should have been png" ); } -- 2.43.0 From 02631fc14cf71aed0dd072e514b687a57bafc488 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 20:29:13 -0400 Subject: [PATCH 06/15] tsk-45: Code formatting --- src/detection/coverart.rs | 34 +++++++++++++++++++++++----------- src/detection/song.rs | 14 ++++++-------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index 86e2176..c25f548 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -1,9 +1,16 @@ /// Gets the file type of a CoverArt given it's path -pub fn file_type_from_filepath(filepath: &str) -> Result { +pub fn file_type_from_filepath( + filepath: &str, +) -> Result { match imghdr::from_file(filepath) { - Ok(Some(imghdr::Type::Jpeg)) => Ok(crate::detection::FileType {mime: String::from("image/jpeg"), file_type: String::from(constants::JPEG_TYPE)}), - Ok(Some(imghdr::Type::Png)) => Ok(crate::detection::FileType {mime: String::from("image/png"), - file_type: String::from(constants::PNG_TYPE)}), + Ok(Some(imghdr::Type::Jpeg)) => Ok(crate::detection::FileType { + mime: String::from("image/jpeg"), + file_type: String::from(constants::JPEG_TYPE), + }), + Ok(Some(imghdr::Type::Png)) => Ok(crate::detection::FileType { + mime: String::from("image/png"), + file_type: String::from(constants::PNG_TYPE), + }), Ok(None) => Err(std::io::Error::other("Image file not supported")), Err(err) => Err(err), _ => Err(std::io::Error::other("Image file not supported")), @@ -13,22 +20,25 @@ pub fn file_type_from_filepath(filepath: &str) -> Result) -> Result { match imghdr::from_bytes(data) { - Some(imghdr::Type::Jpeg) => Ok(crate::detection::FileType {mime: String::from("image/jpeg"), file_type: String::from(constants::JPEG_TYPE)}), - Some(imghdr::Type::Png) => Ok(crate::detection::FileType {mime: String::from("image/png"), - file_type: String::from(constants::PNG_TYPE)}), + Some(imghdr::Type::Jpeg) => Ok(crate::detection::FileType { + mime: String::from("image/jpeg"), + file_type: String::from(constants::JPEG_TYPE), + }), + Some(imghdr::Type::Png) => Ok(crate::detection::FileType { + mime: String::from("image/png"), + file_type: String::from(constants::PNG_TYPE), + }), None => Err(std::io::Error::other("Image file not supported")), _ => Err(std::io::Error::other("Image file not supported")), } } - pub mod constants { pub const PNG_TYPE: &str = "png"; pub const JPEG_TYPE: &str = "jpeg"; pub const JPG_TYPE: &str = "jpg"; } - #[cfg(test)] mod tests { #[test] @@ -40,7 +50,8 @@ mod tests { match super::file_type_from_filepath(&filepath) { Ok(filetype) => { assert_eq!( - filetype.file_type, super::constants::PNG_TYPE, + filetype.file_type, + super::constants::PNG_TYPE, "The file type of the CoverArt should have been png" ); } @@ -60,7 +71,8 @@ mod tests { match super::file_type_from_data(&data) { Ok(filetype) => { assert_eq!( - filetype.file_type, super::constants::PNG_TYPE, + filetype.file_type, + super::constants::PNG_TYPE, "The file type of the CoverArt should have been png" ); } diff --git a/src/detection/song.rs b/src/detection/song.rs index a6ca378..38b2097 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -1,22 +1,20 @@ -pub fn file_type_from_filepath(filepath: &str) -> Result { +pub fn file_type_from_filepath( + filepath: &str, +) -> Result { match infer::get_from_path(filepath) { Ok(Some(kind)) => { let mime = kind.mime_type(); if mime == "audio/x-flac" { Ok(crate::detection::FileType { mime: String::from(mime), - file_type: String::from(constants::FLAC_TYPE) + file_type: String::from(constants::FLAC_TYPE), }) } else { Err(std::io::Error::other("Unsupported file type")) } } - Ok(None) => { - Err(std::io::Error::other("File type not determined")) - } - Err(err) => { - Err(err) - } + Ok(None) => Err(std::io::Error::other("File type not determined")), + Err(err) => Err(err), } } -- 2.43.0 From a7ad40478c29010e9577b2c8cd501ea9a319a6a5 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 20:37:36 -0400 Subject: [PATCH 07/15] tsk-45: Version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b985de0..a3669f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -104,7 +104,7 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.4.2" +version = "0.4.3" dependencies = [ "imghdr", "infer", diff --git a/Cargo.toml b/Cargo.toml index 4734751..8090b6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.4.2" +version = "0.4.3" edition = "2024" rust-version = "1.90" -- 2.43.0 From 233bbdeaa1ff0c6df32646c873d7a3e3217369a9 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 20:53:09 -0400 Subject: [PATCH 08/15] tsk-45: Added test --- src/detection/song.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/detection/song.rs b/src/detection/song.rs index 38b2097..97fd4df 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -21,3 +21,22 @@ pub fn file_type_from_filepath( pub mod constants { pub const FLAC_TYPE: &str = "flac"; } + +#[cfg(test)] +mod tests { + #[test] + fn test_song_file_type() { + let directory = String::from(crate::test_util::util::TESTFILEDIRECTORY); + let filename = String::from("track01.flac"); + let filepath = format!("{directory}/{filename}"); + + match super::file_type_from_filepath(&filepath) { + Ok(filetype) => { + assert_eq!(filetype.file_type, crate::detection::song::constants::FLAC_TYPE, "Types do not match") + } + Err(err) => { + assert!(false, "Error: {err:?}") + } + } + } +} -- 2.43.0 From 82fe3ae8e835bc5a0f37f853b7e2615edb38b235 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 21:00:06 -0400 Subject: [PATCH 09/15] tsk-45: Added another function --- src/detection/song.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/detection/song.rs b/src/detection/song.rs index 97fd4df..53f791e 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -1,10 +1,11 @@ +/// Gets the file type of a Song from it's path pub fn file_type_from_filepath( filepath: &str, ) -> Result { match infer::get_from_path(filepath) { Ok(Some(kind)) => { let mime = kind.mime_type(); - if mime == "audio/x-flac" { + if mime == constants::mime::FLAC { Ok(crate::detection::FileType { mime: String::from(mime), file_type: String::from(constants::FLAC_TYPE), @@ -18,8 +19,32 @@ pub fn file_type_from_filepath( } } +/// Gets the file type of a Song given it's data +pub fn file_type_from_data(data: &Vec) -> Result { + match infer::get(data) { + Some(kind) => { + let mime = kind.mime_type(); + if mime == constants::mime::FLAC { + Ok(crate::detection::FileType { + mime: String::from(mime), + file_type: String::from(constants::FLAC_TYPE) + }) + } else { + Err(std::io::Error::other("Unsupported file type")) + } + } + None => { + Err(std::io::Error::other("File type not determined")) + } + } +} + pub mod constants { pub const FLAC_TYPE: &str = "flac"; + + pub mod mime { + pub const FLAC: &str = "audio/x-flac"; + } } #[cfg(test)] -- 2.43.0 From 0c3e4bf82a7431f1ef19e5a4b9edec21d8bd10a8 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 21:02:11 -0400 Subject: [PATCH 10/15] tsk-45: Added test --- src/detection/song.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/detection/song.rs b/src/detection/song.rs index 53f791e..e031aea 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -64,4 +64,22 @@ mod tests { } } } + + #[test] + fn test_song_file_type_from_data() { + let directory = String::from(crate::test_util::util::TESTFILEDIRECTORY); + let filename = String::from("track01.flac"); + 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.file_type, crate::detection::song::constants::FLAC_TYPE, "Types do not match") + } + Err(err) => { + assert!(false, "Error: {err:?}") + } + } + } + } -- 2.43.0 From 290cd4eaa878c7898ea0bda28434219e5906a066 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 21:08:14 -0400 Subject: [PATCH 11/15] tsk-45: Making use of constants --- src/detection/coverart.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/detection/coverart.rs b/src/detection/coverart.rs index c25f548..da51d71 100644 --- a/src/detection/coverart.rs +++ b/src/detection/coverart.rs @@ -4,11 +4,11 @@ pub fn file_type_from_filepath( ) -> Result { match imghdr::from_file(filepath) { Ok(Some(imghdr::Type::Jpeg)) => Ok(crate::detection::FileType { - mime: String::from("image/jpeg"), + mime: String::from(constants::mime::JPEG), file_type: String::from(constants::JPEG_TYPE), }), Ok(Some(imghdr::Type::Png)) => Ok(crate::detection::FileType { - mime: String::from("image/png"), + mime: String::from(constants::mime::PNG), file_type: String::from(constants::PNG_TYPE), }), Ok(None) => Err(std::io::Error::other("Image file not supported")), @@ -21,11 +21,11 @@ pub fn file_type_from_filepath( pub fn file_type_from_data(data: &Vec) -> Result { match imghdr::from_bytes(data) { Some(imghdr::Type::Jpeg) => Ok(crate::detection::FileType { - mime: String::from("image/jpeg"), + mime: String::from(constants::mime::JPEG), file_type: String::from(constants::JPEG_TYPE), }), Some(imghdr::Type::Png) => Ok(crate::detection::FileType { - mime: String::from("image/png"), + mime: String::from(constants::mime::PNG), file_type: String::from(constants::PNG_TYPE), }), None => Err(std::io::Error::other("Image file not supported")), @@ -37,6 +37,11 @@ pub mod constants { pub const PNG_TYPE: &str = "png"; pub const JPEG_TYPE: &str = "jpeg"; pub const JPG_TYPE: &str = "jpg"; + + pub mod mime { + pub const JPEG: &str = "image/jpeg"; + pub const PNG: &str = "image/png"; + } } #[cfg(test)] -- 2.43.0 From 80e28643123cc3de9cc879ecdce77faa32de36a3 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 21:08:57 -0400 Subject: [PATCH 12/15] tsk-45: Code formatting --- src/detection/song.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/detection/song.rs b/src/detection/song.rs index e031aea..7382495 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -27,15 +27,13 @@ pub fn file_type_from_data(data: &Vec) -> Result { - Err(std::io::Error::other("File type not determined")) - } + None => Err(std::io::Error::other("File type not determined")), } } @@ -57,7 +55,11 @@ mod tests { match super::file_type_from_filepath(&filepath) { Ok(filetype) => { - assert_eq!(filetype.file_type, crate::detection::song::constants::FLAC_TYPE, "Types do not match") + assert_eq!( + filetype.file_type, + crate::detection::song::constants::FLAC_TYPE, + "Types do not match" + ) } Err(err) => { assert!(false, "Error: {err:?}") @@ -74,12 +76,15 @@ mod tests { match super::file_type_from_data(&data) { Ok(filetype) => { - assert_eq!(filetype.file_type, crate::detection::song::constants::FLAC_TYPE, "Types do not match") + assert_eq!( + filetype.file_type, + crate::detection::song::constants::FLAC_TYPE, + "Types do not match" + ) } Err(err) => { assert!(false, "Error: {err:?}") } } } - } -- 2.43.0 From 561d740120d9d2e0224bff0c8a4d7d40c6230413 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 21:28:41 -0400 Subject: [PATCH 13/15] tsk-45: Workflow change --- .gitea/workflows/tag_release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitea/workflows/tag_release.yml b/.gitea/workflows/tag_release.yml index ef2df31..3e39896 100644 --- a/.gitea/workflows/tag_release.yml +++ b/.gitea/workflows/tag_release.yml @@ -4,6 +4,9 @@ on: push: branches: - main + pull_request: + branches: + - main jobs: release: -- 2.43.0 From 8acf220fc4a646090cfb54eff78aaa2f172bf882 Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 21:43:55 -0400 Subject: [PATCH 14/15] tsk-45: Added macros of FileType --- src/detection/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/detection/mod.rs b/src/detection/mod.rs index df4b487..ad6601e 100644 --- a/src/detection/mod.rs +++ b/src/detection/mod.rs @@ -1,6 +1,7 @@ pub mod coverart; pub mod song; +#[derive(Debug, Default)] pub struct FileType { pub mime: String, pub file_type: String, -- 2.43.0 From 60d30bff0120faf065e43b5a3d43e676265c768b Mon Sep 17 00:00:00 2001 From: phoenix Date: Tue, 21 Oct 2025 21:46:49 -0400 Subject: [PATCH 15/15] tsk-45: Warning fix --- src/detection/song.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/detection/song.rs b/src/detection/song.rs index 7382495..1094055 100644 --- a/src/detection/song.rs +++ b/src/detection/song.rs @@ -20,7 +20,7 @@ pub fn file_type_from_filepath( } /// Gets the file type of a Song given it's data -pub fn file_type_from_data(data: &Vec) -> Result { +pub fn file_type_from_data(data: &[u8]) -> Result { match infer::get(data) { Some(kind) => { let mime = kind.mime_type(); -- 2.43.0