From 973d163ca54a53b5284a7172843b7a84cea2a3e4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Wed, 25 Jun 2025 21:44:04 +0000 Subject: [PATCH 1/6] coverart fix (#34) Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/34 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/meta.rs | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7fbf564..d6282c8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.2.0" +version = "0.2.1" dependencies = [ "lofty", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 239b90a..5640c4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.2.0" +version = "0.2.1" edition = "2024" rust-version = "1.86" diff --git a/src/meta.rs b/src/meta.rs index f70643e..3deb1a3 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -21,7 +21,17 @@ pub mod coverart { match lofty::picture::PictureInformation::from_picture(&pic) { Ok(info) => { flac_file.set_picture(0, pic.clone(), info); - Ok(pic.into_data()) + + match flac_file.save_to_path( + song_filepath, + lofty::config::WriteOptions::default(), + ) { + Ok(_) => Ok(pic.into_data()), + 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, From 565d361b64f23c2a0100b33fceeebacfad3331c4 Mon Sep 17 00:00:00 2001 From: phoenix Date: Thu, 26 Jun 2025 22:23:25 +0000 Subject: [PATCH 2/6] Added function to get all Types (#36) Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/36 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/types.rs | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d6282c8..cc173ba 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.2.1" +version = "0.2.2" dependencies = [ "lofty", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 5640c4a..9b4d265 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.2.1" +version = "0.2.2" edition = "2024" rust-version = "1.86" diff --git a/src/types.rs b/src/types.rs index b7efc00..05a30b0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -32,6 +32,21 @@ impl MetadataType { } } +pub fn all_metadata_types() -> Vec { + vec![ + Type::Album, + Type::Artist, + Type::AlbumArtist, + Type::Date, + Type::Disc, + Type::Genre, + Type::Title, + Type::Track, + Type::TrackCount, + Type::DiscCount, + ] +} + pub mod access { pub fn get_type(t: super::Type) -> Result { match t { From f51b3a0c4e113b20b1b2e0b0d89c2d44900cbc89 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 29 Jun 2025 19:24:51 +0000 Subject: [PATCH 3/6] Rust std change (#37) Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/37 Co-authored-by: phoenix Co-committed-by: phoenix --- .gitea/workflows/tag_release.yml | 2 +- .gitea/workflows/workflow.yml | 12 ++++++------ Cargo.toml | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/tag_release.yml b/.gitea/workflows/tag_release.yml index bcaedf3..8e05c1a 100644 --- a/.gitea/workflows/tag_release.yml +++ b/.gitea/workflows/tag_release.yml @@ -17,7 +17,7 @@ jobs: - name: Install Rust uses: actions-rs/toolchain@v1 with: - toolchain: 1.86.0 + toolchain: 1.88.0 components: cargo - name: Extract Version from Cargo.toml diff --git a/.gitea/workflows/workflow.yml b/.gitea/workflows/workflow.yml index 28ad362..fa5260a 100644 --- a/.gitea/workflows/workflow.yml +++ b/.gitea/workflows/workflow.yml @@ -18,7 +18,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.86.0 + toolchain: 1.88.0 - run: | mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key @@ -36,7 +36,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.86.0 + toolchain: 1.88.0 - run: | mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key @@ -54,7 +54,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.86.0 + toolchain: 1.88.0 - run: rustup component add rustfmt - run: | mkdir -p ~/.ssh @@ -73,7 +73,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.86.0 + toolchain: 1.88.0 - run: rustup component add clippy - run: | mkdir -p ~/.ssh @@ -92,7 +92,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: 1.86.0 + toolchain: 1.88.0 - run: | mkdir -p ~/.ssh echo "${{ secrets.MYREPO_TOKEN }}" > ~/.ssh/gitlab_deploy_key @@ -100,4 +100,4 @@ jobs: ssh-keyscan ${{ vars.MYHOST }} >> ~/.ssh/known_hosts eval $(ssh-agent -s) ssh-add -v ~/.ssh/gitlab_deploy_key - cargo build --release \ No newline at end of file + cargo build --release diff --git a/Cargo.toml b/Cargo.toml index 9b4d265..5c56dc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "icarus_meta" version = "0.2.2" edition = "2024" -rust-version = "1.86" +rust-version = "1.88" [dependencies] lofty = { version = "0.22.3" } From 5288b5de3061fe303bb5318dc484b458d5eb4034 Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 29 Jun 2025 19:30:29 +0000 Subject: [PATCH 4/6] Updated lofty and tempfile (#38) Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/38 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cc173ba..df265a7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -211,9 +211,9 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.19.1" +version = "3.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7437ac7763b9b123ccf33c338a5cc1bac6f69b45a136c19bdd8a65e3916435bf" +checksum = "e8a64e3985349f2441a1a9ef0b853f869006c3855f2cda6862a94d26ebb9d6a1" dependencies = [ "fastrand", "getrandom", diff --git a/Cargo.toml b/Cargo.toml index 5c56dc4..e6b87a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ edition = "2024" rust-version = "1.88" [dependencies] -lofty = { version = "0.22.3" } +lofty = { version = "0.22.4" } [dev-dependencies] -tempfile = { version = "3.19.1" } +tempfile = { version = "3.20.0" } From f4b71de9692029a706b1ce82c39f6715c560158e Mon Sep 17 00:00:00 2001 From: phoenix Date: Sun, 29 Jun 2025 19:39:02 +0000 Subject: [PATCH 5/6] Version bump (#39) Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/39 Co-authored-by: phoenix Co-committed-by: phoenix --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index df265a7..0670b17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -81,7 +81,7 @@ dependencies = [ [[package]] name = "icarus_meta" -version = "0.2.2" +version = "0.3.0" dependencies = [ "lofty", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index e6b87a3..dad9897 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "icarus_meta" -version = "0.2.2" +version = "0.3.0" edition = "2024" rust-version = "1.88" From 5baecbaa9af8af626bb38de0ef3002463909d01c Mon Sep 17 00:00:00 2001 From: phoenix Date: Fri, 4 Jul 2025 21:45:48 +0000 Subject: [PATCH 6/6] Duration (#40) Reviewed-on: https://git.kundeng.us/phoenix/icarus_meta/pulls/40 Co-authored-by: phoenix Co-committed-by: phoenix --- src/lib.rs | 64 ++++++++++++++++++++++++++++++++++ src/meta.rs | 88 +++++------------------------------------------ src/properties.rs | 51 +++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 79 deletions(-) create mode 100644 src/properties.rs diff --git a/src/lib.rs b/src/lib.rs index 1009908..bbf790d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,66 @@ pub mod meta; +pub mod properties; pub mod types; + +pub mod test_util { + pub mod util { + use std::io::{self, Write}; + + // 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); + let mut file = std::fs::File::create(file)?; + + match file.write_all(bytes) { + Ok(_res) => Ok(()), + Err(err) => Err(err), + } + } + pub fn get_full_path( + directory: &String, + filename: &String, + ) -> Result { + match path_buf(directory, filename) { + Ok(pf) => Ok(pf.display().to_string()), + Err(err) => Err(err), + } + } + + pub fn copy_file( + source_path: &String, + destination_path: &String, + ) -> Result { + let src_path = std::path::Path::new(source_path); + let dest_path = std::path::Path::new(destination_path); + + std::fs::copy(src_path, dest_path) + } + + pub fn file_exists(directory: &String, filename: &String) -> Result { + match path_buf(directory, filename) { + Ok(pf) => Ok(pf.exists()), + Err(err) => Err(err), + } + } + + fn path_buf( + directory: &String, + filename: &String, + ) -> Result { + let dir_path = std::path::Path::new(&directory); + Ok(dir_path.join(filename)) + } + + pub const TESTFILEDIRECTORY: &str = "tests/sample_tracks3"; + + pub fn get_filename(track: i32) -> String { + const FLAC_EXTENSION: &str = ".flac"; + + if track < 10 { + format!("track0{track}{FLAC_EXTENSION}") + } else { + format!("track{track}{FLAC_EXTENSION}") + } + } + } +} diff --git a/src/meta.rs b/src/meta.rs index 3deb1a3..b3e4174 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -275,83 +275,10 @@ pub mod metadata { #[cfg(test)] mod tests { - use util::{file_exists, get_full_path}; - - use super::*; - - mod util { - - use std::io::{self, Write}; - - // 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); - let mut file = std::fs::File::create(file)?; - - match file.write_all(bytes) { - Ok(_res) => Ok(()), - Err(err) => Err(err), - } - } - pub fn get_full_path( - directory: &String, - filename: &String, - ) -> Result { - match path_buf(directory, filename) { - Ok(pf) => Ok(pf.display().to_string()), - Err(err) => Err(err), - } - } - - pub fn copy_file( - source_path: &String, - destination_path: &String, - ) -> Result { - let src_path = std::path::Path::new(source_path); - let dest_path = std::path::Path::new(destination_path); - - match std::fs::copy(src_path, dest_path) { - Ok(bytes) => Ok(bytes), - Err(err) => Err(err), - } - } - - pub fn file_exists(directory: &String, filename: &String) -> Result { - match path_buf(directory, filename) { - Ok(pf) => Ok(pf.exists()), - Err(err) => Err(err), - } - } - - fn path_buf( - directory: &String, - filename: &String, - ) -> Result { - let dir_path = std::path::Path::new(&directory); - Ok(dir_path.join(filename)) - } - - pub const TESTFILEDIRECTORY: &str = "tests/sample_tracks3"; - - pub fn get_filename(track: i32) -> String { - let mut filename = String::from("track"); - - if track < 10 { - filename += "0"; - filename += &track.to_string(); - } else { - filename += &track.to_string(); - } - - filename += ".flac"; - - filename - } - } - mod get { - use super::metadata::get_meta; - use super::*; + use super::super::metadata::get_meta; + use crate::test_util::util; + use crate::test_util::util::{file_exists, get_full_path}; use crate::types; #[test] @@ -605,8 +532,9 @@ mod tests { } mod set { - use super::metadata::{get_meta, set_meta}; - use super::*; + use super::super::metadata::{get_meta, set_meta}; + use crate::test_util::util; + use crate::test_util::util::{file_exists, get_full_path}; use crate::types; #[test] @@ -1142,7 +1070,9 @@ mod tests { mod pictures { - use super::*; + use super::super::*; + use crate::test_util::util; + use crate::test_util::util::{file_exists, get_full_path}; #[test] fn test_get_picture() { diff --git a/src/properties.rs b/src/properties.rs new file mode 100644 index 0000000..3e28031 --- /dev/null +++ b/src/properties.rs @@ -0,0 +1,51 @@ +use lofty::file::AudioFile; + +pub fn get_duration(song_path: &String) -> Result { + match std::fs::File::open(song_path) { + Ok(mut content) => { + match lofty::flac::FlacFile::read_from(&mut content, lofty::config::ParseOptions::new()) + { + Ok(flac_file) => { + let properties = flac_file.properties(); + Ok(properties.duration()) + } + Err(err) => Err(std::io::Error::other(err.to_string())), + } + } + Err(err) => Err(err), + } +} + +#[cfg(test)] +mod tests { + use crate::test_util; + + #[test] + fn test_get_duration() { + let filename = test_util::util::get_filename(1); + let dir = String::from(test_util::util::TESTFILEDIRECTORY); + + match test_util::util::file_exists(&dir, &filename) { + Ok(_) => { + let filepath = test_util::util::get_full_path(&dir, &filename).unwrap(); + match super::get_duration(&filepath) { + Ok(duration) => { + let song_duration: u64 = 41; + let fetched_song_duration = duration.as_secs(); + + assert_eq!( + song_duration, fetched_song_duration, + "Durations should match, but they don't {song_duration} {fetched_song_duration} ({duration:?})" + ); + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } + } + Err(err) => { + assert!(false, "Error: {err:?}"); + } + } + } +}