url things
This commit is contained in:
parent
76a8315434
commit
3b3e3166ca
3 changed files with 42 additions and 16 deletions
|
@ -11,7 +11,7 @@ struct MetadataMap {
|
|||
// mpris
|
||||
track_id: Option<OwnedObjectPath>,
|
||||
length: Option<i64>,
|
||||
//art_url: Option<url::Url>,
|
||||
art_url: Option<url::Url>,
|
||||
// xesam
|
||||
album: Option<String>,
|
||||
//album_artist: Option<Vec<String>>,
|
||||
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue