| 1 | #! /usr/bin/awk -f |
| 2 | |
| 3 | # Msg BEGINs |
| 4 | /^OK MPD / { delete status; next} |
| 5 | |
| 6 | # Msg ENDs |
| 7 | /^OK$/ { |
| 8 | split(status["time"], time, ":") |
| 9 | seconds_current = time[1] |
| 10 | seconds_total = time[2] |
| 11 | |
| 12 | hours = int(seconds_current / 60 / 60); |
| 13 | secs_beyond_hours = seconds_current - (hours * 60 * 60); |
| 14 | mins = int(secs_beyond_hours / 60); |
| 15 | secs = secs_beyond_hours - (mins * 60); |
| 16 | |
| 17 | if (hours > 0) { |
| 18 | current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs) |
| 19 | } else { |
| 20 | current_time = sprintf("%.2d:%.2d", mins, secs) |
| 21 | } |
| 22 | |
| 23 | if (seconds_total > 0) { |
| 24 | time_percentage = (seconds_current / seconds_total) * 100 |
| 25 | current_percentage = sprintf("%d%%", time_percentage) |
| 26 | } else { |
| 27 | current_percentage = "~" |
| 28 | } |
| 29 | |
| 30 | printf("%s %s %s\n", status["state"], current_time, current_percentage) |
| 31 | next |
| 32 | } |
| 33 | |
| 34 | # Msg content |
| 35 | /^[a-z]+: / { |
| 36 | sub(":$", "", $1) |
| 37 | status[$1] = $2 |
| 38 | next |
| 39 | } |