From 61e5a3512974373477990271414d5fd2c73e7e34 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Sun, 29 Jul 2018 15:48:49 -0400 Subject: [PATCH] Add volume data --- bin/khatus_loop | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bin/khatus_loop b/bin/khatus_loop index e5174c5..bc1e1a7 100755 --- a/bin/khatus_loop +++ b/bin/khatus_loop @@ -1,5 +1,28 @@ #! /bin/bash +produce_volume() { + pactl list sinks \ + | awk ' + /^\tMute:/ { + printf("%s,", $0); + } + /^\tVolume:/ { + for (i=2; i<=NF; i++) printf(" %s", $i); + }' \ + | awk -v RS=',' ' + /^[ \t]*Mute:/ {mute = $2} + /^[ \t]*front-left:/ {left = $4} + /^[ \t]*front-right:/ {right = $4} + END { + if (mute == "yes") { + printf("x") + } else { + printf("%s %s", left, right) + } + } + ' +} + produce_mpd_state() { echo 'status' \ | nc 127.0.0.1 6600 \ @@ -119,6 +142,12 @@ consume() { -v opt_debug=0 \ -v opt_mpd_song_max_chars=10 \ ' + /^in:VOLUME/\ + { + split_msg_parts() + db["volume"] = msg_body + } + /^in:MPD_STATE/\ { split_msg_parts() @@ -160,6 +189,7 @@ consume() { } function make_bar( position, bar, sep, i, j) { + position[++i] = sprintf("(%s)", db["volume"]) position[++i] = make_status_mpd() position[++i] = db["weather_temperature"] position[++i] = db["datetime"] @@ -243,6 +273,7 @@ main() { spawn produce_weather "$pipe" 'in:WEATHER' $(( 30 * 60 )) spawn produce_mpd_state "$pipe" 'in:MPD_STATE' 1 spawn produce_mpd_song "$pipe" 'in:MPD_SONG' 1 + spawn produce_volume "$pipe" 'in:VOLUME' 1 spawn produce_bar_req "$pipe" 'out:BAR' 1 consume "$pipe" } -- 2.20.1