X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=bin%2Fkhatus_controller;fp=bin%2Fkhatus_controller;h=ae4a8dce59fa75592ee6cbe7a2bf60b48835d699;hb=a3bb1cff9b572b224736e0b475026816b274f261;hp=1ff6e83569f90e899b0e2f6f5c7b506cdc27e9e9;hpb=9419890bb9da94630bdb047d194680f2a50a1c7c;p=khatus.git diff --git a/bin/khatus_controller b/bin/khatus_controller index 1ff6e83..ae4a8dc 100755 --- a/bin/khatus_controller +++ b/bin/khatus_controller @@ -90,18 +90,32 @@ db["volume"] = $0 } -/^in:MPD_STATE/\ +/^in:MPD_SONG +file:/\ { fields_shift() - db["mpd_state"] = $1 - db["mpd_curr_song_time"] = $2 - db["mpd_curr_song_percent"] = $3 + fields_shift() + db["mpd_song_curr_file"] = $0 } -/^in:MPD_SONG/\ +/^in:MPD_SONG +Title:/\ { fields_shift() - db["mpd_curr_song_name"] = $0 + fields_shift() + db["mpd_song_curr_title"] = $0 +} +/^in:MPD_SONG +Name:/\ +{ + fields_shift() + fields_shift() + db["mpd_song_curr_name"] = $0 +} + +/^in:MPD_STATE /\ +{ + fields_shift() + db["mpd_status_state"] = $1 + db["mpd_status_time"] = $2 + db["mpd_status_percent"] = $3 } /^in:WEATHER/\ @@ -379,7 +393,7 @@ function make_status_net( \ } function make_status_mpd( state, status) { - state = db["mpd_state"] + state = db["mpd_status_state"] if (state == "play") { status = make_status_mpd_state_known("▶") @@ -394,13 +408,29 @@ function make_status_mpd( state, status) { return sprintf("[%s]", status) } -function make_status_mpd_state_known(symbol) { +function make_status_mpd_state_known(symbol, \ + currently_playing, name, title, file\ +) { + name = db["mpd_song_curr_name"] + title = db["mpd_song_curr_title:"] + file = db["mpd_song_curr_file"] + + if (name) { + currently_playing = name + } else if (title) { + currently_playing = title + } else if (file) { + last = split(file, parts, "/") + currently_playing = parts[last] + } else { + currently_playing = "" + } return sprintf(\ "%s %s %s %s", symbol, - db["mpd_curr_song_time"], - db["mpd_curr_song_percent"], - substr(db["mpd_curr_song_name"], 1, opt_mpd_song_max_chars)\ + db["mpd_status_time"], + db["mpd_status_percent"], + substr(currently_playing, 1, opt_mpd_song_max_chars)\ ) }