Split workers into dedicated files
[khatus.git] / bin / khatus_sensor_mpd_state
1 #! /bin/sh
2
3 set -e
4
5 echo 'status' \
6 | nc 127.0.0.1 6600 \
7 | awk '
8 {
9 status[$1] = $2
10 }
11
12 /^time: +[0-9]+:[0-9]+$/ {
13 split($2, time, ":")
14 seconds_current = time[1]
15 seconds_total = time[2]
16
17 hours = int(seconds_current / 60 / 60);
18 secs_beyond_hours = seconds_current - (hours * 60 * 60);
19 mins = int(secs_beyond_hours / 60);
20 secs = secs_beyond_hours - (mins * 60);
21 if (hours > 0) {
22 current_time = sprintf("%d:%.2d:%.2d", hours, mins, secs)
23 } else {
24 current_time = sprintf("%.2d:%.2d", mins, secs)
25 }
26
27 if (seconds_total > 0) {
28 time_percentage = (seconds_current / seconds_total) * 100
29 current_percentage = sprintf("%d%%", time_percentage)
30 } else {
31 current_percentage = "~"
32 }
33 }
34
35 END {
36 state = status["state:"]
37
38 if (state == "play") {
39 symbol = "▶"
40 } else if (state == "pause") {
41 symbol = "❚❚"
42 } else if (state == "stop") {
43 symbol = "⬛"
44 } else {
45 symbol = "--"
46 }
47
48 printf(\
49 "%s %s %s\n",
50 status["state:"], current_time, current_percentage\
51 )
52 }
53 '
This page took 0.084623 seconds and 4 git commands to generate.