1234567891011121314151617181920212223242526272829303132333435 |
- 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!("{{\"name\":\"mpd\",\"separator\":false,\"markup\":\"pango\",\"align\":\"left\",\"full_text\":\"<span face=\\\"Ionicons\\\">{}</span> {}\"}}", 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.title.as_ref().unwrap_or(&unknown);
- format!("{} - {}", artist, title)
- }
|