Commit 599b31e6 authored by Jean Felder's avatar Jean Felder Committed by Jean Felder

mpris: Group MPRIS playlist creation logic into one method

MPRIS playlists are a data structure describing a playlist. It
consists of a unique identifier (path), a name, and an icon.
In GNOME Music case, icon are always empty.
parent a2444ee1
...@@ -389,6 +389,12 @@ class MediaPlayer2Service(Server): ...@@ -389,6 +389,12 @@ class MediaPlayer2Service(Server):
return playlist return playlist
return None return None
@log
def _get_mpris_playlist_from_playlist(self, playlist):
playlist_name = utils.get_media_title(playlist)
path = self._get_playlist_dbus_path(playlist)
return (path, playlist_name, "")
@log @log
def _get_playlist_from_id(self, playlist_id): def _get_playlist_from_id(self, playlist_id):
for playlist in self._stored_playlists: for playlist in self._stored_playlists:
...@@ -424,9 +430,8 @@ class MediaPlayer2Service(Server): ...@@ -424,9 +430,8 @@ class MediaPlayer2Service(Server):
return (False, ("/", "", "")) return (False, ("/", "", ""))
playlist = self._get_playlist_from_id(self.player.get_playlist_id()) playlist = self._get_playlist_from_id(self.player.get_playlist_id())
playlist_name = utils.get_media_title(playlist) mpris_playlist = self._get_mpris_playlist_from_playlist(playlist)
path = self._get_playlist_dbus_path(playlist) return (True, mpris_playlist)
return (True, (path, playlist_name, ""))
@log @log
def _on_current_song_changed(self, player): def _on_current_song_changed(self, player):
...@@ -653,17 +658,16 @@ class MediaPlayer2Service(Server): ...@@ -653,17 +658,16 @@ class MediaPlayer2Service(Server):
if order != 'Alphabetical': if order != 'Alphabetical':
return [] return []
playlists = [(self._get_playlist_dbus_path(playlist), mpris_playlists = [self._get_mpris_playlist_from_playlist(playlist)
utils.get_media_title(playlist), '') for playlist in self._stored_playlists]
for playlist in self._stored_playlists]
if not reverse: if not reverse:
return playlists[index:index + max_count] return mpris_playlists[index:index + max_count]
first_index = index - 1 first_index = index - 1
if first_index < 0: if first_index < 0:
first_index = None first_index = None
return playlists[index + max_count - 1:first_index:-1] return mpris_playlists[index + max_count - 1:first_index:-1]
def PlaylistChanged(self, playlist): def PlaylistChanged(self, playlist):
self.con.emit_signal(None, self.con.emit_signal(None,
......
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