4 /^OK
/ {msg_count
++; next}
10 sub(".*" key
" *", "", val
)
13 # Note that we expect a particular order of response messages (also
14 # reflected in the name of this script file): "status" THEN "currentsong"
15 if (msg_count ==
1) {status
[key
] = val
}
16 else if (msg_count ==
2) {currentsong
[key
] = val
}
18 printf("Unexpected msg_count in mpd response: %d\n", msg_count
) \
26 name = currentsong
["name"]
27 title = currentsong
["title"]
28 file = currentsong
["file"]
35 last =
split(file
, parts
, "/")
41 format_time
(status
["time"], time
)
42 state_symbol = symbol_of_state
(status
["state"])
43 print("status", sprintf("%s %s %s", state_symbol
, time
["minimal_units"], time
["percentage"]))
46 function symbol_of_state
(state
) {
49 } else if (state =
"pause") {
51 } else if (state =
"stop") {
54 print("Error: unexpected value for state: ", state
) > "/dev/stderr"
59 function format_time
(time_str
, time_arr
, \
70 split(time_str
, time_str_parts
, ":")
71 seconds_current = time_str_parts
[1]
72 seconds_total = time_str_parts
[2]
74 hours = int
(seconds_current
/ 60 / 60);
75 secs_beyond_hours = seconds_current
- (hours
* 60 * 60);
76 mins = int
(secs_beyond_hours
/ 60);
77 secs = secs_beyond_hours
- (mins
* 60);
80 time_arr
["minimal_units"] =
sprintf("%d:%.2d:%.2d", hours
, mins
, secs
)
82 time_arr
["minimal_units"] =
sprintf("%.2d:%.2d", mins
, secs
)
85 if (seconds_total
> 0) {
86 time_percentage =
(seconds_current
/ seconds_total
) * 100
87 time_arr
["percentage"] =
sprintf("%d%%", time_percentage
)
89 time_arr
["percentage"] =
"~"