[gnome-music/wip/mschraal/mpris-object-path: 17/17] mpris: Fix object path for track ids



commit 19b413ada1f4b75a84ac229e8f08ee9eb5afff91
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Jan 12 00:42:13 2018 +0100

    mpris: Fix object path for track ids
    
    Follow the MPRIS2 spec regarding TrackList track id's and encode the
    Grilo song id so it cannot contain invalid characters.
    
    Related: #100

 gnomemusic/mpris.py | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 87317ce..a282b2a 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -23,6 +23,8 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
+import codecs
+
 from gnomemusic.player import PlaybackStatus, RepeatType
 from gnomemusic.grilo import grilo
 from gnomemusic.playlists import Playlists
@@ -336,8 +338,14 @@ class MediaPlayer2Service(Server):
 
     @log
     def _get_media_id(self, media):
-        return '/org/mpris/MediaPlayer2/TrackList/%s' % \
-            (media.get_id() if media else 'NoTrack')
+        if media:
+            trackid = "/org/gnome/GnomeMusic/Tracklist/{}".format(
+                codecs.encode(
+                    bytes(media.get_id(), 'ascii'), 'hex').decode('ascii'))
+        else:
+            trackid = "/org/mpris/MediaPlayer2/TrackList/NoTrack"
+
+        return trackid
 
     @log
     def _get_media_from_id(self, track_id):


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