[gnome-music/wip/mschraal/core: 2/6] player: Trigger writeback through CoreSong
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/core: 2/6] player: Trigger writeback through CoreSong
- Date: Thu, 4 Jul 2019 14:31:20 +0000 (UTC)
commit 3141df290e7bc793b58fb2d6c713c6ba49f5dc57
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Jul 3 23:15:55 2019 +0200
player: Trigger writeback through CoreSong
gnomemusic/coresong.py | 10 ++++++-
gnomemusic/grilo.py | 79 --------------------------------------------------
gnomemusic/mpris.py | 9 +++---
gnomemusic/player.py | 4 +--
4 files changed, 16 insertions(+), 86 deletions(-)
---
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index a4f3756a..e118f200 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -1,6 +1,6 @@
import gi
gi.require_version('Grl', '0.3')
-from gi.repository import Grl, GObject
+from gi.repository import Grl, GLib, GObject
from gnomemusic import log
import gnomemusic.utils as utils
@@ -74,3 +74,11 @@ class CoreSong(GObject.GObject):
self.props.title = utils.get_media_title(media)
self.props.track_number = media.get_track_number()
self.props.url = media.get_url()
+
+ def bump_play_count(self):
+ self.props.media.set_play_count(self.props.play_count + 1)
+ self._grilo.writeback(self.props.media, Grl.METADATA_KEY_PLAY_COUNT)
+
+ def set_last_played(self):
+ self.props.media.set_last_played(GLib.DateTime.new_now_utc())
+ self._grilo.writeback(self.props.media, Grl.METADATA_KEY_LAST_PLAYED)
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index d05268d8..642cebfc 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -347,16 +347,6 @@ class Grilo(GObject.GObject):
callback(source, param, item, remaining, data)
self.tracker.query(query, self.METADATA_KEYS, options, _callback, data)
- @log
- def set_favorite(self, song_item, favorite):
- """Set the favorite status of a media item
-
- :param song_item: A Grilo media item
- :param bool favorite: Set favorite status
- """
- if song_item.get_favourite() != favorite:
- self.toggle_favorite(song_item)
-
@log
def search(self, q, callback, data=None):
options = self.options.copy()
@@ -421,75 +411,6 @@ class Grilo(GObject.GObject):
self.tracker.query(query, self.METADATA_KEYS, options, callback, None)
- @log
- def _store_metadata(self, media, key):
- """Convenience function to store metadata
-
- Wrap the metadata store call in a idle_add compatible form.
- :param media: A Grilo media item
- :param key: A Grilo metadata key
- """
- # FIXME: We assume this is the tracker plugin.
- # FIXME: Doing this async crashes.
- try:
- self.tracker.store_metadata_sync(
- media, [key], Grl.WriteFlags.NORMAL)
- except GLib.Error as error:
- logger.warning(
- "Error {}: {}".format(error.domain, error.message))
-
- return GLib.SOURCE_REMOVE
-
- @log
- def bump_play_count(self, media):
- """Bumps the play count of a song
-
- Adds one to the playcount and adds it to the tracker store
- :param media: A Grilo media item
- """
- count = media.get_play_count()
- media.set_play_count(count + 1)
- # FIXME: Do this as an idle call, otherwise it may not return
- # and block other sources. This seems to point to a problem in
- # Grilo (gnomemusic!411).
- GLib.idle_add(self._store_metadata, media, Grl.METADATA_KEY_PLAY_COUNT)
-
- @log
- def set_last_played(self, media):
- """Sets the date-time when the media was last played
-
- Sets the last played date-time for the media.
- :param media: A Grilo media item
- """
- media.set_last_played(GLib.DateTime.new_now_utc())
- # FIXME: Do this as an idle call, otherwise it may not return
- # and block other sources. This seems to point to a problem in
- # Grilo (gnomemusic!411).
- GLib.idle_add(
- self._store_metadata, media, Grl.METADATA_KEY_LAST_PLAYED)
-
- @log
- def toggle_favorite(self, media, override=False):
- """Toggles favorite status for media item
-
- Toggles favorite status and writes it back to the tracker store
- :param media: A Grilo media item
- """
- print("favorite for media", media)
- if not override:
- if media.get_favourite():
- # For now keep unsetting the lyrics to deal with how
- # previous versions dealt with favorites.
- media.set_lyrics("")
- media.set_favourite(False)
- else:
- media.set_favourite(True)
-
- # FIXME: Do this as an idle call, otherwise it may not return
- # and block other sources. This seems to point to a problem in
- # Grilo (gnomemusic!411).
- GLib.idle_add(self._store_metadata, media, Grl.METADATA_KEY_FAVOURITE)
-
@log
def songs_available(self, callback):
"""Checks if there are any songs available
diff --git a/gnomemusic/mpris.py b/gnomemusic/mpris.py
index f2bb71bf..55c1cb10 100644
--- a/gnomemusic/mpris.py
+++ b/gnomemusic/mpris.py
@@ -718,11 +718,12 @@ class MPRIS(DBusInterface):
:param str path: Identifier of the track to skip to
"""
- current_song_path = self._get_song_dbus_path()
- position = self._path_list.index(current_song_path)
- goto_index = self._path_list.index(path)
- song_offset = goto_index - position
# FIXME: Dropped this for core rewrite.
+ pass
+ # current_song_path = self._get_song_dbus_path()
+ # position = self._path_list.index(current_song_path)
+ # goto_index = self._path_list.index(path)
+ # song_offset = goto_index - position
# self._player.play(song_offset=song_offset)
def _track_list_replaced(self, tracks, current_song):
diff --git a/gnomemusic/player.py b/gnomemusic/player.py
index 1d8f7c39..fe8ef8dc 100644
--- a/gnomemusic/player.py
+++ b/gnomemusic/player.py
@@ -653,8 +653,8 @@ class Player(GObject.GObject):
# playlists here but removing it may introduce
# a bug. So, we keep it for the time being.
playlists.update_all_smart_playlists()
- grilo.bump_play_count(current_song)
- grilo.set_last_played(current_song)
+ current_song.bump_play_count()
+ current_song.set_last_played()
@log
def _on_repeat_setting_changed(self, settings, value):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]