Include more info in mpd song change alert
authorSiraaj Khandkar <siraaj@khandkar.net>
Wed, 1 Aug 2018 05:36:14 +0000 (01:36 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Wed, 1 Aug 2018 05:40:40 +0000 (01:40 -0400)
bin/khatus_controller

index a3b97c7..d7f627c 100755 (executable)
     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()
-    fields_shift()
-    db["mpd_song_curr_file"] = $0
-}
-
-/^in:MPD_SONG +Title:/\
-{
-    fields_shift()
-    fields_shift()
-    db["mpd_song_curr_title"] = $0
-}
-
-/^in:MPD_SONG +Name:/\
-{
-    fields_shift()
-    fields_shift()
-    db["mpd_song_curr_name"] = $0
-}
-
-/^in:MPD_SONG +OK$/\
-{
-    set_mpd_playing()
-}
-# END MPD_SONG
-# -----------------------------------------------------------------------------
+/^in:MPD_SONG OK +MPD/ { delete db_mpd_song; next }
+/^in:MPD_SONG OK$/     { set_mpd_playing() ; next }
+/^in:MPD_SONG /        { set_mpd_song()    ; next }
 
 /^in:MPD_STATE /\
 {
     output_msg_status_bar(make_status_bar())
 }
 
+function set_mpd_song(    key, val) {
+    key = $2
+    fields_shift()
+    fields_shift()
+    val = $0
+    db_mpd_song[key] = val
+    debug("set_mpd_song", db_mpd_song)
+}
+
 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"]
+    debug("set_mpd_playing", db_mpd_song)
+    name  = db_mpd_song["Name:"]
+    title = db_mpd_song["Title:"]
+    file  = db_mpd_song["file:"]
 
     if (name) {
         currently_playing = name
@@ -171,11 +148,20 @@ function set_mpd_playing(    \
     alert_check_mpd()
 }
 
-function alert_check_mpd(    curr, prev) {
+function alert_check_mpd(    curr, prev, name, body) {
     prev = db["mpd_playing_prev"]
     curr = db["mpd_playing_curr"]
     if (curr && curr != prev) {
-        alert_trigger_low("alert_check_mpd", "NowPlaying", curr)
+        name = db_mpd_song["Name:"]
+        if (name) {
+            body = name
+        } else {
+            body = \
+                      db_mpd_song["Artist:"] \
+                " - " db_mpd_song["Album:"] \
+                " - " db_mpd_song["Title:"]
+        }
+        alert_trigger_low("alert_check_mpd", "NowPlaying", body)
     }
 }
 
This page took 0.028702 seconds and 4 git commands to generate.