From 3b3e3166ca028b7407f2f874790df6145b922c5c Mon Sep 17 00:00:00 2001 From: Erica Z Date: Sat, 2 Nov 2024 08:46:37 +0100 Subject: [PATCH] url things --- src/mpris/player.rs | 6 +++++- src/playbin.vala | 13 +++++++++---- src/playbin/song.rs | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/mpris/player.rs b/src/mpris/player.rs index e119559..3202f90 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -11,7 +11,7 @@ struct MetadataMap { // mpris track_id: Option, length: Option, - //art_url: Option, + art_url: Option, // xesam album: Option, //album_artist: Option>, @@ -44,6 +44,7 @@ impl MetadataMap { .unwrap() }), length: Some(song.duration() * MICROSECONDS as i64), + //art_url: Some(song.cover_art_url()), // FIXME: this would leak credentials album: Some(song.album().into()), artist: Some(vec![song.artist().into()]), //content_created: song.year().map(|year| chrono::NaiveDate::from_yo_opt(year, 1).unwrap()), // FIXME: replace this unwrap with Some(Err) -> None @@ -62,6 +63,9 @@ impl MetadataMap { if let Some(track_id) = &self.track_id { map.insert("mpris:trackid", Value::new(track_id.as_ref())); } + if let Some(art_url) = &self.art_url { + map.insert("mpris:artUrl", Value::new(art_url.to_string())); + } if let Some(length) = &self.length { map.insert("mpris:length", Value::new(length)); } diff --git a/src/playbin.vala b/src/playbin.vala index 74d1eee..3966c7d 100644 --- a/src/playbin.vala +++ b/src/playbin.vala @@ -23,6 +23,9 @@ public class Audrey.PlaybinSong : Object { public int64 track { get { return inner.track; } } public int64 play_count { get { return inner.play_count; } } + public string cover_art_url { owned get { return this.api.cover_art_uri (this.id); } } + public string stream_url { owned get { return this.api.stream_uri (this.id); } } + public Gdk.Paintable? thumbnail { get; private set; } private Cancellable cancel_loading_thumbnail; @@ -363,24 +366,26 @@ public class Audrey.Playbin : GLib.Object { } public void append_track (Subsonic.Song song) { + var pb_song = new PlaybinSong (this.api, song); assert (this.mpv.command ({ "loadfile", - this.api.stream_uri (song.id), + pb_song.stream_url, "append", }) >= 0); - this._play_queue.append (new PlaybinSong (this.api, song)); + this._play_queue.append (pb_song); this.play_queue_length += 1; } public async void append_track_async (Subsonic.Song song) { + var pb_song = new PlaybinSong (this.api, song); var err = yield this.mpv_command_async ({ "loadfile", - this.api.stream_uri (song.id), + pb_song.stream_url, "append", }); assert (err >= 0); - this._play_queue.append (new PlaybinSong (this.api, song)); + this._play_queue.append (pb_song); this.play_queue_length += 1; } diff --git a/src/playbin/song.rs b/src/playbin/song.rs index 83cba29..658b771 100644 --- a/src/playbin/song.rs +++ b/src/playbin/song.rs @@ -1,5 +1,6 @@ pub mod ffi { use gtk::glib; + use std::ffi::c_char; #[repr(C)] pub struct AudreyPlaybinSong { @@ -14,18 +15,16 @@ pub mod ffi { extern "C" { pub fn audrey_playbin_song_get_type() -> glib::ffi::GType; pub fn audrey_playbin_song_get_counter(self_: *mut AudreyPlaybinSong) -> i64; - pub fn audrey_playbin_song_get_id(self_: *mut AudreyPlaybinSong) - -> *const std::ffi::c_char; - pub fn audrey_playbin_song_get_title( - self_: *mut AudreyPlaybinSong, - ) -> *const std::ffi::c_char; - pub fn audrey_playbin_song_get_artist( - self_: *mut AudreyPlaybinSong, - ) -> *const std::ffi::c_char; - pub fn audrey_playbin_song_get_album( - self_: *mut AudreyPlaybinSong, - ) -> *const std::ffi::c_char; + pub fn audrey_playbin_song_get_id(self_: *mut AudreyPlaybinSong) -> *const c_char; + pub fn audrey_playbin_song_get_title(self_: *mut AudreyPlaybinSong) -> *const c_char; + pub fn audrey_playbin_song_get_artist(self_: *mut AudreyPlaybinSong) -> *const c_char; + pub fn audrey_playbin_song_get_album(self_: *mut AudreyPlaybinSong) -> *const c_char; pub fn audrey_playbin_song_get_duration(self_: *mut AudreyPlaybinSong) -> i64; + + pub fn audrey_playbin_song_get_cover_art_url( + self_: *mut AudreyPlaybinSong, + ) -> *const c_char; + pub fn audrey_playbin_song_get_stream_url(self_: *mut AudreyPlaybinSong) -> *const c_char; } } @@ -65,4 +64,22 @@ impl Song { pub fn duration(&self) -> i64 { unsafe { ffi::audrey_playbin_song_get_duration(self.to_glib_none().0) } } + + pub fn cover_art_url(&self) -> url::Url { + let url: String = unsafe { + from_glib_none(ffi::audrey_playbin_song_get_cover_art_url( + self.to_glib_none().0, + )) + }; + url::Url::parse(&url).expect("invalid url from vala side") + } + + pub fn stream_url(&self) -> url::Url { + let url: String = unsafe { + from_glib_none(ffi::audrey_playbin_song_get_stream_url( + self.to_glib_none().0, + )) + }; + url::Url::parse(&url).expect("invalid url from vala side") + } }