[gnome-music/wip/mschraal/tageditor-13feb2020: 46/53] coresong: Add support to query musicbrainz tags



commit 56f4dab34f86529d42ea050fa86ad150b2510234
Author: Sumaid Syed <sumaidsyed gmail com>
Date:   Sat Nov 23 14:53:17 2019 +0100

    coresong: Add support to query musicbrainz tags
    
    The following framework is used:
    1. Compute the chromaprint (a fingerprint) of the song with the
     chromaprint source
    2. Use the chromaprint to identify the song with the acoustid source

 gnomemusic/coregrilo.py | 25 +++++++++++++++++++++++++
 gnomemusic/coresong.py  | 14 ++++++++++++++
 2 files changed, 39 insertions(+)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 7098d1aa..6c8733f4 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -253,6 +253,31 @@ class CoreGrilo(GObject.GObject):
                 wrapper.create_playlist(playlist_title, callback)
                 break
 
+    def get_chromaprint(self, coresong, callback):
+        """Retrieve the chromaprint for the given CoreSong
+
+        :param CoreSong coresong: The CoreSong to chromaprint
+        :param callback: Metadata retrieval callback
+        """
+        if "grl-chromaprint" not in self._mb_wrappers:
+            callback(None)
+            return
+
+        self._mb_wrappers["grl-chromaprint"].get_chromaprint(
+            coresong, callback)
+
+    def get_tags(self, coresong, callback):
+        """Retrieve Musicbrainz tags for the given CoreSong
+
+        :param CoreSong coresong: The CoreSong to retrieve tags for
+        :param callback: Metadata retrieval callback
+        """
+        if "grl-acoustid" not in self._mb_wrappers:
+            callback(None)
+            return
+
+        self._mb_wrappers["grl-acoustid"].get_tags(coresong, callback)
+
     @GObject.Property(
         type=Grl.Registry, default=None, flags=GObject.ParamFlags.READABLE)
     def registry(self):
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index c2befcb6..f8d5d422 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -136,3 +136,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, callback)
+
+        self._grilo.get_chromaprint(self, chromaprint_retrieved)


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