[gnome-music/wip/mschraal/tageditor-13feb2020: 17/25] coregrilo: Handle a list of keys for writeback
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/tageditor-13feb2020: 17/25] coregrilo: Handle a list of keys for writeback
- Date: Thu, 13 Feb 2020 22:14:35 +0000 (UTC)
commit 92a76523d6ed32b98f12ca1d448ae12f4e763ecd
Author: Jean Felder <jfelder src gnome org>
Date: Sat Nov 23 16:37:53 2019 +0100
coregrilo: Handle a list of keys for writeback
Several metadata can be updated with a single call.
gnomemusic/coregrilo.py | 19 ++++++++++++-------
gnomemusic/coresong.py | 6 +++---
2 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 83b58d46..75c15527 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -180,29 +180,34 @@ class CoreGrilo(GObject.GObject):
for wrapper in self._wrappers.values():
wrapper.populate_album_disc_songs(media, discnr, callback)
- def _store_metadata(self, source, media, key):
+ def _store_metadata(self, source, media, keys):
"""Convenience function to store metadata
Wrap the metadata store call in a idle_add compatible form.
- :param source: A Grilo source object
- :param media: A Grilo media item
- :param key: A Grilo metadata key
+ :param Grl.Source source: A Grilo source object
+ :param Grl.Media media: A Grilo media item
+ :param list keys: A list of Grilo metadata keys
"""
# FIXME: Doing this async crashes.
try:
source.store_metadata_sync(
- media, [key], Grl.WriteFlags.NORMAL)
+ media, keys, Grl.WriteFlags.NORMAL)
except GLib.Error as error:
self._log.warning(
"Error {}: {}".format(error.domain, error.message))
return GLib.SOURCE_REMOVE
- def writeback(self, media, key):
+ def writeback(self, media, keys):
+ """Store the values associated with the keys.
+
+ :param Grl.Media media: A Grilo media item
+ :param list keys: A list of Grilo metadata keys
+ """
for wrapper in self._wrappers.values():
if media.get_source() == wrapper.source.props.source_id:
GLib.idle_add(
- self._store_metadata, wrapper.props.source, media, key)
+ self._store_metadata, wrapper.props.source, media, keys)
break
def search(self, text):
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index f8d5d422..ec8d2371 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -94,7 +94,7 @@ class CoreSong(GObject.GObject):
return
self.props.media.set_favourite(self._favorite)
- self._grilo.writeback(self.props.media, Grl.METADATA_KEY_FAVOURITE)
+ self._grilo.writeback(self.props.media, [Grl.METADATA_KEY_FAVOURITE])
@GObject.Property(type=bool, default=False)
def selected(self):
@@ -128,14 +128,14 @@ class CoreSong(GObject.GObject):
return
self.props.media.set_play_count(self.props.play_count + 1)
- self._grilo.writeback(self.props.media, Grl.METADATA_KEY_PLAY_COUNT)
+ self._grilo.writeback(self.props.media, [Grl.METADATA_KEY_PLAY_COUNT])
def set_last_played(self):
if not self._is_tracker:
return
self.props.media.set_last_played(GLib.DateTime.new_now_utc())
- self._grilo.writeback(self.props.media, Grl.METADATA_KEY_LAST_PLAYED)
+ self._grilo.writeback(self.props.media, [Grl.METADATA_KEY_LAST_PLAYED])
def query_musicbrainz_tags(self, callback):
"""Retrieves metadata keys for this CoreSong
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]