[widgets.mpd] Add fields `${Artists}` and `${Genres}`

This commit is contained in:
Cássio Ávila 2023-12-10 07:15:53 -03:00 committed by GitHub
parent 9435bfdf6d
commit 969d94255b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 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

@ -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