[widgets.mpd] Add fields `${Artists}` and `${Genres}`
This commit is contained in:
parent
9435bfdf6d
commit
969d94255b
|
@ -290,14 +290,17 @@ Provides Music Player Daemon information.
|
||||||
|
|
||||||
Supported platforms: platform independent (required tools: ``curl``).
|
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
|
``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}``,
|
* Returns a table with string keys: ``${volume}``, ``${bitrate}``,
|
||||||
``${elapsed}`` (in seconds), ``${duration}`` (in seconds),
|
``${elapsed}`` (in seconds), ``${duration}`` (in seconds),
|
||||||
``${Elapsed}`` (formatted as [hh:]mm:ss),
|
``${Elapsed}`` (formatted as [hh:]mm:ss),
|
||||||
``${Duration}`` (formatted as [hh:]mm:ss), ``${Progress}`` (in percentage),
|
``${Duration}`` (formatted as [hh:]mm:ss), ``${Progress}`` (in percentage),
|
||||||
``${random}``, ``${repeat}``, ``${state}``, ``${Artist}``, ``${Title}``,
|
``${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}``.
|
``${Album}``, ``${Genre}`` and optionally ``${Name}`` and ``${file}``.
|
||||||
|
|
||||||
In addition, some common mpd commands are available as functions:
|
In addition, some common mpd commands are available as functions:
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
-- Copyright (C) 2019 Juan Carlos Menonita <JuanKman94@users.noreply.github.com>
|
-- Copyright (C) 2019 Juan Carlos Menonita <JuanKman94@users.noreply.github.com>
|
||||||
-- Copyright (C) 2019 Lorenzo Gaggini <lg@lgaggini.net>
|
-- Copyright (C) 2019 Lorenzo Gaggini <lg@lgaggini.net>
|
||||||
-- Copyright (C) 2022 Constantin Piber <cp.piber@gmail.com>
|
-- Copyright (C) 2022 Constantin Piber <cp.piber@gmail.com>
|
||||||
|
-- Copyright (C) 2023 Cássio Ávila <cassioavila@autistici.org>
|
||||||
--
|
--
|
||||||
-- This file is part of Vicious.
|
-- This file is part of Vicious.
|
||||||
--
|
--
|
||||||
|
@ -122,15 +123,21 @@ function mpd_all.async(format, warg, callback)
|
||||||
["{random}"] = 0,
|
["{random}"] = 0,
|
||||||
["{state}"] = "N/A",
|
["{state}"] = "N/A",
|
||||||
["{Artist}"] = "N/A",
|
["{Artist}"] = "N/A",
|
||||||
|
["{Artists}"] = "N/A",
|
||||||
["{Title}"] = "N/A",
|
["{Title}"] = "N/A",
|
||||||
["{Album}"] = "N/A",
|
["{Album}"] = "N/A",
|
||||||
["{Genre}"] = "N/A",
|
["{Genre}"] = "N/A",
|
||||||
--["{Name}"] = "N/A",
|
["{Genres}"] = "N/A",
|
||||||
--["{file}"] = "N/A",
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local separator = warg and (warg.separator or warg[4]) or ", "
|
||||||
|
|
||||||
local cmd = build_cmd(warg, "status\ncurrentsong\n")
|
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
|
-- Get data from MPD server
|
||||||
spawn.with_line_callback_with_shell(cmd, {
|
spawn.with_line_callback_with_shell(cmd, {
|
||||||
stdout = function (line)
|
stdout = function (line)
|
||||||
|
@ -144,8 +151,17 @@ function mpd_all.async(format, warg, callback)
|
||||||
elseif k == "state" then
|
elseif k == "state" then
|
||||||
mpd_state[key] = helpers.capitalize(v)
|
mpd_state[key] = helpers.capitalize(v)
|
||||||
elseif k == "Artist" or k == "Title" or
|
elseif k == "Artist" or k == "Title" or
|
||||||
--k == "Name" or k == "file" or
|
|
||||||
k == "Album" or k == "Genre" then
|
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
|
mpd_state[key] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue