~phate/musinfo

df76968be7092a263924638ef0ed27849973e118 — ValleyKnight 2 years ago 67ab1fe
add check for if mpd is stopped
1 files changed, 35 insertions(+), 30 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +35 -30
@@ 49,38 49,43 @@ fn info_extended(status: &mut Status) -> (String, String, String) {
fn main() {
    let mut c = Client::connect("127.0.0.1:6600").unwrap();
    let mut status: Status = c.status().unwrap();
    let (format, tit, art, alb, dat, gen) = info(&mut c);
    let (elapsed, duration, bitrate) = info_extended(&mut status);
    let stat = status.state;
    let state = PlayState { sta: stat }.to_string();
    let info = [format, " @ ".to_string(), bitrate].concat();
    // elapsed/duration [state]
    // title [format @ bitrate kbps]
    // album [date]
    // artist
    // genre
    // ^^ Output of `msg`
    let msg = [
        elapsed,
        "/".to_string(),
        duration,
        " [".to_string(),
        state,
        "]\n".to_string(),
        tit,
        " [".to_string(),
        info,
        "]\n".to_string(),
        alb,
        " [".to_string(),
        dat,
        "]\n".to_string(),
        art,
        "\n".to_string(),
        gen,
    ].concat();
    let message: String = if stat == State::Play {
        let (format, tit, art, alb, dat, gen) = info(&mut c);
        let (elapsed, duration, bitrate) = info_extended(&mut status);
        let state = PlayState { sta: stat }.to_string();
        let info = [format, " @ ".to_string(), bitrate].concat();
        // elapsed/duration [state]
        // title [format @ bitrate kbps]
        // album [date]
        // artist
        // genre
        // ^^ Output of `msg`
        [elapsed,
            "/".to_string(),
            duration,
            " [".to_string(),
            state,
            "]\n".to_string(),
            tit,
            " [".to_string(),
            info,
            "]\n".to_string(),
            alb,
            " [".to_string(),
            dat,
            "]\n".to_string(),
            art,
            "\n".to_string(),
            gen,
        ].concat()
    } else if stat == State::Stop {
        "[mpd is stopped]".to_string()
    } else {
        "[this is broken]".to_string()
    };
    Notification::new()
        .summary(&msg)
        .summary(&message)
        .icon("/tmp/cover.png") // Cover art should be wrote to `/tmp/cover.png`
        .timeout(Timeout::Milliseconds(6000)) // Notification closes in 6s
        .show()