initial work for mpris cover art

This commit is contained in:
Erica Z 2024-11-19 21:34:15 +01:00
parent 3963c8404c
commit d5d7ff882e
2 changed files with 11 additions and 3 deletions

View file

@ -1,4 +1,4 @@
mod player;
pub mod player;
pub use player::Player;
use adw::prelude::*;

View file

@ -13,7 +13,7 @@ pub struct MetadataMap {
// mpris
track_id: Option<OwnedObjectPath>,
length: Option<i64>,
art_url: Option<url::Url>,
art_url: Option<String>,
// xesam
album: Option<String>,
//album_artist: Option<Vec<String>>,
@ -36,6 +36,14 @@ pub struct MetadataMap {
user_rating: Option<f32>,
}
pub fn art_path() -> &'static std::path::Path {
static PATH: std::sync::OnceLock<std::path::PathBuf> = std::sync::OnceLock::new();
PATH.get_or_init(|| {
let xdg_dirs = xdg::BaseDirectories::with_prefix("audrey").expect("failed to get xdg dirs");
xdg_dirs.get_state_file("mpris-art")
})
}
impl MetadataMap {
pub fn from_playbin_song(song: Option<&Song>) -> Self {
song.map(|song| MetadataMap {
@ -46,7 +54,7 @@ impl MetadataMap {
.unwrap()
}),
length: Some(song.duration() * MICROSECONDS as i64),
//art_url: Some(song.cover_art_url()), // FIXME: this would leak credentials
art_url: Some(url::Url::from_file_path(art_path()).unwrap().to_string()),
album: Some(song.album()),
artist: Some(vec![song.artist()]),
//content_created: song.year().map(|year| chrono::NaiveDate::from_yo_opt(year, 1).unwrap()), // FIXME: replace this unwrap with Some(Err) -> None