~phate/musinfo

0d0e27d7047e83a93a55255a26f237176380b456 — ValleyKnight 2 years ago f9e2377 master
fix when paused
1 files changed, 38 insertions(+), 31 deletions(-)

M src/main.rs
M src/main.rs => src/main.rs +38 -31
@@ 46,41 46,48 @@ fn info_extended(status: &mut Status) -> (String, String, String) {
    (elapsed, duration, bitrate)
}

fn build_message(mut c: Client, stat: State, mut status: Status) -> String {
    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`
    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();
    return msg;
}

fn main() {
    let mut c = Client::connect("127.0.0.1:6600").unwrap();
    let mut status: Status = c.status().unwrap();
    let status: Status = c.status().unwrap();
    let stat = status.state;
    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()
        build_message(c, stat, status)
    } else if stat == State::Pause {
        build_message(c, stat, status)
    } else if stat == State::Stop {
        "[mpd is stopped]".to_string()
    } else {