[gnome-music/wip/mschraal/grilo-writeback-sync-fix: 1/2] grilo: Use idle_add for writeback functions
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/grilo-writeback-sync-fix: 1/2] grilo: Use idle_add for writeback functions
- Date: Thu, 2 May 2019 14:10:20 +0000 (UTC)
commit f55eeea9ae46c063cac2b2671cb412a594dc7872
Author: Marinus Schraal <mschraal gnome org>
Date: Wed Aug 29 23:11:10 2018 +0200
grilo: Use idle_add for writeback functions
The GStreamer clock stops ticking as soon as a Grilo writeback is
triggered. This does not pose as an immediate problem, as it is currently
only relied upon for scrobbling, triggering Tracker writeback and passing
on the clock-tick. However, the former two are one-time events per song and
the latter is also provided by other means.
It will be a problem as soon as the pipeline and clock do not reset between
songs when gapless playback is introduced. The exact core of the problem is
unknown, but might be related to Grilo async handling: grilo#81.
Calling the Grilo writeback function in an idle_add seems to resolve the
issue until it is fixed upstream.
gnomemusic/grilo.py | 103 +++++++++++++++++++++++++++++++++-------------------
1 file changed, 65 insertions(+), 38 deletions(-)
---
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index 6a90dec7..7f3a3bd8 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -346,29 +346,6 @@ class Grilo(GObject.GObject):
callback(source, param, item, remaining, data)
self.tracker.query(query, self.METADATA_KEYS, options, _callback, data)
- @log
- def toggle_favorite(self, song_item):
- """Toggles favorite status for media item
-
- Toggles favorite status and writes it back to the tracker store
- :param song_item: A Grilo media item
- """
- if song_item.get_favourite():
- # For now keep unsetting the lyrics to deal with how
- # previous versions dealt with favorites.
- song_item.set_lyrics("")
- song_item.set_favourite(False)
- else:
- song_item.set_favourite(True)
-
- # FIXME: We assume this is the tracker plugin.
- # FIXME: Doing this async crashes
- try:
- self.tracker.store_metadata_sync(
- song_item, [Grl.METADATA_KEY_FAVOURITE], Grl.WriteFlags.NORMAL)
- except GLib.Error as error:
- logger.warning("Error {}: {}".format(error.domain, error.message))
-
@log
def set_favorite(self, song_item, favorite):
"""Set the favorite status of a media item
@@ -450,16 +427,24 @@ class Grilo(GObject.GObject):
Adds one to the playcount and adds it to the tracker store
:param media: A Grilo media item
"""
+ def store_metadata(media):
+ # FIXME: We assume this is the tracker plugin.
+ # FIXME: Doing this async crashes.
+ try:
+ self.tracker.store_metadata_sync(
+ media, [Grl.METADATA_KEY_PLAY_COUNT], Grl.WriteFlags.NORMAL)
+ except GLib.Error as error:
+ logger.warning(
+ "Error {}: {}".format(error.domain, error.message))
+
+ return GLib.SOURCE_REMOVE
+
count = media.get_play_count()
media.set_play_count(count + 1)
-
- # FIXME: We assume this is the tracker plugin.
- # FIXME: Doing this async crashes
- try:
- self.tracker.store_metadata_sync(
- media, [Grl.METADATA_KEY_PLAY_COUNT], Grl.WriteFlags.NORMAL)
- except GLib.Error as error:
- logger.warning("Error {}: {}".format(error.domain, error.message))
+ # 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(store_metadata, media)
@log
def set_last_played(self, media):
@@ -468,14 +453,56 @@ class Grilo(GObject.GObject):
Sets the last played date-time for the media.
:param media: A Grilo media item
"""
+ def store_metadata(media):
+ # FIXME: We assume this is the tracker plugin.
+ # FIXME: Doing this async crashes.
+ try:
+ self.tracker.store_metadata_sync(
+ media, [Grl.METADATA_KEY_LAST_PLAYED],
+ Grl.WriteFlags.NORMAL)
+ except GLib.Error as error:
+ logger.warning(
+ "Error {}: {}".format(error.domain, error.message))
+
+ return GLib.SOURCE_REMOVE
+
media.set_last_played(GLib.DateTime.new_now_utc())
- # FIXME: We assume this is the tracker plugin.
- # FIXME: Doing this async crashes
- try:
- self.tracker.store_metadata_sync(
- media, [Grl.METADATA_KEY_LAST_PLAYED], Grl.WriteFlags.NORMAL)
- except GLib.Error as error:
- logger.warning("Error {}: {}".format(error.domain, error.message))
+ # 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(store_metadata, media)
+
+ @log
+ def toggle_favorite(self, media):
+ """Toggles favorite status for media item
+
+ Toggles favorite status and writes it back to the tracker store
+ :param media: A Grilo media item
+ """
+ def store_metadata(media):
+ # FIXME: We assume this is the tracker plugin.
+ # FIXME: Doing this async crashes.
+ try:
+ self.tracker.store_metadata_sync(
+ media, [Grl.METADATA_KEY_FAVOURITE], Grl.WriteFlags.NORMAL)
+ except GLib.Error as error:
+ logger.warning(
+ "Error {}: {}".format(error.domain, error.message))
+
+ return GLib.SOURCE_REMOVE
+
+ 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(store_metadata, media)
@log
def songs_available(self, callback):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]