Commits

Luke Plant committed 2f8f8c9

Fixed support for Guayadeque

* Use dbus interfaces properly
* Don't assume GetStatus method is supported

Comments (0)

Files changed (3)

 -----------
 
 * Added support for quodlibet
+* Fixed support for Guayadeque
 
 Version 0.4
 -----------

playerdo/backends/mpris.py

             and not str(s).startswith('org.mpris.MediaPlayer2')]
 
 def get_sorted_candidate_buses():
+    import dbus
     candidates = get_all_mpris_buses()
     # Sort by status - playing = 0, paused = 1, stopped = 2
-    l = [(int(DBusObject(n, PLAYER_OBJECT_NAME).GetStatus()[0]), n)
-         for n in candidates]
+    l = []
+    for n in candidates:
+        try:
+            status = (int(DBusObject(n, PLAYER_OBJECT_NAME).GetStatus()[0]), n)
+        except dbus.exceptions.DBusException:
+            # probably 'unknown method', so we assume 'stopped'
+            status = (2, n)
+        l.append(status)
     l.sort()
     return [n for i, n in l]
 
 
 PLAYER_OBJECT_NAME = "/Player"
-
+MPRIS_INTERFACE_NAME = "org.freedesktop.MediaPlayer"
 
 class MprisPlayer(Player):
 
 
     @property
     def friendly_name(self):
+        import dbus
         retval = self._friendly_name
         try:
             l = get_sorted_candidate_buses()
                 try:
                     bus = DBusObject(n, "/")
                     names.append(bus.Identity())
+                except dbus.exceptions.DBusException:
+                    bus = DBusObject(n, "/", interface=MPRIS_INTERFACE_NAME)
+                    names.append(bus.Identity())
                 except:
                     pass
 
         try:
             return self._player
         except AttributeError:
-            obj = DBusObject(self.bus_name, PLAYER_OBJECT_NAME)
+            obj = DBusObject(self.bus_name, PLAYER_OBJECT_NAME, interface=MPRIS_INTERFACE_NAME)
             self._player = obj
             return obj
 
             return False
 
     def is_paused(self):
-        return self.player.GetStatus()[0] == 1
+        import dbus
+        try:
+            return self.player.GetStatus()[0] == 1
+        except dbus.exceptions.DBusException:
+            # Assume stopped, not paused, if doesn't support GetStatus
+            return False
 
     def is_stopped(self):
-        return self.player.GetStatus()[0] == 2
+        import dbus
+        try:
+            return self.player.GetStatus()[0] == 2
+        except dbus.exceptions.DBusException:
+            # Assume stopped if doesn't support GetStatus
+            return True
 
     def check_dependencies(self):
         retval = []

playerdo/utils.py

     to be specified once.
     """
 
-    def __init__(self, bus_name, object_name):
+    def __init__(self, bus_name, object_name, interface=None):
         import dbus
         bus = dbus.SessionBus()
         self._bus = bus
-        self._obj = bus.get_object(bus_name, object_name)
+        obj = bus.get_object(bus_name, object_name)
+        if interface is not None:
+            obj = dbus.Interface(obj, interface)
+        self._obj = obj
 
     def __getattr__(self, name):
         def f(*args, **kwargs):