Fixed various issues in now_playing

This commit is contained in:
enkore 2014-08-04 03:05:43 +02:00
parent e639335152
commit 5c2af069af

View File

@ -57,6 +57,8 @@ class NowPlaying(IntervalModule):
players = [a for a in dbus.SessionBus().get_object("org.freedesktop.DBus", "/org/freedesktop/DBus").ListNames() if a.startswith("org.mpris.MediaPlayer2.")] players = [a for a in dbus.SessionBus().get_object("org.freedesktop.DBus", "/org/freedesktop/DBus").ListNames() if a.startswith("org.mpris.MediaPlayer2.")]
if self.old_player in players: if self.old_player in players:
return self.old_player return self.old_player
if not players:
raise dbus.exceptions.DBusException()
self.old_player = players[0] self.old_player = players[0]
return players[0] return players[0]
@ -90,14 +92,14 @@ class NowPlaying(IntervalModule):
"title":currentsong.get("xesam:title", ""), "title":currentsong.get("xesam:title", ""),
"album": currentsong.get("xesam:album", ""), "album": currentsong.get("xesam:album", ""),
"artist": ", ".join(currentsong.get("xesam:artist", "")), "artist": ", ".join(currentsong.get("xesam:artist", "")),
"song_length": TimeWrapper(currentsong.get("mpris:length") / 1000**2), "song_length": TimeWrapper((currentsong.get("mpris:length") or 0) / 1000**2),
"song_elapsed": TimeWrapper(get_prop("Position") / 1000**2), "song_elapsed": TimeWrapper((get_prop("Position") or 0) / 1000**2),
"filename": "", "filename": "",
} }
if not fdict["title"]: if not fdict["title"]:
fdict["filename"] = '.'.join( fdict["filename"] = '.'.join(
basename(currentsong["xesam:url"]).split('.')[:-1]) basename((currentsong.get("xesam:url") or "")).split('.')[:-1])
self.output = { self.output = {
"full_text": formatp(self.format, **fdict).strip(), "full_text": formatp(self.format, **fdict).strip(),