[gnome-music/wip/mschraal/coresong-thumbnail-prop: 4/8] Simple cache



commit 52875a452845b0c684bda832a8563bb0cc021e39
Author: Marinus Schraal <mschraal gnome org>
Date:   Thu Nov 28 15:44:53 2019 +0100

    Simple cache

 gnomemusic/corealbum.py          | 19 +++++++++++++++++--
 gnomemusic/widgets/albumcover.py | 10 ++++++++++
 2 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/gnomemusic/corealbum.py b/gnomemusic/corealbum.py
index 24517658..5b2cc481 100644
--- a/gnomemusic/corealbum.py
+++ b/gnomemusic/corealbum.py
@@ -23,8 +23,8 @@
 # delete this exception statement from your version.
 
 import gi
-gi.require_version("Grl", "0.3")
-from gi.repository import Gio, Grl, GObject
+gi.require_versions({"Grl": "0.3", "MediaArt": "2.0"})
+from gi.repository import Gio, Grl, GObject, MediaArt
 
 import gnomemusic.utils as utils
 
@@ -122,8 +122,23 @@ class CoreAlbum(GObject.GObject):
         if self._thumbnail == None:
             self._thumbnail = "loading"
 
+            self._in_cache()
+
         return self._thumbnail
 
     @thumbnail.setter
     def thumbnail(self, value):
+        if self._thumbnail == value:
+            return
+
         self._thumbnail = value
+
+    def _in_cache(self):
+        success, thumb_file = MediaArt.get_file(
+            self.props.artist, self.props.title, "album")
+
+        if (not success
+                or not thumb_file.query_exists()):
+            return False
+
+        self.props.thumbnail = thumb_file.get_path()
diff --git a/gnomemusic/widgets/albumcover.py b/gnomemusic/widgets/albumcover.py
index 7b9cfaa7..1b2d74e5 100644
--- a/gnomemusic/widgets/albumcover.py
+++ b/gnomemusic/widgets/albumcover.py
@@ -100,6 +100,12 @@ class AlbumCover(Gtk.FlowBoxChild):
         self._update_cover_id = self._cover_stack.connect(
             "updated", self._on_cover_stack_updated)
 
+        self._corealbum.connect(
+            "notify::thumbnail", self._on_thumbnail_changed)
+
+    def _on_thumbnail_changed(self, klass, param):
+        print(self._corealbum.props.title, self._corealbum.props.thumbnail)
+
     def retrieve(self):
         """Start retrieving the actual album cover
 
@@ -109,6 +115,10 @@ class AlbumCover(Gtk.FlowBoxChild):
         if self._retrieved:
             return
 
+        print(
+            "retrieve", self._corealbum.props.title,
+            self._corealbum.props.thumbnail)
+
         self._retrieved = True
         self._cover_stack.update(self._corealbum)
 


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