Added code for checking if file has pictures
All checks were successful
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 38s
Rust Build / build (pull_request) Successful in 43s
All checks were successful
Rust Build / Check (pull_request) Successful in 31s
Rust Build / Test Suite (pull_request) Successful in 35s
Rust Build / Rustfmt (pull_request) Successful in 28s
Rust Build / Clippy (pull_request) Successful in 38s
Rust Build / build (pull_request) Successful in 43s
This commit is contained in:
67
src/meta.rs
67
src/meta.rs
@@ -88,6 +88,45 @@ pub mod coverart {
|
|||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
if !res.is_empty() {
|
||||||
|
let picture = &res[0];
|
||||||
|
Ok(picture.clone().0.into_data())
|
||||||
|
} else {
|
||||||
|
Ok(Vec::new())
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
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> {
|
||||||
@@ -944,5 +983,33 @@ mod tests {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_picture_exists() {
|
||||||
|
let filename = util::get_filename(1);
|
||||||
|
let dir = String::from(util::TESTFILEDIRECTORY);
|
||||||
|
|
||||||
|
// let new_coverart = String::from("Sample Tracks 3 - Other one.png");
|
||||||
|
// let new_cover_art_path = get_full_path(&dir, &new_coverart).unwrap();
|
||||||
|
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user