From be83476aef89f7bd30b228c48d93eee6c62d3029 Mon Sep 17 00:00:00 2001 From: Jo De Boeck Date: Sun, 3 Apr 2016 15:49:37 +0200 Subject: [PATCH] Now playing: be more tolerant for mpris properties Some mpris clients dont implement all properties --- i3pystatus/now_playing.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/i3pystatus/now_playing.py b/i3pystatus/now_playing.py index 1c066de..953c4d8 100644 --- a/i3pystatus/now_playing.py +++ b/i3pystatus/now_playing.py @@ -100,14 +100,20 @@ class NowPlaying(IntervalModule): try: player = self.get_player() properties = dbus.Interface(player, "org.freedesktop.DBus.Properties") - get_prop = functools.partial(properties.Get, "org.mpris.MediaPlayer2.Player") + + def get_prop(name, default=None): + try: + return properties.Get("org.mpris.MediaPlayer2.Player", name) + except dbus.exceptions.DBusException: + return default + currentsong = get_prop("Metadata") fdict = { "status": self.status[self.statusmap[get_prop("PlaybackStatus")]], "len": 0, # TODO: Use optional(!) TrackList interface for this to gain 100 % mpd<->now_playing compat "pos": 0, - "volume": int(get_prop("Volume") * 100), + "volume": int(get_prop("Volume", 0) * 100), "title": currentsong.get("xesam:title", ""), "album": currentsong.get("xesam:album", ""),