From cd51cd511c6686c2791db031d42ca893cd804bf8 Mon Sep 17 00:00:00 2001 From: James Walker Date: Tue, 31 Dec 2024 18:35:48 +0000 Subject: [PATCH 1/3] Implement track number support for mpris module Adds a new {trackno} format placeholder that returns the current track number value Uses the xesam:tracknumber metadata attribute, which works with VLC --- py3status/modules/mpris.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/py3status/modules/mpris.py b/py3status/modules/mpris.py index f154f47bfa..f2883b30a4 100644 --- a/py3status/modules/mpris.py +++ b/py3status/modules/mpris.py @@ -40,6 +40,7 @@ {state} playback status of the player {time} played time of the song {title} name of the song + {trackno} track number of the song {nowplaying} now playing field provided by VLC for stream info Button placeholders: @@ -278,6 +279,10 @@ def metadata(self, metadata=None): self._metadata["length"] = self._get_time_str(metadata.get(Metadata_Map.LENGTH)) + # we are converting the attribute name to lowercase because although the spec + # says it's `xesam:trackNumber`, VLC exposes it as `xesam:tracknumber` + self._metadata["trackno"] = metadata.get(Metadata_Map.TRACK_NUMBER.lower()); + self._metadata["nowplaying"] = metadata.get("vlc:nowplaying", None) if not self._metadata.get("title"): @@ -407,6 +412,7 @@ def post_config_hook(self): "artist": None, "length": None, "title": None, + "trackno": None, "nowplaying": None, "time": None, "state": None, @@ -477,7 +483,7 @@ def post_config_hook(self): self._color_inactive = self.py3.COLOR_CONTROL_INACTIVE or self.py3.COLOR_BAD self._format_contains_metadata = False - self._metadata_keys = ["album", "artist", "title", "nowplaying", "length"] + self._metadata_keys = ["album", "artist", "title", "nowplaying", "length", "trackno"] for key in self._metadata_keys: if self.py3.format_contains(self.format, key): self._format_contains_metadata = True From c6a820653d6ba23531fbe316be75996284ed8706 Mon Sep 17 00:00:00 2001 From: James Walker Date: Thu, 2 Jan 2025 18:03:55 +0000 Subject: [PATCH 2/3] Change mpris trackno format placeholder to tracknumber --- py3status/modules/mpris.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/py3status/modules/mpris.py b/py3status/modules/mpris.py index f2883b30a4..514394db36 100644 --- a/py3status/modules/mpris.py +++ b/py3status/modules/mpris.py @@ -40,7 +40,7 @@ {state} playback status of the player {time} played time of the song {title} name of the song - {trackno} track number of the song + {tracknumber} track number of the song {nowplaying} now playing field provided by VLC for stream info Button placeholders: @@ -281,7 +281,7 @@ def metadata(self, metadata=None): # we are converting the attribute name to lowercase because although the spec # says it's `xesam:trackNumber`, VLC exposes it as `xesam:tracknumber` - self._metadata["trackno"] = metadata.get(Metadata_Map.TRACK_NUMBER.lower()); + self._metadata["tracknumber"] = metadata.get(Metadata_Map.TRACK_NUMBER.lower()); self._metadata["nowplaying"] = metadata.get("vlc:nowplaying", None) @@ -412,7 +412,7 @@ def post_config_hook(self): "artist": None, "length": None, "title": None, - "trackno": None, + "tracknumber": None, "nowplaying": None, "time": None, "state": None, @@ -483,7 +483,7 @@ def post_config_hook(self): self._color_inactive = self.py3.COLOR_CONTROL_INACTIVE or self.py3.COLOR_BAD self._format_contains_metadata = False - self._metadata_keys = ["album", "artist", "title", "nowplaying", "length", "trackno"] + self._metadata_keys = ["album", "artist", "title", "nowplaying", "length", "tracknumber"] for key in self._metadata_keys: if self.py3.format_contains(self.format, key): self._format_contains_metadata = True From e5f2ebbebe25d8ab577178eb50676e77066da7b5 Mon Sep 17 00:00:00 2001 From: James Walker Date: Tue, 21 Jan 2025 15:41:32 +0000 Subject: [PATCH 3/3] Fix incorrect formatting in mpris.py --- py3status/modules/mpris.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py3status/modules/mpris.py b/py3status/modules/mpris.py index 514394db36..844ece90db 100644 --- a/py3status/modules/mpris.py +++ b/py3status/modules/mpris.py @@ -279,9 +279,9 @@ def metadata(self, metadata=None): self._metadata["length"] = self._get_time_str(metadata.get(Metadata_Map.LENGTH)) - # we are converting the attribute name to lowercase because although the spec + # we are converting the attribute name to lowercase because although the spec # says it's `xesam:trackNumber`, VLC exposes it as `xesam:tracknumber` - self._metadata["tracknumber"] = metadata.get(Metadata_Map.TRACK_NUMBER.lower()); + self._metadata["tracknumber"] = metadata.get(Metadata_Map.TRACK_NUMBER.lower()) self._metadata["nowplaying"] = metadata.get("vlc:nowplaying", None)