[gnome-music/wip/jfelder/mpris-limit-songs] mpris: limit the amount of playlist items
- From: Jean Felder <jfelder src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/jfelder/mpris-limit-songs] mpris: limit the amount of playlist items
- Date: Mon, 17 Sep 2018 06:34:03 +0000 (UTC)
commit 790fba85eeb4e743fe593f8b5fd2c8e71084fb0a
Author: Jean Felder <jfelder src gnome org>
Date: Fri Sep 14 00:16:17 2018 +0200
mpris: limit the amount of playlist items
gnomemusic/mpris.py | 15 +++++++++++----
gnomemusic/player.py | 19 +++++++++++++------
2 files changed, 24 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index 5a33d846..bb242704 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -208,6 +208,8 @@ class MediaPlayer2Service(Server):
MEDIA_PLAYER2_TRACKLIST_IFACE = 'org.mpris.MediaPlayer2.TrackList'
MEDIA_PLAYER2_PLAYLISTS_IFACE = 'org.mpris.MediaPlayer2.Playlists'
+ _nb_songs = -10
+
def __repr__(self):
return '<MediaPlayer2Service>'
@@ -350,7 +352,9 @@ class MediaPlayer2Service(Server):
@log
def _get_media_from_id(self, track_id):
- for media in self.player.get_songs():
+ songs = self.player.get_songs(
+ self._nb_songs, self._nb_songs)
+ for media in songs:
if track_id == self._get_media_id(media):
return media
return None
@@ -358,8 +362,9 @@ class MediaPlayer2Service(Server):
@log
def _get_track_list(self):
if self.player.props.playing:
- return [self._get_media_id(song)
- for song in self.player.get_songs()]
+ songs = self.player.get_songs(
+ self._nb_songs, self._nb_songs)
+ return [self._get_media_id(song) for song in songs]
else:
return []
@@ -580,7 +585,9 @@ class MediaPlayer2Service(Server):
pass
def GoTo(self, track_id):
- for index, song in enumerate(self.player.get_songs()):
+ songs = self.player.get_songs(
+ self._nb_songs, self._nb_songs)
+ for index, song in enumerate(songs):
if track_id == self._get_media_id(song):
self.player_play(index)
return
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index a4903458..8d113b6d 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -473,13 +473,18 @@ class PlayerPlaylist(GObject.GObject):
return self._type
@log
- def get_songs(self):
- """Get the current playlist.
+ def get_songs(self, first_index, last_index):
+ """Get some songs from the current playlist.
+ :param int nb_songs: number of songs to get
+ :param bool start_at_current_index: start at the current song
:returns: current playlist
:rtype: list of Grl.Media
"""
- songs = [elt[PlayerField.SONG] for elt in self._songs]
+ first_pos = max(self._current_index - first_index, 0)
+ last_pos = min(self._current_index + last_index + 1, len(self._songs))
+ songs = [elt[PlayerField.SONG]
+ for elt in self._songs[first_pos:last_pos]]
return songs
@@ -857,10 +862,12 @@ class Player(GObject.GObject):
return self._playlist.props.current_song is not None
@log
- def get_songs(self):
- """Get the current playlist.
+ def get_songs(self, first_index, last_index):
+ """Get some songs from the current playlist.
+ :param int nb_songs: number of songs to get
+ :param bool start_at_current_index: start at the current song
:returns: current playlist
:rtype: list of Grl.Media
"""
- return self._playlist.get_songs()
+ return self._playlist.get_songs(first_index, last_index)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]