From f5dfebd2b3df7a959357a2eb02706ae45d7a1d49 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Wed, 1 Aug 2018 00:35:13 -0400 Subject: [PATCH] Add alert - mpd song change --- bin/khatus_controller | 68 +++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/bin/khatus_controller b/bin/khatus_controller index ae4a8dc..836a915 100755 --- a/bin/khatus_controller +++ b/bin/khatus_controller @@ -90,6 +90,15 @@ db["volume"] = $0 } +# ----------------------------------------------------------------------------- +# BEGIN MPD_SONG +/^in:MPD_SONG +OK +/\ +{ + delete db["mpd_song_curr_file"] + delete db["mpd_song_curr_title"] + delete db["mpd_song_curr_name"] +} + /^in:MPD_SONG +file:/\ { fields_shift() @@ -103,6 +112,7 @@ fields_shift() db["mpd_song_curr_title"] = $0 } + /^in:MPD_SONG +Name:/\ { fields_shift() @@ -110,6 +120,13 @@ db["mpd_song_curr_name"] = $0 } +/^in:MPD_SONG +OK$/\ +{ + set_mpd_playing() +} +# END MPD_SONG +# ----------------------------------------------------------------------------- + /^in:MPD_STATE /\ { fields_shift() @@ -131,6 +148,37 @@ output_msg_status_bar(make_status_bar()) } +function set_mpd_playing( \ + currently_playing, name, title, file, last, parts\ +) { + 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 = "" + } + db["mpd_playing_prev"] = db["mpd_playing_curr"] + db["mpd_playing_curr"] = currently_playing + + alert_check_mpd() +} + +function alert_check_mpd( curr, prev) { + prev = db["mpd_playing_prev"] + curr = db["mpd_playing_curr"] + if (curr != prev) { + alert_trigger_low("alert_check_mpd", "NowPlaying", curr) + } +} + # TODO: Generalize alert spec lang # - trigger threshold # - above/bellow/equal to threshold value @@ -408,29 +456,13 @@ function make_status_mpd( state, status) { return sprintf("[%s]", status) } -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 = "" - } +function make_status_mpd_state_known(symbol) { return sprintf(\ "%s %s %s %s", symbol, db["mpd_status_time"], db["mpd_status_percent"], - substr(currently_playing, 1, opt_mpd_song_max_chars)\ + substr(db["mpd_playing_curr"], 1, opt_mpd_song_max_chars)\ ) } -- 2.20.1