Commits

Luke Plant  committed e59e463

friendly_name for MprisPlayer now includes all currently running MPRIS players

  • Participants
  • Parent commits 99b8d2a

Comments (0)

Files changed (1)

File playerdo/backends/mpris.py

             if str(s).startswith('org.mpris.')]
 
 
+def get_sorted_candidate_buses(player_object_name):
+    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.sort()
+    return [n for i, n in l]
+
+
+class classproperty(property):
+    def __get__(self, cls, owner):
+        return self.fget.__get__(None, owner)()
+
+
 class MprisPlayer(Player):
 
-    friendly_name = "Any MPRIS player"
+    _friendly_name = "Any MPRIS player"
     player_object_name = "/Player"
 
+    @classproperty
+    @classmethod
+    def friendly_name(cls):
+        retval = cls._friendly_name
+        try:
+            l = get_sorted_candidate_buses(cls.player_object_name)
+            names = []
+            for n in l:
+                try:
+                    bus = DBusObject(n, "/")
+                    names.append(bus.Identity())
+                except:
+                    pass
+
+            if len(names) > 0:
+                retval += " (currently running: %s)" %  ", ".join(names)
+        except Exception:
+            pass
+
+        return retval
+
     @property
     def bus_name(self):
-        # Use the first one we find.
         try:
             return self._bus_name
         except AttributeError:
-            candidates = get_all_mpris_buses()
-            # Sort by status - playing = 0, paused = 1, stopped = 2
-            l = [(int(DBusObject(n, self.player_object_name).GetStatus()[0]), n)
-                 for n in candidates]
-            l.sort()
+            l = get_sorted_candidate_buses(self.player_object_name)
             if len(l) > 0:
-                bus_name = l[0][1]
+                bus_name = l[0]
             else:
                 bus_name = None
             self._bus_name = bus_name