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
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>
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "icarus_meta"
|
name = "icarus_meta"
|
||||||
version = "0.1.10"
|
version = "0.1.11"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.86"
|
rust-version = "1.86"
|
||||||
|
|
||||||
|
65
src/meta.rs
65
src/meta.rs
@@ -118,6 +118,37 @@ pub mod coverart {
|
|||||||
Err(err) => Err(err),
|
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),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Error> {
|
pub fn get_meta(t: types::Type, filepath: &String) -> Result<String, std::io::Error> {
|
||||||
@@ -999,5 +1030,39 @@ mod tests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user