diff --git a/src/mpris.rs b/src/mpris.rs index 3457edf..d65db7d 100644 --- a/src/mpris.rs +++ b/src/mpris.rs @@ -1,4 +1,4 @@ -mod player; +pub mod player; pub use player::Player; use adw::prelude::*; diff --git a/src/mpris/player.rs b/src/mpris/player.rs index c654cc9..5564049 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -13,7 +13,7 @@ pub struct MetadataMap { // mpris track_id: Option, length: Option, - art_url: Option, + art_url: Option, // xesam album: Option, //album_artist: Option>, @@ -36,6 +36,14 @@ pub struct MetadataMap { user_rating: Option, } +pub fn art_path() -> &'static std::path::Path { + static PATH: std::sync::OnceLock = 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