[gnome-music/wip/jfelder/mpris-cleanup: 46/67] mpris: Make the trackid truly unique
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-cleanup: 46/67] mpris: Make the trackid truly unique
- Date: Fri, 5 Apr 2019 20:09:49 +0000 (UTC)
commit 7de602ce5aee146d3fa39302b7a73708c11383ff
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 56b758f3..96866927 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -337,6 +337,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
@@ -346,7 +348,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 a2e7c89c..09a18db1 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -861,6 +861,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]