Use "Name:" field if it is available
authorSiraaj Khandkar <siraaj@khandkar.net>
Tue, 3 Jul 2018 22:07:30 +0000 (18:07 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Tue, 3 Jul 2018 22:07:30 +0000 (18:07 -0400)
like in SomaFM streams, otherwise fallback on "file:"

bin/khatus_show

index c0a41a1..537475b 100755 (executable)
@@ -342,15 +342,30 @@ mpd_state=$(
         '
 )
 
-mpd_current_file=$(
+mpd_current=$(
     echo 'currentsong' \
     | nc 127.0.0.1 6600 \
     | awk -v max_chars=10 '
-        /^file:/ {
-            file = $2
-            for (i=3; i<=NF; i++) {file = file " " $i}
-            last = split(file, parts, "/")
-            print substr(parts[last], 1, max_chars)
+        /^OK/ {
+            next
+        }
+
+        {
+            key = $1
+            val = $2
+            for (i=3; i<=NF; i++) {val = val " " $i}
+            data[key] = val
+        }
+
+        END {
+            if (data["Name:"]) {
+                out = data["Name:"]
+            } else {
+                file = data["file:"]
+                last = split(file, parts, "/")
+                out = parts[last]
+            }
+            printf("%s", substr(out, 1, max_chars))
         }
         '
 )
@@ -401,7 +416,7 @@ echo \
  \
  V=$volume\
  \
- [$mpd_state $mpd_current_file]\
+ [$mpd_state $mpd_current]\
  \
  $signal_last_msg_age\
  \
This page took 0.028121 seconds and 4 git commands to generate.