[gnome-music/wip/jfelder/mpris-limit-songs: 2/3] player: Simplify get_songs method



commit aa32bb07b1623a7c94e2e54141d576680c6375e4
Author: Jean Felder <jfelder src gnome org>
Date:   Thu Sep 13 22:44:01 2018 +0200

    player: Simplify get_songs method
    
    Remove the validation field from the returned list. This method is
    only used by mpris which does not need it.

 gnomemusic/mpris.py  |  9 ++++-----
 gnomemusic/player.py | 13 ++++++++-----
 2 files changed, 12 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index b103c50c..5a33d846 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -26,7 +26,7 @@
 import codecs
 
 from gnomemusic.gstplayer import Playback
-from gnomemusic.player import PlayerField, PlayerPlaylist, RepeatMode
+from gnomemusic.player import PlayerPlaylist, RepeatMode
 from gnomemusic.grilo import grilo
 from gnomemusic.playlists import Playlists
 from gnomemusic.utils import View
@@ -350,8 +350,7 @@ class MediaPlayer2Service(Server):
 
     @log
     def _get_media_from_id(self, track_id):
-        for track in self.player.get_songs():
-            media = track[PlayerField.SONG]
+        for media in self.player.get_songs():
             if track_id == self._get_media_id(media):
                 return media
         return None
@@ -359,7 +358,7 @@ class MediaPlayer2Service(Server):
     @log
     def _get_track_list(self):
         if self.player.props.playing:
-            return [self._get_media_id(song[PlayerField.SONG])
+            return [self._get_media_id(song)
                     for song in self.player.get_songs()]
         else:
             return []
@@ -582,7 +581,7 @@ class MediaPlayer2Service(Server):
 
     def GoTo(self, track_id):
         for index, song in enumerate(self.player.get_songs()):
-            if track_id == self._get_media_id(song[PlayerField.SONG]):
+            if track_id == self._get_media_id(song):
                 self.player_play(index)
                 return
 
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 644a6ee2..a4903458 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -476,13 +476,11 @@ class PlayerPlaylist(GObject.GObject):
     def get_songs(self):
         """Get the current playlist.
 
-        Each member of the list has two elements: the song, and the validation
-        status.
-
         :returns: current playlist
-        :rtype: list
+        :rtype: list of Grl.Media
         """
-        return self._songs
+        songs = [elt[PlayerField.SONG] for elt in self._songs]
+        return songs
 
 
 class Player(GObject.GObject):
@@ -860,4 +858,9 @@ class Player(GObject.GObject):
 
     @log
     def get_songs(self):
+        """Get the current playlist.
+
+        :returns: current playlist
+        :rtype: list of Grl.Media
+        """
         return self._playlist.get_songs()


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