|
@@ -0,0 +1,35 @@
|
|
|
+extern crate mpd;
|
|
|
+
|
|
|
+use comm;
|
|
|
+use comm::Channel;
|
|
|
+use config::Config;
|
|
|
+use self::mpd::client::Client;
|
|
|
+use self::mpd::song::Song;
|
|
|
+use self::mpd::idle;
|
|
|
+use self::mpd::idle::Idle;
|
|
|
+use self::mpd::status::State;
|
|
|
+
|
|
|
+pub fn music(tx: &Channel, _cfg: &Config) {
|
|
|
+ let mut conn = Client::connect("127.0.0.1:6600").unwrap();
|
|
|
+ loop {
|
|
|
+ let state = match conn.status().unwrap().state {
|
|
|
+ State::Play => "",
|
|
|
+ State::Pause => "",
|
|
|
+ State::Stop => ""
|
|
|
+ };
|
|
|
+
|
|
|
+ let song = conn.currentsong().unwrap();
|
|
|
+ let stopped = "Stopped".to_string();
|
|
|
+ let display = song.as_ref().map(get_display).unwrap_or(stopped);
|
|
|
+ comm::send(tx, "mpd", &format!("%{{A:mpd:}}{} {}%{{A}}", state, display));
|
|
|
+ conn.wait(&[idle::Subsystem::Player]).ok();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+fn get_display(song: &Song) -> String {
|
|
|
+ let unknown = "Unknown".to_string();
|
|
|
+ let artist = song.tags.get("Artist").unwrap_or(&unknown);
|
|
|
+ let title = song.tags.get("Title").unwrap_or(&unknown);
|
|
|
+
|
|
|
+ format!("{} - {}", artist, title)
|
|
|
+}
|