[gnome-music/songeditor-tracker3: 16/32] coresong: Add support to query musicbrainz tags



commit d13b47584597bf6d478d77d141adadcbc33900f2
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 62ce07a7..3ce407d5 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -276,3 +276,28 @@ class CoreGrilo(GObject.GObject):
         if "grl-tracker-source" in self._wrappers:
             self._wrappers["grl-tracker-source"].create_playlist(
                 playlist_title, callback)
+
+    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)
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index eaa67fc5..c329971a 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -143,3 +143,17 @@ class CoreSong(GObject.GObject):
         self.props.media.set_last_played(GLib.DateTime.new_now_utc())
         self._coregrilo.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._coregrilo.get_tags(self, callback)
+
+        self._coregrilo.get_chromaprint(self, chromaprint_retrieved)


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