[gnome-music/wip/mschraal/async-queue: 4/8] grltrackwrapper: Use AsyncQueue for storing art




commit f85b9efba86f01792c6fd1bf27975758ca04688c
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Aug 11 14:17:30 2021 +0200

    grltrackwrapper: Use AsyncQueue for storing art
    
    Use AsyncQueue for storing art.

 gnomemusic/grilowrappers/grltrackerwrapper.py | 11 ++++++++---
 gnomemusic/storeart.py                        | 21 +++++++++++++++++++--
 2 files changed, 27 insertions(+), 5 deletions(-)
---
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index cd888067f..c78a7cd04 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -30,6 +30,7 @@ import gi
 gi.require_versions({"Gfm": "0.1", "Grl": "0.3", "Tracker": "3.0"})
 from gi.repository import Gfm, Gio, Grl, GLib, GObject, Tracker
 
+from gnomemusic.asyncqueue import AsyncQueue
 from gnomemusic.corealbum import CoreAlbum
 from gnomemusic.coreartist import CoreArtist
 from gnomemusic.coredisc import CoreDisc
@@ -103,6 +104,7 @@ class GrlTrackerWrapper(GObject.GObject):
         """
         super().__init__()
 
+        self._async_queue = AsyncQueue()
         self._application: Application = application
         cm: CoreModel = application.props.coremodel
         self._log: MusicLogger = application.props.log
@@ -1219,7 +1221,8 @@ class GrlTrackerWrapper(GObject.GObject):
                 coresong.props.thumbnail = "generic"
                 return
 
-            StoreArt(coresong, queried_media.get_thumbnail())
+            self._async_queue.queue(
+                StoreArt(), coresong, queried_media.get_thumbnail())
 
         song_id: str = media.get_id()
         query: str = self._get_album_for_media_id_query(song_id)
@@ -1248,7 +1251,8 @@ class GrlTrackerWrapper(GObject.GObject):
                 corealbum.props.thumbnail = "generic"
                 return
 
-            StoreArt(corealbum, queried_media.get_thumbnail())
+            self._async_queue.queue(
+                StoreArt(), corealbum, queried_media.get_thumbnail())
 
         album_id: str = media.get_id()
         query: str = self._get_album_for_media_id_query(album_id, False)
@@ -1279,7 +1283,8 @@ class GrlTrackerWrapper(GObject.GObject):
                 coreartist.props.thumbnail = "generic"
                 return
 
-            StoreArt(coreartist, resolved_media.get_thumbnail())
+            self._async_queue.queue(
+                StoreArt(), coreartist, resolved_media.get_thumbnail())
 
         self.props.source.resolve(
             media, [Grl.METADATA_KEY_THUMBNAIL], self._full_options,
diff --git a/gnomemusic/storeart.py b/gnomemusic/storeart.py
index 368d61b23..678a8ae23 100644
--- a/gnomemusic/storeart.py
+++ b/gnomemusic/storeart.py
@@ -36,20 +36,30 @@ class StoreArt(GObject.Object):
     """Stores Art in the MediaArt cache.
     """
 
-    def __init__(self, coreobject, uri):
+    __gsignals__ = {
+        "result": (GObject.SignalFlags.RUN_FIRST, None, ())
+    }
+
+    def __init__(self):
         """Initialize StoreArtistArt
 
         :param coreobject: The CoreArtist or CoreAlbum to store art for
         :param string uri: The art uri
         """
-        self._coreobject = coreobject
+        super().__init__()
+
+        self._coreobject = None
 
         self._log = MusicLogger()
         self._soup_session = Soup.Session.new()
 
+    def query(self, coreobject, uri):
+        self._coreobject = coreobject
+
         if (uri is None
                 or uri == ""):
             self._coreobject.props.thumbnail = "generic"
+            self.emit("result")
             return
 
         cache_dir = GLib.build_filenamev(
@@ -70,6 +80,7 @@ class StoreArt(GObject.Object):
                 self._log.warning(
                     "Error: {}, {}".format(error.domain, error.message))
                 self._coreobject.props.thumbnail = "generic"
+                self.emit("result")
                 return
 
         msg = Soup.Message.new("GET", uri)
@@ -88,6 +99,7 @@ class StoreArt(GObject.Object):
             self._log.warning(
                 "Error: {}, {}".format(error.domain, error.message))
             self._coreobject.props.thumbnail = "generic"
+            self.emit("result")
             return
 
         istream = Gio.MemoryInputStream.new_from_bytes(
@@ -119,6 +131,7 @@ class StoreArt(GObject.Object):
             self._log.warning(
                 "Error: {}, {}".format(error.domain, error.message))
             self._coreobject.props.thumbnail = "generic"
+            self.emit("result")
             return
 
         if isinstance(self._coreobject, CoreArtist):
@@ -137,6 +150,7 @@ class StoreArt(GObject.Object):
 
         if not success:
             self._coreobject.props.thumbnail = "generic"
+            self.emit("result")
             return
 
         try:
@@ -146,11 +160,14 @@ class StoreArt(GObject.Object):
             self._log.warning(
                 "Error: {}, {}".format(error.domain, error.message))
             self._coreobject.props.thumbnail = "generic"
+            self.emit("result")
             return
 
         self._coreobject.props.media.set_thumbnail(cache_file.get_uri())
         self._coreobject.props.thumbnail = cache_file.get_uri()
 
+        self.emit("result")
+
         tmp_file.delete_async(
             GLib.PRIORITY_LOW, None, self._delete_callback, None)
 


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