[gnome-music/wip/jfelder/mpris-cleanup: 15/23] mpris: Make the trackid truly unique



commit 0882d5ad161fa6defa33d97a28e7571f9e049040
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Sep 5 01:22:52 2018 +0200

    mpris: Make the trackid truly unique
    
    Use the song position as a suffix to trackid to handle duplicate
    songs.
    
    Related: #100

 gnomemusic/mpris.py  | 6 +++++-
 gnomemusic/player.py | 9 +++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index aca849d4..b29dbbd9 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -339,6 +339,8 @@ class MPRIS(DBusInterface):
         """Convert a Grilo media to a D-Bus path
 
         The hex encoding is used to remove any possible invalid character.
+        Use player index to make the path truly unique in case the same song
+        is present multiple times in a playlist.
 
         :param Grl.Media media: The media object
         :return: a D-Bus id to uniquely identify the song
@@ -348,7 +350,9 @@ class MPRIS(DBusInterface):
             return "/org/mpris/MediaPlayer2/TrackList/NoTrack"
 
         id_hex = media.get_id().encode('ascii').hex()
-        path = "/org/gnome/GnomeMusic/TrackList/{}".format(id_hex)
+        current_index = self.player.get_current_index()
+        path = "/org/gnome/GnomeMusic/TrackList/{}_{}".format(
+            id_hex, current_index)
         return path
 
     @log
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 67214a83..a0e7f4e5 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -860,6 +860,15 @@ class Player(GObject.GObject):
         """
         return self._playlist.props.playlist_id
 
+    @log
+    def get_current_index(self):
+        """Get current song index.
+
+        :returns: position of the current song int the playlist.
+        :rtype: int
+        """
+        return self._playlist.get_current_index()
+
     @log
     def get_position(self):
         """Get player position.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]