[gnome-music/wip/mschraal/tageditor: 2/3] Pass CoreSong around + docstrings



commit b241467d12c54c836fcba30b0ddf628f6ea9d520
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Nov 22 16:55:18 2019 +0100

    Pass CoreSong around + docstrings

 gnomemusic/coregrilo.py                           | 19 +++++++++++++++----
 gnomemusic/coresong.py                            |  4 ++--
 gnomemusic/grilowrappers/grlacoustidwrapper.py    | 12 +++++++++---
 gnomemusic/grilowrappers/grlchromaprintwrapper.py | 15 ++++++++++-----
 4 files changed, 36 insertions(+), 14 deletions(-)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 45113066..a91bbcf0 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -262,16 +262,27 @@ class CoreGrilo(GObject.GObject):
                 wrapper.create_playlist(playlist_title, callback)
                 break
 
-    def get_chromaprint(self, media, 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 len(self._mb_wrappers) != 2:
             callback(None)
             return
 
-        self._mb_wrappers["grl-chromaprint"].get_chromaprint(media, callback)
+        self._mb_wrappers["grl-chromaprint"].get_chromaprint(
+            coresong, callback)
 
-    def get_tags(self, media, 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 len(self._mb_wrappers) != 2:
             callback(None)
             return
 
-        self._mb_wrappers["grl-acoustid"].get_tags(media, callback)
+        self._mb_wrappers["grl-acoustid"].get_tags(coresong, callback)
diff --git a/gnomemusic/coresong.py b/gnomemusic/coresong.py
index b1dd64b3..d9330a92 100644
--- a/gnomemusic/coresong.py
+++ b/gnomemusic/coresong.py
@@ -192,6 +192,6 @@ class CoreSong(GObject.GObject):
                 callback(None)
                 return
 
-            self._grilo.get_tags(self.props.media, callback)
+            self._grilo.get_tags(self, callback)
 
-        self._grilo.get_chromaprint(self.props.media, chromaprint_retrieved)
+        self._grilo.get_chromaprint(self, chromaprint_retrieved)
diff --git a/gnomemusic/grilowrappers/grlacoustidwrapper.py b/gnomemusic/grilowrappers/grlacoustidwrapper.py
index c83058b3..7cccd7db 100644
--- a/gnomemusic/grilowrappers/grlacoustidwrapper.py
+++ b/gnomemusic/grilowrappers/grlacoustidwrapper.py
@@ -58,12 +58,18 @@ class GrlAcoustIDWrapper(GObject.GObject):
         self._fingerprint_key = self._grilo._registry.lookup_metadata_key(
             "chromaprint")
 
-    def get_tags(self, media, callback):
+    def get_tags(self, coresong, callback):
+        """Retrieve Musicbrainz tag set for the given song
+
+        :param CoreSong coresong: The song to retrieve tags for
+        :param callback: Metadata retrieval callback
+        """
         options = Grl.OperationOptions()
         options.set_resolution_flags(Grl.ResolutionFlags.NORMAL)
 
-        query = "duration=" + str(media.get_duration())
-        query += "&fingerprint=" + media.get_string(self._fingerprint_key)
+        query = "duration=" + str(coresong.props.duration)
+        query += "&fingerprint=" + coresong.props.media.get_string(
+            self._fingerprint_key)
 
         def acoustid_resolved(source, op_id, media, count, callback, error):
             if error:
diff --git a/gnomemusic/grilowrappers/grlchromaprintwrapper.py 
b/gnomemusic/grilowrappers/grlchromaprintwrapper.py
index 2e02ea4f..a108cdf1 100644
--- a/gnomemusic/grilowrappers/grlchromaprintwrapper.py
+++ b/gnomemusic/grilowrappers/grlchromaprintwrapper.py
@@ -65,14 +65,19 @@ class GrlChromaprintWrapper(GObject.GObject):
             Grl.METADATA_KEY_DURATION
         ]
 
-    def get_chromaprint(self, media, callback):
+    def get_chromaprint(self, coresong, callback):
+        """Retrieve Chromaprint value
+
+        :param CoreSong coresong: The song to chromaprint
+        :param callback: Metadata retrieval callback
+        """
         if self._fingerprint_key == Grl.METADATA_KEY_INVALID:
             callback(None)
             return
 
-        chromaprint = media.get_string(self._fingerprint_key)
+        chromaprint = coresong.props.media.get_string(self._fingerprint_key)
         if chromaprint is not None:
-            callback(media)
+            callback(coresong.props.media)
             return
 
         options = Grl.OperationOptions()
@@ -89,5 +94,5 @@ class GrlChromaprintWrapper(GObject.GObject):
             callback(media)
 
         self._source.resolve(
-            media, self._METADATA_KEYS, options, chromaprint_resolved,
-            callback)
+            coresong.props.media, self._METADATA_KEYS, options,
+            chromaprint_resolved, callback)


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