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



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

    Move tag retrieval initiation to CoreSong

 gnomemusic/coregrilo.py                           |  24 ++--
 gnomemusic/coresong.py                            |  14 ++
 gnomemusic/grilowrappers/grlmusicbrainzwrapper.py | 165 ----------------------
 gnomemusic/widgets/tageditordialog.py             |   6 +-
 4 files changed, 30 insertions(+), 179 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 4d6a59ab..45113066 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -32,8 +32,6 @@ from gnomemusic.grilowrappers.grlchromaprintwrapper import (
     GrlChromaprintWrapper)
 from gnomemusic.grilowrappers.grlsearchwrapper import GrlSearchWrapper
 from gnomemusic.grilowrappers.grltrackerwrapper import GrlTrackerWrapper
-from gnomemusic.grilowrappers.grlmusicbrainzwrapper import (
-    GrlMusicbrainzWrapper)
 from gnomemusic.trackerwrapper import TrackerState, TrackerWrapper
 
 
@@ -191,14 +189,6 @@ class CoreGrilo(GObject.GObject):
         for wrapper in self._wrappers.values():
             wrapper.populate_album_disc_songs(media, discnr, callback)
 
-    def get_tags_from_musicbrainz(self, media, callback):
-        """Retrieves the metadata keys of media
-
-        :param Grl.Media media: A Grilo media item
-        :param function callback: Function called after metadata retrieval
-        """
-        return self._musicbrainz.get_song_tags(media, callback)
-
     def _store_metadata(self, source, media, key):
         """Convenience function to store metadata
 
@@ -271,3 +261,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..32d12714 100644
--- a/gnomemusic/widgets/tageditordialog.py
+++ b/gnomemusic/widgets/tageditordialog.py
@@ -25,7 +25,7 @@
 import logging
 from gettext import gettext as _
 
-from gi.repository import Grl, Gtk, Gio, GObject, GLib
+from gi.repository import Gtk, Gio, GObject, GLib
 
 from gnomemusic.albumartcache import Art
 from gnomemusic.widgets.notificationspopup import TagEditorNotification
@@ -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]