Skip to content

Commit

Permalink
Implement track number support for mpris module
Browse files Browse the repository at this point in the history
Adds a new {trackno} format placeholder that returns the current track number value

Uses the xesam:tracknumber metadata attribute, which works with VLC
  • Loading branch information
ilmiont authored Dec 31, 2024
1 parent 5d73d00 commit cd51cd5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion py3status/modules/mpris.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -407,6 +412,7 @@ def post_config_hook(self):
"artist": None,
"length": None,
"title": None,
"trackno": None,
"nowplaying": None,
"time": None,
"state": None,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cd51cd5

Please sign in to comment.