cover art
This commit is contained in:
19
src/coverartarchive.rs
Normal file
19
src/coverartarchive.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use std::io::Read;
|
||||
|
||||
pub fn fetch_cover_art(release_id: &str) -> Option<Vec<u8>> {
|
||||
let url = format!("https://coverartarchive.org/release/{}/front", release_id);
|
||||
let response = ureq::get(&url)
|
||||
.header("User-Agent", "Timbre/0.1 ( ...your repo... )")
|
||||
.call();
|
||||
match response {
|
||||
Ok(resp) => {
|
||||
let mut bytes = Vec::new();
|
||||
resp.into_body()
|
||||
.into_reader()
|
||||
.read_to_end(&mut bytes)
|
||||
.expect("i couldn't read the cover art :(\n");
|
||||
Some(bytes)
|
||||
}
|
||||
Err(_) => None,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user