[gnome-music/wip/mschraal/async-queue: 21/25] grltrackwrapper: Use AsyncQueue for storing art
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/async-queue: 21/25] grltrackwrapper: Use AsyncQueue for storing art
- Date: Sat, 14 Aug 2021 23:20:23 +0000 (UTC)
commit 41f23492f11e63b79cfc11719ce4042e28877b63
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..89f13c0ec 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__ = {
+ "finished": (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 start(self, coreobject, uri):
+ self._coreobject = coreobject
+
if (uri is None
or uri == ""):
self._coreobject.props.thumbnail = "generic"
+ self.emit("finished")
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("finished")
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("finished")
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("finished")
return
if isinstance(self._coreobject, CoreArtist):
@@ -137,6 +150,7 @@ class StoreArt(GObject.Object):
if not success:
self._coreobject.props.thumbnail = "generic"
+ self.emit("finished")
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("finished")
return
self._coreobject.props.media.set_thumbnail(cache_file.get_uri())
self._coreobject.props.thumbnail = cache_file.get_uri()
+ self.emit("finished")
+
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]