4 OFS = msg_fs ? msg_fs
: "|"
5 Kfs = key_fs ? key_fs
: ":"
9 /^OK
/ {msg_count
++; next}
15 sub(".*" key
" *", "", val
)
18 # Note that we expect a particular order of response messages (also
19 # reflected in the name of this script file): "status" THEN "currentsong"
20 if (msg_count ==
1) {status
[key
] = val
}
21 else if (msg_count ==
2) {currentsong
[key
] = val
}
23 printf("Unexpected msg_count in mpd response: %d\n", msg_count
) \
31 name = currentsong
["name"]
32 title = currentsong
["title"]
33 file = currentsong
["file"]
40 last =
split(file
, parts
, "/")
46 format_time
(status
["time"], time
)
47 output
["play_time_minimal_units"] = time
["minimal_units"]
48 output
["play_time_percentage"] = time
["percentage"]
49 output
["state"] = status
["state"]
52 print(key
, output
[key
])
56 function format_time
(time_str
, time_arr
, \
67 split(time_str
, time_str_parts
, ":")
68 seconds_current = time_str_parts
[1]
69 seconds_total = time_str_parts
[2]
71 hours = int
(seconds_current
/ 60 / 60);
72 secs_beyond_hours = seconds_current
- (hours
* 60 * 60);
73 mins = int
(secs_beyond_hours
/ 60);
74 secs = secs_beyond_hours
- (mins
* 60);
77 time_arr
["minimal_units"] =
sprintf("%d:%.2d:%.2d", hours
, mins
, secs
)
79 time_arr
["minimal_units"] =
sprintf("%.2d:%.2d", mins
, secs
)
82 if (seconds_total
> 0) {
83 time_percentage =
(seconds_current
/ seconds_total
) * 100
84 time_arr
["percentage"] =
sprintf("%d%%", time_percentage
)
86 time_arr
["percentage"] =
"~"