use flac_codec::metadata::{Picture, PictureType, update};
fn main() {
match std::env::args_os().skip(1).collect::<Vec<_>>().as_slice() {
[image] => match Picture::open(PictureType::FrontCover, "", image) {
Ok(Picture {
media_type,
width,
height,
color_depth,
colors_used,
..
}) => {
println!(" MIME type : {media_type}");
println!(" width : {width}");
println!(" height : {height}");
println!("color depth : {color_depth}");
if let Some(colors_used) = colors_used {
println!("colors used : {colors_used}");
}
}
Err(err) => eprintln!("* {} : {err}", image.display()),
},
[image, flacs @ ..] => match Picture::open(PictureType::FrontCover, "", image) {
Ok(picture) => {
if let Err(err) = flacs.iter().try_for_each(|flac| {
update(flac, |blocklist| {
blocklist.remove::<Picture>();
blocklist.insert(picture.clone());
Ok::<(), flac_codec::Error>(())
})
.map(|_| ())
}) {
eprintln!("* Error : {err}");
}
}
Err(err) => eprintln!("* {} : {err}", image.display()),
},
[] => eprintln!("* Usage: <image file> <file1.flac> <file2.flac> ..."),
}
}