From e15f57f2de007a4f0dc26a6cbc412228a227ad1d Mon Sep 17 00:00:00 2001 From: Chris Wood Date: Thu, 31 Jul 2014 17:26:18 -0400 Subject: [PATCH] Add filename tag to mpd module --- i3pystatus/mpd.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/i3pystatus/mpd.py b/i3pystatus/mpd.py index 0363c2b..83e7d4c 100644 --- a/i3pystatus/mpd.py +++ b/i3pystatus/mpd.py @@ -1,4 +1,5 @@ import socket +from os.path import basename from i3pystatus import IntervalModule, formatp from i3pystatus.core.util import TimeWrapper @@ -13,6 +14,7 @@ class MPD(IntervalModule): * `{title}` — (the title of the current song) * `{album}` — (the album of the current song, can be an empty string (e.g. for online streams)) * `{artist}` — (can be empty, too) + * `{filename}` — (empty unless title is empty) * `{song_elapsed}` — (Position in the currently playing song, uses `TimeWrapper`_, default is `%m:%S`) * `{song_length}` — (Length of the current song, same as song_elapsed) * `{pos}` — (Position of current song in playlist, one-based) @@ -79,7 +81,7 @@ class MPD(IntervalModule): "len": int(status["playlistlength"]), "status": self.status[status["state"]], "volume": int(status["volume"]), - + "title": currentsong.get("Title", ""), "album": currentsong.get("Album", ""), "artist": currentsong.get("Artist", ""), @@ -88,6 +90,11 @@ class MPD(IntervalModule): "bitrate": int(status.get("bitrate", 0)), } + if not fdict["title"]: + fdict["filename"] = '.'.join( + basename(currentsong["file"]).split('.')[:-1]) + else: + fdict["filename"] = "" self.output = { "full_text": formatp(self.format, **fdict).strip(), "color": self.color,