diff --git a/README.md b/README.md index bf3838c..d8ff255 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index c419dbc..ca04449 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -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 -- }}}