Compare commits

...

8 Commits

Author SHA1 Message Date
2a798dea9c Next release (#14)
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 32s
Rust Build / Test Suite (push) Successful in 39s
Rust Build / Rustfmt (push) Successful in 27s
Rust Build / Clippy (push) Successful in 39s
Rust Build / build (push) Successful in 43s
Reviewed-on: #14
2025-04-19 21:27:21 +00:00
000639b0f8 added_types (#26)
All checks were successful
Release Tagging / release (push) Successful in 32s
Rust Build / Check (push) Successful in 44s
Rust Build / Test Suite (push) Successful in 59s
Rust Build / Rustfmt (push) Successful in 32s
Rust Build / Clippy (push) Successful in 35s
Rust Build / build (push) Successful in 43s
Rust Build / Check (pull_request) Successful in 23s
Rust Build / Test Suite (pull_request) Successful in 25s
Rust Build / Rustfmt (pull_request) Successful in 21s
Rust Build / Clippy (pull_request) Successful in 26s
Rust Build / build (pull_request) Successful in 29s
Reviewed-on: #26
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-04-19 21:19:01 +00:00
2932cdbe1c Added counts for disc and track (#25)
All checks were successful
Release Tagging / release (push) Successful in 39s
Rust Build / Check (push) Successful in 39s
Rust Build / Check (pull_request) Successful in 30s
Rust Build / Test Suite (push) Successful in 36s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 36s
Rust Build / build (push) Successful in 41s
Rust Build / Test Suite (pull_request) Successful in 41s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 43s
Reviewed-on: #25
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-04-19 01:37:16 +00:00
f534687292 refactor (#24)
All checks were successful
Rust Build / Check (push) Successful in 37s
Rust Build / Check (pull_request) Successful in 31s
Release Tagging / release (push) Successful in 41s
Rust Build / Test Suite (push) Successful in 41s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 38s
Rust Build / build (push) Successful in 42s
Rust Build / Test Suite (pull_request) Successful in 37s
Rust Build / Rustfmt (pull_request) Successful in 33s
Rust Build / Clippy (pull_request) Successful in 33s
Rust Build / build (pull_request) Successful in 43s
Reviewed-on: #24
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-04-19 01:31:57 +00:00
c80bc7d7e1 remove_picture (#23)
All checks were successful
Release Tagging / release (push) Successful in 36s
Rust Build / Check (push) Successful in 42s
Rust Build / Check (pull_request) Successful in 39s
Rust Build / Test Suite (push) Successful in 47s
Rust Build / Rustfmt (push) Successful in 31s
Rust Build / Clippy (push) Successful in 40s
Rust Build / build (push) Successful in 46s
Rust Build / Test Suite (pull_request) Successful in 40s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 46s
Reviewed-on: #23
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-04-19 01:07:49 +00:00
805dfb269b Contains pictures (#22)
All checks were successful
Release Tagging / release (push) Successful in 38s
Rust Build / Check (push) Successful in 33s
Rust Build / Check (pull_request) Successful in 35s
Rust Build / Test Suite (push) Successful in 43s
Rust Build / Rustfmt (push) Successful in 35s
Rust Build / Clippy (push) Successful in 38s
Rust Build / build (push) Successful in 43s
Rust Build / Test Suite (pull_request) Successful in 33s
Rust Build / Rustfmt (pull_request) Successful in 31s
Rust Build / Clippy (pull_request) Successful in 34s
Rust Build / build (pull_request) Successful in 40s
Reviewed-on: #22
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-04-19 00:52:14 +00:00
5e57b9146c Release (#8)
All checks were successful
Release Tagging / release (push) Successful in 35s
Rust Build / Check (push) Successful in 38s
Rust Build / Test Suite (push) Successful in 34s
Rust Build / Rustfmt (push) Successful in 34s
Rust Build / Clippy (push) Successful in 37s
Rust Build / build (push) Successful in 41s
Reviewed-on: #8
2025-04-12 19:32:16 +00:00
0dc8c153d2 devel (#3)
All checks were successful
Release Tagging / release (push) Successful in 35s
Rust Build / Check (push) Successful in 31s
Rust Build / Test Suite (push) Successful in 28s
Rust Build / Rustfmt (push) Successful in 25s
Rust Build / Clippy (push) Successful in 33s
Rust Build / build (push) Successful in 29s
Reviewed-on: #3
2025-03-30 18:11:03 +00:00
6 changed files with 396 additions and 89 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "icarus_meta"
version = "0.1.0"
version = "0.1.30"
edition = "2024"
rust-version = "1.86"

View File

@@ -1,20 +1,3 @@
use lofty::{file::AudioFile, tag::Accessor};
use crate::types;
fn get_type(t: types::Type) -> Result<String, std::io::Error> {
match t {
types::Type::Title => Ok("TITLE".to_owned()),
types::Type::Artist => Ok("ARTIST".to_owned()),
types::Type::Album => Ok("ALBUM".to_owned()),
types::Type::AlbumArtist => Ok("ALBUMARTIST".to_owned()),
types::Type::Genre => Ok("GENRE".to_owned()),
types::Type::Date => Ok("DATE".to_owned()),
types::Type::Track => Ok("TRACKNUMBER".to_owned()),
types::Type::Disc => Ok("DISCNUMBER".to_owned()),
}
}
pub mod coverart {
use lofty::{file::AudioFile, ogg::OggPictureStorage};
@@ -88,92 +71,169 @@ pub mod coverart {
Err(err) => Err(err),
}
}
}
pub fn get_meta(t: types::Type, filepath: &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(flac_file) => match flac_file.vorbis_comments() {
Some(vb) => {
let type_str: String = get_type(t).unwrap();
match vb.get(&type_str) {
Some(val) => Ok(val.to_owned()),
None => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Could not get tag data",
)),
pub fn contains_coverart(song_filepath: &String) -> Result<(bool, usize), std::io::Error> {
match std::fs::File::open(song_filepath) {
Ok(mut file) => {
match lofty::flac::FlacFile::read_from(
&mut file,
lofty::config::ParseOptions::new(),
) {
Ok(flac_file) => {
let pictures = flac_file.pictures();
if pictures.is_empty() {
Ok((false, 0))
} else {
let res = pictures.to_vec();
if res.is_empty() {
Ok((false, 0))
} else {
Ok((true, res.len()))
}
}
}
None => Err(std::io::Error::new(
Err(err) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"No tags found",
err.to_string(),
)),
},
Err(err) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
err.to_string(),
)),
}
}
Err(err) => Err(err),
}
}
pub fn remove_coverart(song_filepath: &String) -> Result<Vec<u8>, std::io::Error> {
match std::fs::File::open(song_filepath) {
Ok(mut file) => {
match lofty::flac::FlacFile::read_from(
&mut file,
lofty::config::ParseOptions::new(),
) {
Ok(mut flac_file) => {
let pictures = flac_file.pictures();
let res = pictures.to_vec();
if !res.is_empty() {
let picture = &res[0];
flac_file.remove_picture(0);
Ok(picture.clone().0.into_data())
} else {
Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"No pictures found",
))
}
}
Err(err) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
err.to_string(),
)),
}
}
Err(err) => Err(err),
}
Err(err) => Err(err),
}
}
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) => {
let pre_value = value.clone();
match t {
types::Type::Album => {
vb.set_album(pre_value);
}
types::Type::AlbumArtist => {
vb.insert(get_type(t).unwrap(), pre_value);
}
types::Type::Artist => {
vb.set_artist(pre_value);
}
types::Type::Date => {
vb.insert(get_type(t).unwrap(), pre_value);
}
types::Type::Disc => {
vb.set_disk(pre_value.parse().unwrap());
}
types::Type::Genre => {
vb.set_genre(pre_value);
}
types::Type::Title => {
vb.set_title(pre_value);
}
types::Type::Track => {
vb.set_track(pre_value.parse().unwrap());
}
};
pub mod metadata {
use crate::types;
use lofty::file::AudioFile;
use lofty::tag::Accessor;
Ok(value.to_owned())
}
None => Err(std::io::Error::new(
pub fn get_meta(t: types::Type, filepath: &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(flac_file) => match flac_file.vorbis_comments() {
Some(vb) => {
let type_str: String = types::access::get_type(t).unwrap();
match vb.get(&type_str) {
Some(val) => Ok(val.to_owned()),
None => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"Could not get tag data",
)),
}
}
None => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"No tags found",
)),
},
Err(err) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
"No tags found",
err.to_string(),
)),
},
Err(err) => Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
err.to_string(),
)),
}
}
Err(err) => Err(err),
}
}
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) => {
let pre_value = value.clone();
match t {
types::Type::Album => {
vb.set_album(pre_value);
}
types::Type::AlbumArtist => {
vb.insert(types::access::get_type(t).unwrap(), pre_value);
}
types::Type::Artist => {
vb.set_artist(pre_value);
}
types::Type::Date => {
vb.insert(types::access::get_type(t).unwrap(), pre_value);
}
types::Type::Disc => {
vb.set_disk(pre_value.parse().unwrap());
}
types::Type::Genre => {
vb.set_genre(pre_value);
}
types::Type::Title => {
vb.set_title(pre_value);
}
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())
}
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),
}
Err(err) => Err(err),
}
}
@@ -254,6 +314,7 @@ mod tests {
}
mod get {
use super::metadata::get_meta;
use super::*;
use crate::types;
@@ -455,10 +516,62 @@ 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 {
use super::metadata::{get_meta, set_meta};
use super::*;
use crate::types;
#[test]
fn test_set_title() {
@@ -822,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);
@@ -944,5 +1172,64 @@ mod tests {
}
};
}
#[test]
fn test_picture_exists() {
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 coverart::contains_coverart(&filepath) {
Ok((exists, pictures)) => {
assert!(exists, "File should have a cover art");
assert!((pictures > 0), "No cover art was found in the file");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
}
Err(err) => {
assert!(false, "Error: File does not exist {:?}", err.to_string());
}
};
}
#[test]
fn test_remove_picture() {
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("track09.flac");
let new_filepath = get_full_path(&test_dir, &test_filename).unwrap();
match file_exists(&dir, &filename) {
Ok(_) => {
let filepath = get_full_path(&dir, &filename).unwrap();
match util::copy_file(&filepath, &new_filepath) {
Ok(_o) => match coverart::remove_coverart(&new_filepath) {
Ok(bytes) => {
assert_eq!(false, bytes.is_empty(), "This should not be empty");
}
Err(err) => {
assert!(false, "Error: {:?}", err);
}
},
Err(err) => {
assert!(false, "Error: {:?}", err);
}
}
}
Err(err) => {
assert!(false, "Error: File does not exist {:?}", err.to_string());
}
};
}
}
}

View File

@@ -7,4 +7,24 @@ pub enum Type {
Date,
Track,
Disc,
TrackCount,
DiscCount,
}
pub mod access {
pub fn get_type(t: super::Type) -> Result<String, std::io::Error> {
match t {
super::Type::Title => Ok("TITLE".to_owned()),
super::Type::Artist => Ok("ARTIST".to_owned()),
super::Type::Album => Ok("ALBUM".to_owned()),
super::Type::AlbumArtist => Ok("ALBUMARTIST".to_owned()),
super::Type::Genre => Ok("GENRE".to_owned()),
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()),
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.