More tests, but need to be run with --test-threads=1

This commit is contained in:
Andrew Radev
2019-02-17 21:55:04 +02:00
parent 7b8ac1b476
commit 915a6e8ff4
4 changed files with 301 additions and 63 deletions

View File

@ -19,7 +19,7 @@ pub fn embed_image(music_filename: &str, image_filename: &str) -> Result<(), Box
});
tag.write_to_path(music_filename, id3::Version::Id3v23).
map_err(|e| format!("Error writing image to file: {}", e))?;
map_err(|e| format!("Error writing image to music file {}: {}", music_filename, e))?;
Ok(())
}
@ -33,7 +33,8 @@ pub fn extract_image(music_filename: &str, image_filename: &str) -> Result<(), B
if let Some(p) = first_picture {
match image::load_from_memory(&p.data) {
Ok(image) => {
image.save(&image_filename);
image.save(&image_filename).
map_err(|e| format!("Couldn't write image file {}: {}", image_filename, e))?;
println!("{}", image_filename);
},
Err(e) => return Err(format!("Couldn't load image: {}", e).into()),
@ -42,3 +43,15 @@ pub fn extract_image(music_filename: &str, image_filename: &str) -> Result<(), B
Ok(())
}
pub fn remove_images(music_filename: &str) -> Result<(), Box<Error>> {
let mut tag = id3::Tag::read_from_path(&music_filename).
map_err(|e| format!("Error reading music file {}: {}", music_filename, e))?;
tag.remove("APIC");
tag.write_to_path(music_filename, id3::Version::Id3v23).
map_err(|e| format!("Error updating music file {}: {}", music_filename, e))?;
Ok(())
}