~phate/mpc-status

c97346d864d99a5940fe748b983fb5644cc86fef — ValleyKnight 1 year, 8 months ago 9c1b04d
add check for if mpd is stopped
1 files changed, 18 insertions(+), 14 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +18 -14
@@ 22,19 22,23 @@ fn format_time(time: i64) -> String {
fn main() {
    let mut c = Client::connect("127.0.0.1:6600").unwrap();
    let status: Status = c.status().unwrap();
    let song: Song = c.currentsong().unwrap().unwrap();
    let na = "N/A".to_string();
    let gen = song.tags.get("Genre").unwrap_or(&na);
    let art = song.tags.get("Artist").unwrap_or(&na);
    let alb = song.tags.get("Album").unwrap_or(&na);
    let tit = song.title.as_ref().unwrap();
    let dat = song.tags.get("Date").unwrap_or(&na);
    let elap = status.elapsed.unwrap().num_seconds();
    let elapsed = format_time(elap);
    let dur = status.duration.unwrap().num_seconds();
    let duration = format_time(dur);
    let stat = status.state;
    let state = PlayState { sta: stat }.to_string();
    let state = find_and_replace(&state, &["s/Play/Playing/g", "s/Pause/Paused/g"]).unwrap();
    println!("{} - {} - {} ({}) - {} -- {} -- [{}/{}]", gen, art, alb, dat, tit, state, elapsed, duration);
    if stat == State::Play {
        let song: Song = c.currentsong().unwrap().unwrap();
        let na = "N/A".to_string();
        let gen = song.tags.get("Genre").unwrap_or(&na);
        let art = song.tags.get("Artist").unwrap_or(&na);
        let alb = song.tags.get("Album").unwrap_or(&na);
        let tit = song.title.as_ref().unwrap();
        let dat = song.tags.get("Date").unwrap_or(&na);
        let elap = status.elapsed.unwrap().num_seconds();
        let elapsed = format_time(elap);
        let dur = status.duration.unwrap().num_seconds();
        let duration = format_time(dur);
        let state = PlayState { sta: stat }.to_string();
        let state = find_and_replace(&state, &["s/Play/Playing/g", "s/Pause/Paused/g"]).unwrap();
        println!("{} - {} - {} ({}) - {} -- {} -- [{}/{}]", gen, art, alb, dat, tit, state, elapsed, duration);
    } else if stat == State::Stop {
        println!("[mpd is stopped]");
    }
}