2 /^OK
/ {msg_count
++; next}
8 sub(".*" key
" *", "", val
)
11 # Note that we expect a particular order of response messages (also
12 # reflected in the name of this script file): "status" THEN "currentsong"
13 if (msg_count ==
1) {status
[key
] = val
}
14 else if (msg_count ==
2) {currentsong
[key
] = val
}
16 printf("Unexpected msg_count in mpd response: %d\n", msg_count
) \
24 name = currentsong
["name"]
25 title = currentsong
["title"]
26 file = currentsong
["file"]
33 last =
split(file
, parts
, "/")
39 format_time
(status
["time"], time
)
40 output
["play_time_minimal_units"] = time
["minimal_units"]
41 output
["play_time_percentage"] = time
["percentage"]
42 output
["state"] = status
["state"]
45 print(key
, output
[key
])
49 function format_time
(time_str
, time_arr
, \
60 split(time_str
, time_str_parts
, ":")
61 seconds_current = time_str_parts
[1]
62 seconds_total = time_str_parts
[2]
64 hours = int
(seconds_current
/ 60 / 60);
65 secs_beyond_hours = seconds_current
- (hours
* 60 * 60);
66 mins = int
(secs_beyond_hours
/ 60);
67 secs = secs_beyond_hours
- (mins
* 60);
70 time_arr
["minimal_units"] =
sprintf("%d:%.2d:%.2d", hours
, mins
, secs
)
72 time_arr
["minimal_units"] =
sprintf("%.2d:%.2d", mins
, secs
)
75 if (seconds_total
> 0) {
76 time_percentage =
(seconds_current
/ seconds_total
) * 100
77 time_arr
["percentage"] =
sprintf("%d%%", time_percentage
)
79 time_arr
["percentage"] =
"~"