[gnome-music/wip/carlosg/tracker3: 27/39] coresong: Add support to query musicbrainz tags




commit 662ade534be74e0dd3a59e0aacb245cbaed23e12
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 b7dadc64..3927f338 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -326,3 +326,28 @@ class CoreGrilo(GObject.GObject):
         if "grl-tracker3-source" in self._wrappers:
             self._wrappers["grl-tracker3-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 6099b3d5..f63a56a9 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -168,3 +168,17 @@ class CoreSong(GObject.GObject):
         self.props.media.set_last_played(GLib.DateTime.new_now_utc())
         self._coregrilo.writeback_tracker(
             self.props.media, "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]