Compare commits
No commits in common. "c827dd4863d54253787b9556c24982f022311a19" and "e4c54dc6f577030a9848c5b2b222f64de2c44786" have entirely different histories.
c827dd4863
...
e4c54dc6f5
4 changed files with 30 additions and 48 deletions
17
src/lib.rs
17
src/lib.rs
|
@ -1,16 +1,15 @@
|
||||||
pub mod globals {
|
pub mod globals {
|
||||||
use std::path::PathBuf;
|
pub fn art_path() -> &'static std::path::Path {
|
||||||
use tokio::sync::Mutex;
|
static ART_PATH: std::sync::LazyLock<std::path::PathBuf> = std::sync::LazyLock::new(|| {
|
||||||
|
let xdg_dirs =
|
||||||
pub fn xdg_dirs() -> &'static xdg::BaseDirectories {
|
xdg::BaseDirectories::with_prefix("audrey").expect("failed to get xdg dirs");
|
||||||
static DIRS: std::sync::LazyLock<xdg::BaseDirectories> = std::sync::LazyLock::new(|| {
|
xdg_dirs
|
||||||
xdg::BaseDirectories::with_prefix("audrey").expect("failed to get xdg dirs")
|
.place_state_file("mpris-art")
|
||||||
|
.expect("failed to create mpris art state dir")
|
||||||
});
|
});
|
||||||
&DIRS
|
&ART_PATH
|
||||||
}
|
}
|
||||||
|
|
||||||
pub static MPRIS_ART_PATH: Mutex<Option<PathBuf>> = Mutex::const_new(None);
|
|
||||||
|
|
||||||
pub fn runtime() -> &'static tokio::runtime::Runtime {
|
pub fn runtime() -> &'static tokio::runtime::Runtime {
|
||||||
static RUNTIME: std::sync::LazyLock<tokio::runtime::Runtime> =
|
static RUNTIME: std::sync::LazyLock<tokio::runtime::Runtime> =
|
||||||
std::sync::LazyLock::new(|| {
|
std::sync::LazyLock::new(|| {
|
||||||
|
|
|
@ -30,8 +30,6 @@ mod imp {
|
||||||
duration: Cell<i64>,
|
duration: Cell<i64>,
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
track: Cell<i64>,
|
track: Cell<i64>,
|
||||||
#[property(get, set)]
|
|
||||||
cover_art: RefCell<String>,
|
|
||||||
|
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
stream_url: RefCell<String>,
|
stream_url: RefCell<String>,
|
||||||
|
@ -85,7 +83,6 @@ impl Song {
|
||||||
.property("duration", song.duration as i64)
|
.property("duration", song.duration as i64)
|
||||||
.property("track", song.track.map(i64::from).unwrap_or(-1))
|
.property("track", song.track.map(i64::from).unwrap_or(-1))
|
||||||
.property("stream-url", api.stream_url(&song.id).as_str())
|
.property("stream-url", api.stream_url(&song.id).as_str())
|
||||||
.property("cover-art", &song.cover_art)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
song
|
song
|
||||||
|
|
|
@ -92,11 +92,10 @@ impl Player {
|
||||||
|
|
||||||
#[tracing::instrument(skip(self), parent = None, target = "audrey::mpris", level = Level::DEBUG, ret)]
|
#[tracing::instrument(skip(self), parent = None, target = "audrey::mpris", level = Level::DEBUG, ret)]
|
||||||
fn set_position(&self, track_id: ObjectPath<'_>, position: i64) -> zbus::fdo::Result<()> {
|
fn set_position(&self, track_id: ObjectPath<'_>, position: i64) -> zbus::fdo::Result<()> {
|
||||||
//let metadata = self.metadata();
|
let metadata = self.metadata();
|
||||||
// TODO: reimplment stale seeks
|
if Some(&track_id.into()) == metadata.get("track_id") {
|
||||||
//if Some(&track_id.into()) == metadata.get("track_id") {
|
|
||||||
self.window().set_time_pos(position as f64 / MICROSECONDS);
|
self.window().set_time_pos(position as f64 / MICROSECONDS);
|
||||||
//}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,29 +153,31 @@ impl Player {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[zbus(property)]
|
#[zbus(property)]
|
||||||
async fn metadata(&self) -> HashMap<&'static str, Value<'_>> {
|
fn metadata(&self) -> HashMap<&'static str, Value<'_>> {
|
||||||
let mut map = HashMap::new();
|
let mut map = HashMap::new();
|
||||||
let mpris_art_path = audrey::globals::MPRIS_ART_PATH.lock().await;
|
|
||||||
|
|
||||||
if let Some(song) = self.window().song() {
|
if let Some(song) = self.window().song() {
|
||||||
map.insert(
|
map.insert(
|
||||||
"mpris:trackid",
|
"mpris:trackid",
|
||||||
format!("/eu/callcc/audrey/Track/{}", song.counter()).into(),
|
Value::new(format!("/eu/callcc/audrey/Track/{}", song.counter())).to_owned(),
|
||||||
);
|
);
|
||||||
map.insert(
|
map.insert(
|
||||||
"mpris:length",
|
"mpris:length",
|
||||||
((self.window().duration() * MICROSECONDS) as i64).into(),
|
Value::new((self.window().duration() * MICROSECONDS) as i64),
|
||||||
);
|
);
|
||||||
if let Some(path) = mpris_art_path.as_ref() {
|
|
||||||
map.insert(
|
map.insert(
|
||||||
"mpris:artUrl",
|
"mpris:artUrl",
|
||||||
(url::Url::from_file_path(path).unwrap().to_string()).into(),
|
Value::new(
|
||||||
|
url::Url::from_file_path(audrey::globals::art_path())
|
||||||
|
.unwrap()
|
||||||
|
.to_string(),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
);
|
);
|
||||||
}
|
map.insert("xesam:album", Value::new(song.album()));
|
||||||
map.insert("xesam:album", song.album().into());
|
|
||||||
// TODO: use the right opensubsonic data
|
// TODO: use the right opensubsonic data
|
||||||
map.insert("xesam:artist", vec![song.artist()].into());
|
map.insert("xesam:artist", Value::new(vec![song.artist()]));
|
||||||
map.insert("xesam:title", song.title().into());
|
map.insert("xesam:title", Value::new(song.title()));
|
||||||
}
|
}
|
||||||
|
|
||||||
map
|
map
|
||||||
|
|
|
@ -733,7 +733,7 @@ mod imp {
|
||||||
self.mpris_player_playback_status_changed();
|
self.mpris_player_playback_status_changed();
|
||||||
|
|
||||||
let window = self.obj().clone();
|
let window = self.obj().clone();
|
||||||
let song_id = song.id();
|
let song_id = window.song().unwrap().id();
|
||||||
if let Some(handle) = self
|
if let Some(handle) = self
|
||||||
.loading_cover_handle
|
.loading_cover_handle
|
||||||
.replace(Some(glib::spawn_future_local(async move {
|
.replace(Some(glib::spawn_future_local(async move {
|
||||||
|
@ -754,27 +754,12 @@ mod imp {
|
||||||
|
|
||||||
// we consume image below into a pixbuf so we need a copy for save
|
// we consume image below into a pixbuf so we need a copy for save
|
||||||
let image_copy = image.clone();
|
let image_copy = image.clone();
|
||||||
let save_path = audrey::globals::xdg_dirs()
|
|
||||||
.place_state_file(format!("{}.jpg", song.cover_art()))
|
|
||||||
.expect("failed to create mpris art state dir");
|
|
||||||
let save_path_copy = save_path.clone();
|
|
||||||
let mut mpris_art_path = audrey::globals::MPRIS_ART_PATH.lock().await;
|
|
||||||
let save_future = audrey::globals::runtime().spawn_blocking(
|
let save_future = audrey::globals::runtime().spawn_blocking(
|
||||||
move || -> Result<(), image::ImageError> {
|
move || -> Result<(), image::ImageError> {
|
||||||
// TODO: wipe xdg state folder on init
|
let save_path = audrey::globals::art_path();
|
||||||
if let Some(path) = mpris_art_path.take() {
|
|
||||||
if let Err(err) = std::fs::remove_file(&path) {
|
|
||||||
event!(
|
|
||||||
Level::ERROR,
|
|
||||||
"could not remove previous mpris art at {}: {err}",
|
|
||||||
path.display()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let resized =
|
let resized =
|
||||||
image_copy.resize(400, 400, image::imageops::FilterType::Lanczos3);
|
image_copy.resize(400, 400, image::imageops::FilterType::Lanczos3);
|
||||||
resized.save_with_format(&save_path_copy, image::ImageFormat::Jpeg)?;
|
resized.save_with_format(save_path, image::ImageFormat::Jpeg)?;
|
||||||
*mpris_art_path = Some(save_path_copy);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue