X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=bin%2Fkhatus_parse_mpd_status;fp=bin%2Fkhatus_parse_mpd_status;h=1088b4e9de14bca0a2d9d5191da4ed375610e3d6;hb=e7a3c6ab3cc5fd8c89a483789cde8d1ca623aaba;hp=0000000000000000000000000000000000000000;hpb=a9038fad36330d7dca12cfd4bef0147a7d312c0c;p=khatus.git diff --git a/bin/khatus_parse_mpd_status b/bin/khatus_parse_mpd_status new file mode 100755 index 0000000..1088b4e --- /dev/null +++ b/bin/khatus_parse_mpd_status @@ -0,0 +1,39 @@ +#! /usr/bin/awk -f + +# Msg BEGINs +/^OK MPD / { delete status; next} + +# Msg ENDs +/^OK$/ { + split(status["time"], 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 = "~" + } + + printf("%s %s %s\n", status["state"], current_time, current_percentage) + next +} + +# Msg content +/^[a-z]+: / { + sub(":$", "", $1) + status[$1] = $2 + next +}