Merge pull request #139 from Arvedui/mpd_text_len

mpd text length
This commit is contained in:
enkore 2014-11-07 11:10:07 +01:00
commit 43e9b49396

View File

@ -34,6 +34,8 @@ class MPD(IntervalModule):
("format", "formatp string"), ("format", "formatp string"),
("status", "Dictionary mapping pause, play and stop to output"), ("status", "Dictionary mapping pause, play and stop to output"),
("color", "The color of the text"), ("color", "The color of the text"),
("text_len", "Defines max length for title, album and artist, if truncated ellipsis are appended as indicator"),
("truncate_fields", "fileds that will be truncated if exceeding text_len"),
) )
host = "localhost" host = "localhost"
@ -46,6 +48,8 @@ class MPD(IntervalModule):
"stop": "", "stop": "",
} }
color = "#FFFFFF" color = "#FFFFFF"
text_len = 25
truncate_fields = ("title", "album", "artist")
def _mpd_command(self, sock, command): def _mpd_command(self, sock, command):
try: try:
@ -82,6 +86,11 @@ class MPD(IntervalModule):
"bitrate": int(status.get("bitrate", 0)), "bitrate": int(status.get("bitrate", 0)),
} }
for key in self.truncate_fields:
if len(fdict[key]) > self.text_len:
fdict[key] = fdict[key][:self.text_len - 1] + ""
if not fdict["title"] and "filename" in fdict: if not fdict["title"] and "filename" in fdict:
fdict["filename"] = '.'.join( fdict["filename"] = '.'.join(
basename(currentsong["file"]).split('.')[:-1]) basename(currentsong["file"]).split('.')[:-1])