Luke Plant avatar Luke Plant committed e59e463

friendly_name for MprisPlayer now includes all currently running MPRIS players

Comments (0)

Files changed (1)

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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.