Commit d8583bf7 authored by Jean Felder's avatar Jean Felder Committed by Marinus Schraal

player: Remove get_mpris_playlist usage

Use coremodel playlist_sort property directly.
parent 456c890a
......@@ -22,6 +22,7 @@
# code, but you are not obligated to do so. If you do not wish to do so,
# delete this exception statement from your version.
from itertools import chain
import logging
import re
......@@ -271,6 +272,8 @@ class MPRIS(DBusInterface):
MEDIA_PLAYER2_TRACKLIST_IFACE = 'org.mpris.MediaPlayer2.TrackList'
MEDIA_PLAYER2_PLAYLISTS_IFACE = 'org.mpris.MediaPlayer2.Playlists'
_playlist_nb_songs = 10
def __repr__(self):
return "<MPRIS>"
......@@ -290,6 +293,8 @@ class MPRIS(DBusInterface):
self._player.connect(
'playlist-changed', self._on_player_playlist_changed)
self._player_model = app.props.coremodel.props.playlist_sort
self._playlists = Playlists.get_default()
self._playlists_model = None
self._playlists.connect('playlist-renamed', self._on_playlist_renamed)
......@@ -416,9 +421,37 @@ class MPRIS(DBusInterface):
previous_path_list = self._path_list
self._path_list = []
self._metadata_list = []
for index, song in self._player.get_mpris_playlist():
path = self._get_song_dbus_path(song, index)
metadata = self._get_metadata(song, index)
current_position = self._player.props.position
nb_songs = self._player_model.get_n_items()
index_min = current_position - self._playlist_nb_songs
index_max = current_position + self._playlist_nb_songs + 1
if self._player.get_playlist_type() == PlayerPlaylist.Type.ALBUM:
index_min = 0
index_max = self._player_model.get_n_items()
first_index = max(index_min, 0)
last_index = min(index_max, nb_songs)
positions = range(first_index, last_index)
nb_songs_max = 2 * self._playlist_nb_songs + 1
if (self._player.props.repeat_mode == RepeatMode.ALL
and (last_index - first_index) < nb_songs_max):
offset_sup = min(
self._playlist_nb_songs - last_index + current_position + 1,
first_index)
offset_inf = min(
self._playlist_nb_songs - current_position + first_index,
nb_songs - last_index)
positions = chain(
range(nb_songs - offset_inf, nb_songs), positions,
range(offset_sup))
for position in positions:
coresong = self._player_model.get_item(position)
path = self._get_song_dbus_path(coresong, position)
metadata = self._get_metadata(coresong, position)
self._path_list.append(path)
self._metadata_list.append(metadata)
......
......@@ -23,7 +23,6 @@
# delete this exception statement from your version.
from enum import IntEnum
from itertools import chain
from random import randint, randrange
import logging
import time
......@@ -336,58 +335,6 @@ class PlayerPlaylist(GObject.GObject):
"""
return self._type
@log
def get_mpris_playlist(self):
"""Get recent and next songs from the current playlist.
If the playlist is an album, return all songs.
Returned songs are sorted according to the repeat mode.
This method is used by mpris to expose a TrackList.
:returns: current playlist
:rtype: list of index and Grl.Media
"""
return []
if not self.props.current_song:
return []
songs = []
nb_songs = len(self._songs)
current_index = self._position
if self.props.repeat_mode == RepeatMode.SHUFFLE:
current_index = self._shuffle_indexes.index(self._position)
index_min = current_index - self._nb_songs_max
index_max = current_index + self._nb_songs_max + 1
if self._type == PlayerPlaylist.Type.ALBUM:
index_min = 0
index_max = nb_songs
first_index = max(index_min, 0)
last_index = min(index_max, nb_songs)
if self.props.repeat_mode == RepeatMode.SHUFFLE:
indexes = self._shuffle_indexes[first_index:last_index]
else:
indexes = range(first_index, last_index)
if (self.props.repeat_mode == RepeatMode.ALL
and (last_index - first_index) < (2 * self._nb_songs_max + 1)):
offset_sup = min(
self._nb_songs_max - last_index + current_index + 1,
first_index)
offset_inf = min(
self._nb_songs_max - current_index + first_index,
nb_songs - last_index)
indexes = chain(
range(nb_songs - offset_inf, nb_songs), indexes,
range(offset_sup))
songs = [[index, self._songs[index][PlayerField.SONG]]
for index in indexes]
return songs
class Player(GObject.GObject):
"""Main Player object
......@@ -757,19 +704,6 @@ class Player(GObject.GObject):
if position_second <= duration_second:
self._gst_player.seek(position_second)
@log
def get_mpris_playlist(self):
"""Get recent and next songs from the current playlist.
If the playlist is an album, return all songs.
Returned songs are sorted according to the repeat mode.
This method is used by mpris to expose a TrackList.
:returns: current playlist
:rtype: list of index and Grl.Media
"""
return self._playlist.get_mpris_playlist()
@log
def _on_seek_finished(self, klass):
# FIXME: Just a proxy
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment