[gnome-music/wip/mschraal/core] player: Pass around CoreSong instead of Grl.Media
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core] player: Pass around CoreSong instead of Grl.Media
- Date: Wed, 3 Jul 2019 22:10:14 +0000 (UTC)
commit 25667d8787a392b1b7f24780aa30020fbb74e0c7
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Jul 3 22:30:34 2019 +0200
player: Pass around CoreSong instead of Grl.Media
gnomemusic/mpris.py | 53 ++++++++++++++++----------------
gnomemusic/player.py | 44 ++++++++++----------------
gnomemusic/views/songsview.py | 2 +-
gnomemusic/widgets/albumwidget.py | 2 +-
gnomemusic/widgets/artistalbumswidget.py | 2 +-
gnomemusic/widgets/playertoolbar.py | 12 ++++----
6 files changed, 52 insertions(+), 63 deletions(-)
---
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index bab453b6..8e90ad54 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -331,42 +331,42 @@ class MPRIS(DBusInterface):
return 'Playlist'
@log
- def _get_metadata(self, media=None, index=None):
- song_dbus_path = self._get_song_dbus_path(media, index)
+ def _get_metadata(self, coresong=None, index=None):
+ song_dbus_path = self._get_song_dbus_path(coresong, index)
if not self._player.props.current_song:
return {
'mpris:trackid': GLib.Variant('o', song_dbus_path)
}
- if not media:
- media = self._player.props.current_song
+ if not coresong:
+ coresong = self._player.props.current_song
- length = media.get_duration() * 1e6
- user_rating = 1.0 if media.get_favourite() else 0.0
- artist = utils.get_artist_name(media)
+ length = coresong.props.duration * 1e6
+ user_rating = 1.0 if coresong.props.favorite else 0.0
+ artist = coresong.props.artist
metadata = {
'mpris:trackid': GLib.Variant('o', song_dbus_path),
- 'xesam:url': GLib.Variant('s', media.get_url()),
+ 'xesam:url': GLib.Variant('s', coresong.props.url),
'mpris:length': GLib.Variant('x', length),
- 'xesam:useCount': GLib.Variant('i', media.get_play_count()),
+ 'xesam:useCount': GLib.Variant('i', coresong.props.play_count),
'xesam:userRating': GLib.Variant('d', user_rating),
- 'xesam:title': GLib.Variant('s', utils.get_media_title(media)),
- 'xesam:album': GLib.Variant('s', utils.get_album_title(media)),
+ 'xesam:title': GLib.Variant('s', coresong.props.title),
+ 'xesam:album': GLib.Variant('s', coresong.props.album),
'xesam:artist': GLib.Variant('as', [artist]),
'xesam:albumArtist': GLib.Variant('as', [artist])
}
- genre = media.get_genre()
+ genre = coresong.props.media.get_genre()
if genre is not None:
metadata['xesam:genre'] = GLib.Variant('as', [genre])
- last_played = media.get_last_played()
+ last_played = coresong.props.media.get_last_played()
if last_played is not None:
last_played_str = last_played.format("%FT%T%:z")
metadata['xesam:lastUsed'] = GLib.Variant('s', last_played_str)
- track_nr = media.get_track_number()
+ track_nr = coresong.props.track_number
if track_nr > 0:
metadata['xesam:trackNumber'] = GLib.Variant('i', track_nr)
@@ -377,12 +377,12 @@ class MPRIS(DBusInterface):
# loading.
# FIXME: The thumbnail retrieval should take place in the
# player.
- art_url = media.get_thumbnail()
+ art_url = coresong.props.media.get_thumbnail()
if not art_url:
- thumb_file = lookup_art_file_from_cache(media)
+ thumb_file = lookup_art_file_from_cache(coresong.props.media)
if thumb_file:
art_url = GLib.filename_to_uri(thumb_file.get_path())
- media.set_thumbnail(art_url)
+ coresong.props.media.set_thumbnail(art_url)
if art_url:
metadata['mpris:artUrl'] = GLib.Variant('s', art_url)
@@ -390,15 +390,16 @@ class MPRIS(DBusInterface):
return metadata
@log
- def _get_song_dbus_path(self, media=None, index=None):
+ def _get_song_dbus_path(self, coresong=None, index=None):
"""Convert a Grilo media to a D-Bus path
- The hex encoding is used to remove any possible invalid character.
- Use player index to make the path truly unique in case the same song
- is present multiple times in a playlist.
- If media is None, it means that the current song path is requested.
+ The hex encoding is used to remove any possible invalid
+ character. Use player index to make the path truly unique in
+ case the same song is present multiple times in a playlist.
+ If coresong is None, it means that the current song path is
+ requested.
- :param Grl.Media media: The media object
+ :param CoreSong coresong: The CoreSong object
:param int index: The media position in the current playlist
:return: a D-Bus id to uniquely identify the song
:rtype: str
@@ -406,11 +407,11 @@ class MPRIS(DBusInterface):
if not self._player.props.current_song:
return "/org/mpris/MediaPlayer2/TrackList/NoTrack"
- if not media:
- media = self._player.props.current_song
+ if not coresong:
+ coresong = self._player.props.current_song
index = self._player.props.position
- id_hex = media.get_id().encode('ascii').hex()
+ id_hex = coresong.props.grlid.encode('ascii').hex()
path = "/org/gnome/GnomeMusic/TrackList/{}_{}".format(
id_hex, index)
return path
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index ada32493..6055e092 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -29,16 +29,13 @@ import logging
import time
import gi
-gi.require_version('Grl', '0.3')
-gi.require_version('Gst', '1.0')
-gi.require_version('GstAudio', '1.0')
gi.require_version('GstPbutils', '1.0')
-from gi.repository import GObject, Grl, GstPbutils
+from gi.repository import GObject, GstPbutils
from gi._gi import pygobject_new_full
from gnomemusic import log
+from gnomemusic.coresong import CoreSong
from gnomemusic.gstplayer import GstPlayer, Playback
-from gnomemusic.grilo import grilo
from gnomemusic.playlists import Playlists
from gnomemusic.scrobbler import LastFmScrobbler
from gnomemusic.widgets.songwidget import SongWidget
@@ -255,25 +252,25 @@ class PlayerPlaylist(GObject.GObject):
return self._position
@GObject.Property(
- type=Grl.Media, default=None, flags=GObject.ParamFlags.READABLE)
+ type=CoreSong, default=None, flags=GObject.ParamFlags.READABLE)
def current_song(self):
"""Get current song.
:returns: the song being played or None if there are no songs
- :rtype: Grl.Media
+ :rtype: CoreSong
"""
n_items = self._model.get_n_items()
if (n_items != 0
and n_items > self._position):
current_song = self._model[self._position]
if current_song.props.state == SongWidget.State.PLAYING:
- return current_song.props.media
+ return current_song
for idx, coresong in enumerate(self._model):
if coresong.props.state == SongWidget.State.PLAYING:
print("position", idx)
self._position = idx
- return coresong.props.media
+ return coresong
return None
@@ -462,19 +459,12 @@ class Player(GObject.GObject):
"""
return self.props.state == Playback.PLAYING
- @log
- def _load(self, song):
- self._gst_player.props.state = Playback.LOADING
- self._time_stamp = int(time.time())
-
- self._gst_player.props.url = song.get_url()
-
@log
def _on_about_to_finish(self, klass):
if self.props.has_next:
self._playlist.next()
- new_url = self._playlist.props.current_song.get_url()
+ new_url = self._playlist.props.current_song.props.url
self._gst_player.props.url = new_url
self._gapless_set = True
@@ -496,15 +486,13 @@ class Player(GObject.GObject):
self.emit("song-changed")
- def _load2(self, song):
+ def _load(self, coresong):
self._gst_player.props.state = Playback.LOADING
self._time_stamp = int(time.time())
-
- self._gst_player.props.url = song.get_url()
- print(song.get_url())
+ self._gst_player.props.url = coresong.props.url
@log
- def play(self, song_changed=True, song_offset=None, media=None):
+ def play(self, song_changed=True, song_offset=None, coresong=None):
"""Play a song.
Load a new song or resume playback depending on song_changed
@@ -516,10 +504,10 @@ class Player(GObject.GObject):
if self.props.current_song is None:
return
- if media is None:
- media = self._playlist.props.current_song
+ if coresong is None:
+ coresong = self._playlist.props.current_song
- self._load2(media)
+ self._load(coresong)
self._gst_player.props.state = Playback.PLAYING
return
@@ -706,12 +694,12 @@ class Player(GObject.GObject):
return self._playlist.props.position
@GObject.Property(
- type=Grl.Media, default=None, flags=GObject.ParamFlags.READABLE)
+ type=CoreSong, default=None, flags=GObject.ParamFlags.READABLE)
def current_song(self):
"""Get the current song.
- :returns: the song being played. None if there is no playlist.
- :rtype: Grl.Media
+ :returns: The song being played. None if there is no playlist.
+ :rtype: CoreSong
"""
return self._playlist.props.current_song
diff --git a/gnomemusic/views/songsview.py b/gnomemusic/views/songsview.py
index 703fbb0b..581c59f6 100644
--- a/gnomemusic/views/songsview.py
+++ b/gnomemusic/views/songsview.py
@@ -164,7 +164,7 @@ class SongsView(BaseView):
if current_song is None:
return
- if model[itr][5].props.media.get_id() == current_song.get_id():
+ if model[itr][5].props.grlid == current_song.props.grlid:
cell.props.icon_name = self._now_playing_icon_name
cell.props.visible = True
else:
diff --git a/gnomemusic/widgets/albumwidget.py b/gnomemusic/widgets/albumwidget.py
index 419a2edc..8e9172a7 100644
--- a/gnomemusic/widgets/albumwidget.py
+++ b/gnomemusic/widgets/albumwidget.py
@@ -164,7 +164,7 @@ class AlbumWidget(Gtk.EventBox):
coremodel = self._parent_view._window._app.props.coremodel
def _on_playlist_loaded(klass):
- self._player.play(None, None, song_widget._media)
+ self._player.play(None, None, song_widget.props.coresong)
coremodel.disconnect(signal_id)
signal_id = coremodel.connect("playlist-loaded", _on_playlist_loaded)
diff --git a/gnomemusic/widgets/artistalbumswidget.py b/gnomemusic/widgets/artistalbumswidget.py
index de163f29..c87879ab 100644
--- a/gnomemusic/widgets/artistalbumswidget.py
+++ b/gnomemusic/widgets/artistalbumswidget.py
@@ -107,7 +107,7 @@ class ArtistAlbumsWidget(Gtk.Box):
coremodel = self._player._app.props.coremodel
def _on_playlist_loaded(klass):
- self._player.play(None, None, song_widget._media)
+ self._player.play(None, None, song_widget.props.coresong)
coremodel.disconnect(signal_id)
signal_id = coremodel.connect("playlist-loaded", _on_playlist_loaded)
diff --git a/gnomemusic/widgets/playertoolbar.py b/gnomemusic/widgets/playertoolbar.py
index 264758c2..17e75807 100644
--- a/gnomemusic/widgets/playertoolbar.py
+++ b/gnomemusic/widgets/playertoolbar.py
@@ -168,16 +168,16 @@ class PlayerToolbar(Gtk.ActionBar):
:param Player player: The main player object
"""
- current_song = player.props.current_song
- self._duration_label.set_label(
- utils.seconds_to_string(current_song.get_duration()))
+ coresong = player.props.current_song
+ self._duration_label.props.label = utils.seconds_to_string(
+ coresong.props.duration)
self._progress_time_label.props.label = "0:00"
self._play_button.set_sensitive(True)
self._sync_prev_next()
- artist = utils.get_artist_name(current_song)
- title = utils.get_media_title(current_song)
+ artist = coresong.props.artist
+ title = coresong.props.title
self._title_label.props.label = title
self._artist_label.props.label = artist
@@ -185,7 +185,7 @@ class PlayerToolbar(Gtk.ActionBar):
self._tooltip.props.title = title
self._tooltip.props.subtitle = artist
- self._cover_stack.update(current_song)
+ self._cover_stack.update(coresong.props.media)
@Gtk.Template.Callback()
@log
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]