[gnome-music/wip/mschraal/tageditor: 15/16] Move tag retrieval initiation to CoreSong



commit 8897e04b05da8a2248cd1da5d3169ec470d3e169
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Nov 22 16:26:33 2019 +0100

    Move tag retrieval initiation to CoreSong

 gnomemusic/coregrilo.py               | 14 ++++++++++++++
 gnomemusic/coresong.py                | 14 ++++++++++++++
 gnomemusic/widgets/tageditordialog.py |  4 +---
 3 files changed, 29 insertions(+), 3 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 4d6a59ab..a2dd2c6b 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -271,3 +271,17 @@ class CoreGrilo(GObject.GObject):
             if wrapper.source.props.source_id == "grl-tracker-source":
                 wrapper.create_playlist(playlist_title, callback)
                 break
+
+    def get_chromaprint(self, media, callback):
+        if len(self._mb_wrappers) != 2:
+            callback(None)
+            return
+
+        self._mb_wrappers["grl-chromaprint"].get_chromaprint(media, callback)
+
+    def get_tags(self, media, callback):
+        if len(self._mb_wrappers) != 2:
+            callback(None)
+            return
+
+        self._mb_wrappers["grl-acoustid"].get_tags(media, callback)
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index 07f3b2e9..b1dd64b3 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -181,3 +181,17 @@ class CoreSong(GObject.GObject):
 
         self.props.media.set_last_played(GLib.DateTime.new_now_utc())
         self._grilo.writeback(self.props.media, Grl.METADATA_KEY_LAST_PLAYED)
+
+    def query_musicbrainz_tags(self, callback):
+        """Retrieves metadata keys for this Coresong
+
+        :param callback: Metadata retrieval callback
+        """
+        def chromaprint_retrieved(media):
+            if not media:
+                callback(None)
+                return
+
+            self._grilo.get_tags(self.props.media, callback)
+
+        self._grilo.get_chromaprint(self.props.media, chromaprint_retrieved)
diff --git a/gnomemusic/widgets/tageditordialog.py b/gnomemusic/widgets/tageditordialog.py
index 4f3c9cea..c032fb48 100644
--- a/gnomemusic/widgets/tageditordialog.py
+++ b/gnomemusic/widgets/tageditordialog.py
@@ -140,9 +140,7 @@ class TagEditorDialog(Gtk.Dialog):
 
     def _search_tags(self):
         self._start_spinner(_("Fetching metadata…"))
-        new_media = Grl.Media.audio_new()
-        new_media.set_url(self._coresong.props.url)
-        self._grilo.get_tags_from_musicbrainz(new_media, self._tags_found)
+        self._coresong.query_musicbrainz_tags(self._tags_found)
 
     def _suggestion_sort_func(self, media):
         creation_date = media.get_creation_date()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]