From 79b46cd5aa5afef1b00e436491aaa0d5c026297c Mon Sep 17 00:00:00 2001 From: Jacob Casper Date: Sat, 17 Oct 2020 20:46:59 -0500 Subject: [PATCH] Get artist of currently playing track --- src/main.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index df3b54e..1d8624e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,7 +14,28 @@ fn main() -> Result<(), Box> { let _ = proxy.match_signal( |pc: PropertiesPropertiesChanged, _: &Connection, _: &Message| { - println! {"dumping {:#x?}", pc.changed_properties["Metadata"]}; + pc.changed_properties["Metadata"] + .0 + .as_iter() + .and_then(|mut iter| { + // Iterating over a RefArg goes key, value, key, value... Insane honestly. + while let Some(key) = iter.next() { + let key_str = key.as_str()?; + let value = iter.next(); + + match key_str { + "xesam:artist" => { + // Variant holding a variant that should just be a Vec<&str> I + // believe. This is _the recommended_ way to do this by the author. + let inner_value = value?.as_iter()?.next()?.as_iter()?.next()?; + let artist = String::from(inner_value.as_str()?); + println!("artist: {}", artist); + } + _ => (), + } + } + Some(()) + }); true }, ); -- 2.20.1