From: Siraaj Khandkar Date: Tue, 3 Jul 2018 22:07:30 +0000 (-0400) Subject: Use "Name:" field if it is available X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=a6f613874dbc5f2462ada2b265006cb57e40749b;p=khatus.git Use "Name:" field if it is available like in SomaFM streams, otherwise fallback on "file:" --- diff --git a/bin/khatus_show b/bin/khatus_show index c0a41a1..537475b 100755 --- a/bin/khatus_show +++ b/bin/khatus_show @@ -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\ \