X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=bin%2Fkhatus_sensor_mpd_state;h=20cc49af0da6151e5621c32a4c30c0cf97ac8d02;hb=d33e965674f4ce5c5f4011445a77e2664798ae08;hp=b5c9b088d5fe0d811ebe7a7b033b0949238c3800;hpb=f37162a4803ea6318e3620b6deccd8659316f31d;p=khatus.git diff --git a/bin/khatus_sensor_mpd_state b/bin/khatus_sensor_mpd_state index b5c9b08..20cc49a 100755 --- a/bin/khatus_sensor_mpd_state +++ b/bin/khatus_sensor_mpd_state @@ -2,52 +2,8 @@ set -e +dir_bin="$1" + echo 'status' \ | nc 127.0.0.1 6600 \ -| awk ' - { - status[$1] = $2 - } - - /^time: +[0-9]+:[0-9]+$/ { - split($2, time, ":") - seconds_current = time[1] - seconds_total = time[2] - - hours = int(seconds_current / 60 / 60); - secs_beyond_hours = seconds_current - (hours * 60 * 60); - mins = int(secs_beyond_hours / 60); - secs = secs_beyond_hours - (mins * 60); - if (hours > 0) { - current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs) - } else { - current_time = sprintf("%.2d:%.2d", mins, secs) - } - - if (seconds_total > 0) { - time_percentage = (seconds_current / seconds_total) * 100 - current_percentage = sprintf("%d%%", time_percentage) - } else { - current_percentage = "~" - } - } - - END { - state = status["state:"] - - if (state == "play") { - symbol = "▶" - } else if (state == "pause") { - symbol = "❚❚" - } else if (state == "stop") { - symbol = "⬛" - } else { - symbol = "--" - } - - printf(\ - "%s %s %s\n", - status["state:"], current_time, current_percentage\ - ) - } - ' +| "$dir_bin"/khatus_parse_mpd_status