[mpd] Add playing progress percentage (#80)
This commit is contained in:
parent
60c57e8a41
commit
f37566b0af
|
@ -360,7 +360,7 @@ Supported platforms: platform independent (required tools: `curl`).
|
|||
fields will be fallen back to default (`localhost:6600` without password).
|
||||
* Returns a table with string keys: `${volume}`, `${bitrate}`, `${elapsed}` (in seconds),
|
||||
`${duration}` (in seconds), `${Elapsed}` (formatted as [hh:]mm:ss), `${Duration}` (formatted as [hh:]mm:ss),
|
||||
`${random}`, `${repeat}`, `${state}`, `${Artist}`, `${Title}`, `${Album}`,
|
||||
`${Progress}` (in percentage), ${random}`, `${repeat}`, `${state}`, `${Artist}`, `${Title}`, `${Album}`,
|
||||
`${Genre}` and optionally `${Name}` and `${file}`.
|
||||
|
||||
### vicious.widgets.net
|
||||
|
|
|
@ -43,6 +43,16 @@ function format_progress(elapsed, duration)
|
|||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ Format playing progress (percentage)
|
||||
function format_progress_percentage(elapsed, duration)
|
||||
if duration > 0 then
|
||||
local percentage = math.floor((elapsed / duration) * 100 + 0.5)
|
||||
return ("%d%%"):format(percentage)
|
||||
else
|
||||
return("0%")
|
||||
end
|
||||
-- }}}
|
||||
|
||||
-- {{{ MPD widget type
|
||||
local function worker(format, warg)
|
||||
-- Fallback values
|
||||
|
@ -94,6 +104,10 @@ local function worker(format, warg)
|
|||
mpd_state["{Elapsed}"], mpd_state["{Duration}"] = format_progress(
|
||||
mpd_state["{elapsed}"], mpd_state["{duration}"])
|
||||
|
||||
-- Formatted playing progress percentage
|
||||
mpd_state["{Progress}"] = format_progress_percentage(
|
||||
mpd_state["{elapsed}"], mpd_state["{duration}"])
|
||||
|
||||
return mpd_state
|
||||
end
|
||||
-- }}}
|
||||
|
|
Loading…
Reference in New Issue