Last active
October 9, 2024 19:03
-
-
Save mxxntype/e2c128a7645d22c39a9d237beb11090e to your computer and use it in GitHub Desktop.
A snippet of getting the cover art (APIC frame) from a music file. For later use :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use eyre::{Context, ContextCompat, Report}; | |
| use id3::{Content, Tag, TagLike}; | |
| use image::ImageReader; | |
| use std::{env, io::Cursor}; | |
| fn main() -> Result<(), Report> { | |
| color_eyre::install()?; | |
| get_cover_art(env::args().nth(1).unwrap().as_str())?; | |
| Ok(()) | |
| } | |
| fn get_cover_art(path: &str) -> Result<(), Report> { | |
| let tag = Tag::read_from_path(path).wrap_err("Couldn't read tag")?; | |
| let apic_frame = tag.get("APIC").wrap_err("Couldn't get APIC frame")?; | |
| if let Content::Picture(cover) = apic_frame.content() { | |
| ImageReader::new(Cursor::new(&cover.data)) | |
| .with_guessed_format()? | |
| .decode()? | |
| .save("cover.png")?; | |
| } | |
| Ok(()) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment