Compare commits

..

No commits in common. "c827dd4863d54253787b9556c24982f022311a19" and "e4c54dc6f577030a9848c5b2b222f64de2c44786" have entirely different histories.

4 changed files with 30 additions and 48 deletions

View file

@ -1,16 +1,15 @@
pub mod globals {
use std::path::PathBuf;
use tokio::sync::Mutex;
pub fn xdg_dirs() -> &'static xdg::BaseDirectories {
static DIRS: std::sync::LazyLock<xdg::BaseDirectories> = std::sync::LazyLock::new(|| {
xdg::BaseDirectories::with_prefix("audrey").expect("failed to get xdg dirs")
pub fn art_path() -> &'static std::path::Path {
static ART_PATH: std::sync::LazyLock<std::path::PathBuf> = std::sync::LazyLock::new(|| {
let xdg_dirs =
xdg::BaseDirectories::with_prefix("audrey").expect("failed to get xdg dirs");
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 {
static RUNTIME: std::sync::LazyLock<tokio::runtime::Runtime> =
std::sync::LazyLock::new(|| {

View file

@ -30,8 +30,6 @@ mod imp {
duration: Cell<i64>,
#[property(get, set)]
track: Cell<i64>,
#[property(get, set)]
cover_art: RefCell<String>,
#[property(get, set)]
stream_url: RefCell<String>,
@ -85,7 +83,6 @@ impl Song {
.property("duration", song.duration as i64)
.property("track", song.track.map(i64::from).unwrap_or(-1))
.property("stream-url", api.stream_url(&song.id).as_str())
.property("cover-art", &song.cover_art)
.build();
song

View file

@ -92,11 +92,10 @@ impl Player {
#[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<()> {
//let metadata = self.metadata();
// TODO: reimplment stale seeks
//if Some(&track_id.into()) == metadata.get("track_id") {
self.window().set_time_pos(position as f64 / MICROSECONDS);
//}
let metadata = self.metadata();
if Some(&track_id.into()) == metadata.get("track_id") {
self.window().set_time_pos(position as f64 / MICROSECONDS);
}
Ok(())
}
@ -154,29 +153,31 @@ impl Player {
}
#[zbus(property)]
async fn metadata(&self) -> HashMap<&'static str, Value<'_>> {
fn metadata(&self) -> HashMap<&'static str, Value<'_>> {
let mut map = HashMap::new();
let mpris_art_path = audrey::globals::MPRIS_ART_PATH.lock().await;
if let Some(song) = self.window().song() {
map.insert(
"mpris:trackid",
format!("/eu/callcc/audrey/Track/{}", song.counter()).into(),
Value::new(format!("/eu/callcc/audrey/Track/{}", song.counter())).to_owned(),
);
map.insert(
"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(
"mpris:artUrl",
(url::Url::from_file_path(path).unwrap().to_string()).into(),
);
}
map.insert("xesam:album", song.album().into());
map.insert(
"mpris:artUrl",
Value::new(
url::Url::from_file_path(audrey::globals::art_path())
.unwrap()
.to_string(),
)
.to_owned(),
);
map.insert("xesam:album", Value::new(song.album()));
// TODO: use the right opensubsonic data
map.insert("xesam:artist", vec![song.artist()].into());
map.insert("xesam:title", song.title().into());
map.insert("xesam:artist", Value::new(vec![song.artist()]));
map.insert("xesam:title", Value::new(song.title()));
}
map

View file

@ -733,7 +733,7 @@ mod imp {
self.mpris_player_playback_status_changed();
let window = self.obj().clone();
let song_id = song.id();
let song_id = window.song().unwrap().id();
if let Some(handle) = self
.loading_cover_handle
.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
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(
move || -> Result<(), image::ImageError> {
// TODO: wipe xdg state folder on init
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 save_path = audrey::globals::art_path();
let resized =
image_copy.resize(400, 400, image::imageops::FilterType::Lanczos3);
resized.save_with_format(&save_path_copy, image::ImageFormat::Jpeg)?;
*mpris_art_path = Some(save_path_copy);
resized.save_with_format(save_path, image::ImageFormat::Jpeg)?;
Ok(())
},
);