From fb4daaaad6630d735f09134db71b8012226f53e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20=C3=81vila?= Date: Tue, 5 Dec 2023 21:56:26 -0300 Subject: [PATCH 1/7] Add option to display all generes and artists in mpd --- widgets/mpd_all.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index 60e323c..7f65cc9 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -125,12 +125,17 @@ function mpd_all.async(format, warg, callback) ["{Title}"] = "N/A", ["{Album}"] = "N/A", ["{Genre}"] = "N/A", - --["{Name}"] = "N/A", - --["{file}"] = "N/A", + ["{Artists}"] = "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 +149,23 @@ 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" then + local current_artists = mpd_state["{Artists}"] + if current_artists == "N/A" then + mpd_state["{Artists}"] = 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) + end + end mpd_state[key] = v end end From 0623f04b07fd8490716ca89a407cb4f0f7216c4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20=C3=81vila?= Date: Tue, 5 Dec 2023 22:05:10 -0300 Subject: [PATCH 2/7] Add documentation --- docs/source/widgets.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/source/widgets.rst b/docs/source/widgets.rst index f7098f4..20944b8 100644 --- a/docs/source/widgets.rst +++ b/docs/source/widgets.rst @@ -290,14 +290,16 @@ 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), + ``${Generes}`` (All generes concatenated with the configured separator), ``${Album}``, ``${Genre}`` and optionally ``${Name}`` and ``${file}``. In addition, some common mpd commands are available as functions: From 39061358cab0fe916f19238c342afa0b891bb4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20=C3=81vila?= Date: Tue, 5 Dec 2023 22:07:05 -0300 Subject: [PATCH 3/7] Add generes to the mpd_state table --- widgets/mpd_all.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index 7f65cc9..681cac8 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -122,10 +122,11 @@ 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", - ["{Artists}"] = "N/A", + ["{Genres}"] = "N/A", } local separator = warg and (warg.separator or warg[4]) or ", " From 157e0a4760c56c5eeeafd189de8f79070fb57725 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20=C3=81vila?= Date: Tue, 5 Dec 2023 22:18:26 -0300 Subject: [PATCH 4/7] Don't surpass 80 columns --- widgets/mpd_all.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index 681cac8..015ce4d 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -156,7 +156,8 @@ function mpd_all.async(format, warg, callback) if current_artists == "N/A" then mpd_state["{Artists}"] = v else - mpd_state["{Artists}"] = append_with_separator(current_artists, v) + mpd_state["{Artists}"] = append_with_separator( + current_artists, v) end end if k == "Genre" then @@ -164,7 +165,8 @@ function mpd_all.async(format, warg, callback) if current_generes == "N/A" then mpd_state["{Generes}"] = v else - mpd_state["{Generes}"] = append_with_separator(current_generes, v) + mpd_state["{Generes}"] = append_with_separator( + current_generes, v) end end mpd_state[key] = v From fdb2fa92b0688395271e96f69e3a78b0537e5fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20=C3=81vila?= Date: Wed, 6 Dec 2023 16:59:29 -0300 Subject: [PATCH 5/7] Add copyright --- widgets/mpd_all.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index 015ce4d..2417e98 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -6,6 +6,7 @@ -- Copyright (C) 2019 Juan Carlos Menonita -- Copyright (C) 2019 Lorenzo Gaggini -- Copyright (C) 2022 Constantin Piber +-- Copyright (C) 2023 Cássio Ávila -- -- This file is part of Vicious. -- From 648f33d059ab1af34436b9bf465738fc32b1d849 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20=C3=81vila?= Date: Thu, 7 Dec 2023 12:26:25 -0300 Subject: [PATCH 6/7] Simplify function and align table values --- widgets/mpd_all.lua | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/widgets/mpd_all.lua b/widgets/mpd_all.lua index 2417e98..79f17ed 100644 --- a/widgets/mpd_all.lua +++ b/widgets/mpd_all.lua @@ -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 From d1229cc6264cd11c2b6e04cb9fbbb162f08a7c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20=C3=81vila?= Date: Thu, 7 Dec 2023 12:36:30 -0300 Subject: [PATCH 7/7] Fix typos and formatting --- docs/source/widgets.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/source/widgets.rst b/docs/source/widgets.rst index 20944b8..571abe8 100644 --- a/docs/source/widgets.rst +++ b/docs/source/widgets.rst @@ -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: