[gnome-music/wip/mschraal/file-exists-async: 5/13] songart: Make file exists check async
- From: Marinus Schraal <mschraal src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/mschraal/file-exists-async: 5/13] songart: Make file exists check async
- Date: Sat, 4 Sep 2021 22:17:13 +0000 (UTC)
commit 0f7a5c24554aba477137a0a27745eaebf32f78c8
Author: Marinus Schraal <mschraal gnome org>
Date: Tue Aug 17 00:22:55 2021 +0200
songart: Make file exists check async
gnomemusic/songart.py | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
---
diff --git a/gnomemusic/songart.py b/gnomemusic/songart.py
index 3311c42f7..cbd5bc164 100644
--- a/gnomemusic/songart.py
+++ b/gnomemusic/songart.py
@@ -26,13 +26,17 @@ import gi
gi.require_version("MediaArt", "2.0")
from gi.repository import GObject, MediaArt
+from gnomemusic.asyncqueue import AsyncQueue
from gnomemusic.embeddedart import EmbeddedArt
+from gnomemusic.fileexistsasync import FileExistsAsync
class SongArt(GObject.GObject):
"""SongArt retrieval object
"""
+ _async_queue = AsyncQueue()
+
def __init__(self, application, coresong):
"""Initialize SongArt
@@ -41,32 +45,35 @@ class SongArt(GObject.GObject):
"""
super().__init__()
- self._application = application
self._coresong = coresong
+ self._coregrilo = application.props.coregrilo
self._album = self._coresong.props.album
self._artist = self._coresong.props.artist
- if self._in_cache():
- return
-
- embedded = EmbeddedArt()
- embedded.connect("art-found", self._on_embedded_art_found)
- embedded.query(coresong, self._album)
+ self._in_cache()
def _on_embedded_art_found(self, embeddedart, found):
if found:
self._in_cache()
else:
- self._application.props.coregrilo.get_song_art(self._coresong)
+ self._coregrilo.get_song_art(self._coresong)
def _in_cache(self):
success, thumb_file = MediaArt.get_file(
self._artist, self._album, "album")
- if (not success
- or not thumb_file.query_exists()):
+ if not success:
self._coresong.props.thumbnail = "generic"
- return False
+ return
- self._coresong.props.thumbnail = thumb_file.get_uri()
+ def on_file_exists_async_finished(obj, result):
+ if result:
+ self._coresong.props.thumbnail = thumb_file.get_uri()
+ else:
+ embedded = EmbeddedArt()
+ embedded.connect("art-found", self._on_embedded_art_found)
+ embedded.query(self._coresong, self._album)
- return True
+ file_exists_async = FileExistsAsync()
+ file_exists_async.connect(
+ "finished", on_file_exists_async_finished)
+ self._async_queue.queue(file_exists_async, thumb_file)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]