Compare commits

...

2 Commits

Author SHA1 Message Date
Cássio Ávila d1229cc626 Fix typos and formatting 2023-12-07 12:36:30 -03:00
Cássio Ávila 648f33d059 Simplify function and align table values 2023-12-07 12:26:25 -03:00
2 changed files with 13 additions and 20 deletions

View File

@ -290,7 +290,8 @@ Provides Music Player Daemon information.
Supported platforms: platform independent (required tools: ``curl``).
* Argument: an array including password, hostname, port and separator in that order, or a table with the previously mentioned fields.
* 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 and ``", "`` as a separator).
* Returns a table with string keys: ``${volume}``, ``${bitrate}``,
@ -298,8 +299,8 @@ Supported platforms: platform independent (required tools: ``curl``).
``${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),
``${Generes}`` (All generes concatenated with the configured separator),
``${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

@ -123,11 +123,11 @@ function mpd_all.async(format, warg, callback)
["{random}"] = 0,
["{state}"] = "N/A",
["{Artist}"] = "N/A",
["{Artists}"] = "N/A",
["{Artists}"] = "N/A",
["{Title}"] = "N/A",
["{Album}"] = "N/A",
["{Genre}"] = "N/A",
["{Genres}"] = "N/A",
["{Genres}"] = "N/A",
}
local separator = warg and (warg.separator or warg[4]) or ", "
@ -152,22 +152,14 @@ function mpd_all.async(format, warg, callback)
mpd_state[key] = helpers.capitalize(v)
elseif k == "Artist" or k == "Title" or
k == "Album" or k == "Genre" then
if k == "Artist" then
local current_artists = mpd_state["{Artists}"]
if current_artists == "N/A" then
mpd_state["{Artists}"] = v
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["{Artists}"] = append_with_separator(
current_artists, v)
end
end
if k == "Genre" then
local current_generes = mpd_state["{Generes}"]
if current_generes == "N/A" then
mpd_state["{Generes}"] = v
else
mpd_state["{Generes}"] = append_with_separator(
current_generes, v)
mpd_state[current_key] = append_with_separator(
current_state, v)
end
end
mpd_state[key] = v