1 use dbus::blocking::stdintf::org_freedesktop_dbus::PropertiesPropertiesChanged;
2 use dbus::blocking::Connection;
3 use dbus::message::Message;
4 use std::time::Duration;
6 fn main() -> Result<(), Box<dyn std::error::Error>> {
7 let conn = Connection::new_session()?;
9 let proxy = conn.with_proxy(
10 "org.mpris.MediaPlayer2.spotify",
11 "/org/mpris/MediaPlayer2",
12 Duration::from_millis(5000),
15 let _ = proxy.match_signal(
16 |pc: PropertiesPropertiesChanged, _: &Connection, _: &Message| {
17 pc.changed_properties["Metadata"]
20 .and_then(|mut iter| {
21 // Iterating over a RefArg goes key, value, key, value... Insane honestly.
22 while let Some(key) = iter.next() {
23 let key_str = key.as_str()?;
24 let value = iter.next();
28 // Variant holding a variant that should just be a Vec<&str> I
29 // believe. This is _the recommended_ way to do this by the author.
30 let inner_value = value?.as_iter()?.next()?.as_iter()?.next()?;
31 let artist = String::from(inner_value.as_str()?);
32 println!("artist: {}", artist);
35 println!("title: {}", value?.as_iter()?.next()?.as_str()?);
47 conn.process(Duration::from_millis(1000))?;