Compare commits

...

4 Commits

Author SHA1 Message Date
Daniel Hahler 75725de146
Merge 9301e186ef into 969d94255b 2023-12-12 05:32:06 -07:00
Cássio Ávila 969d94255b
[widgets.mpd] Add fields `${Artists}` and `${Genres}` 2023-12-10 10:15:53 +00:00
Daniel Hahler 9301e186ef s/timer/timeout, return cur 2021-03-19 08:36:29 +01:00
Daniel Hahler f25866f4e5 Add vicious.change_timer: a helper to change the timeout
This is useful in case you want to change the timeout value for a
registered widget, e.g. from the format callback function.

I am using this to have a shorter timeout interval for the temperature
widget when its value is above some threshold.

Signed-off-by: Daniel Hahler <git@thequod.de>
2021-03-18 14:06:23 +01:00
3 changed files with 37 additions and 5 deletions

View File

@ -290,14 +290,17 @@ Provides Music Player Daemon information.
Supported platforms: platform independent (required tools: ``curl``).
* Argument: an array including password, hostname and port in that order.
* Argument: an array including password, hostname, port and separator in that
order, or a table with the previously mentioned fields.
``nil`` fields will be fallen back to default
(``localhost:6600`` without password).
(``localhost:6600`` without password and ``", "`` as a separator).
* 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), ``${Progress}`` (in percentage),
``${random}``, ``${repeat}``, ``${state}``, ``${Artist}``, ``${Title}``,
``${Artists}`` (all artists concatenated with the configured separator),
``${Genres}`` (all genres concatenated with the configured separator),
``${Album}``, ``${Genre}`` and optionally ``${Name}`` and ``${file}``.
In addition, some common mpd commands are available as functions:

View File

@ -362,5 +362,18 @@ function vicious.call_async(wtype, format, warg, callback)
end
-- }}}
-- {{{ Change the timer of a registered widget.
function vicious.change_timer(reg, timeout)
if not reg then return end
local cur = reg.timeout
if timeout ~= cur then
vicious.unregister(nil, true, reg)
reg.timeout = timeout
regregister(reg)
end
return cur
end
-- }}}
return vicious
-- }}}

View File

@ -6,6 +6,7 @@
-- Copyright (C) 2019 Juan Carlos Menonita <JuanKman94@users.noreply.github.com>
-- Copyright (C) 2019 Lorenzo Gaggini <lg@lgaggini.net>
-- Copyright (C) 2022 Constantin Piber <cp.piber@gmail.com>
-- Copyright (C) 2023 Cássio Ávila <cassioavila@autistici.org>
--
-- This file is part of Vicious.
--
@ -122,15 +123,21 @@ function mpd_all.async(format, warg, callback)
["{random}"] = 0,
["{state}"] = "N/A",
["{Artist}"] = "N/A",
["{Artists}"] = "N/A",
["{Title}"] = "N/A",
["{Album}"] = "N/A",
["{Genre}"] = "N/A",
--["{Name}"] = "N/A",
--["{file}"] = "N/A",
["{Genres}"] = "N/A",
}
local separator = warg and (warg.separator or warg[4]) or ", "
local cmd = build_cmd(warg, "status\ncurrentsong\n")
local function append_with_separator (current, value)
return ("%s%s%s"):format(current, separator, value)
end
-- Get data from MPD server
spawn.with_line_callback_with_shell(cmd, {
stdout = function (line)
@ -144,8 +151,17 @@ function mpd_all.async(format, warg, callback)
elseif k == "state" then
mpd_state[key] = helpers.capitalize(v)
elseif k == "Artist" or k == "Title" or
--k == "Name" or k == "file" or
k == "Album" or k == "Genre" then
if k == "Artist" or k == "Genre" then
local current_key = "{" .. k .. "s}"
local current_state = mpd_state[current_key]
if current_state == "N/A" then
mpd_state[current_key] = v
else
mpd_state[current_key] = append_with_separator(
current_state, v)
end
end
mpd_state[key] = v
end
end