diff --git a/src/mpris/player.rs b/src/mpris/player.rs index ef3e04b..4bb9909 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -62,60 +62,6 @@ impl MetadataMap { }) .unwrap_or_default() } - - fn as_hash_map(&self) -> HashMap<&'static str, OwnedValue> { - let mut map = HashMap::new(); - - if let Some(track_id) = &self.track_id { - map.insert( - "mpris:trackid", - Value::new(track_id.as_ref()).try_into().unwrap(), - ); - } - if let Some(art_url) = &self.art_url { - map.insert( - "mpris:artUrl", - Value::new(art_url.to_string()).try_into().unwrap(), - ); - } - if let Some(length) = &self.length { - map.insert("mpris:length", Value::new(length).try_into().unwrap()); - } - if let Some(album) = &self.album { - map.insert("xesam:album", Value::new(album).try_into().unwrap()); - } - if let Some(artist) = &self.artist { - map.insert("xesam:artist", Value::new(artist).try_into().unwrap()); - } - if let Some(content_created) = &self.content_created { - map.insert( - "xesam:contentCreated", - Value::new(content_created.format("%+").to_string()) - .try_into() - .unwrap(), - ); - } - if let Some(genre) = &self.genre { - map.insert("xesam:genre", Value::new(genre).try_into().unwrap()); - } - if let Some(track_number) = self.track_number { - map.insert( - "xesam:trackNumber", - Value::new(track_number).try_into().unwrap(), - ); - } - if let Some(title) = &self.title { - map.insert("xesam:title", Value::new(title).try_into().unwrap()); - } - if let Some(user_rating) = self.user_rating { - map.insert( - "xesam:userRating", - Value::new(user_rating).try_into().unwrap(), - ); - } - - map - } } pub struct Player { @@ -264,8 +210,59 @@ impl Player { #[zbus(property)] fn metadata(&self) -> HashMap<&'static str, OwnedValue> { - // TODO: no need to MetadataMap wrapper anymore - MetadataMap::from_playbin_song(self.window().song().as_ref()).as_hash_map() + let metadata = MetadataMap::from_playbin_song(self.window().song().as_ref()); + + let mut map = HashMap::new(); + + if let Some(track_id) = &metadata.track_id { + map.insert( + "mpris:trackid", + Value::new(track_id.as_ref()).try_into().unwrap(), + ); + } + if let Some(art_url) = &metadata.art_url { + map.insert( + "mpris:artUrl", + Value::new(art_url.to_string()).try_into().unwrap(), + ); + } + if let Some(length) = &metadata.length { + map.insert("mpris:length", Value::new(length).try_into().unwrap()); + } + if let Some(album) = &metadata.album { + map.insert("xesam:album", Value::new(album).try_into().unwrap()); + } + if let Some(artist) = &metadata.artist { + map.insert("xesam:artist", Value::new(artist).try_into().unwrap()); + } + if let Some(content_created) = &metadata.content_created { + map.insert( + "xesam:contentCreated", + Value::new(content_created.format("%+").to_string()) + .try_into() + .unwrap(), + ); + } + if let Some(genre) = &metadata.genre { + map.insert("xesam:genre", Value::new(genre).try_into().unwrap()); + } + if let Some(track_number) = metadata.track_number { + map.insert( + "xesam:trackNumber", + Value::new(track_number).try_into().unwrap(), + ); + } + if let Some(title) = &metadata.title { + map.insert("xesam:title", Value::new(title).try_into().unwrap()); + } + if let Some(user_rating) = metadata.user_rating { + map.insert( + "xesam:userRating", + Value::new(user_rating).try_into().unwrap(), + ); + } + + map } #[zbus(property)]