[gnome-music/wip/mschraal/searchview-rework: 9/15] start of retrieving artist art



commit ce3ac9ce445a69e733c5e6987cf2116e90a81601
Author: Marinus Schraal <mschraal gnome org>
Date:   Fri Aug 2 13:03:25 2019 +0200

    start of retrieving artist art

 gnomemusic/albumartcache.py                   | 18 ++++++++++++++++++
 gnomemusic/coreartist.py                      | 10 ++++++++++
 gnomemusic/coregrilo.py                       |  4 ++++
 gnomemusic/grilowrappers/grltrackerwrapper.py | 17 +++++++++++++++++
 gnomemusic/widgets/artistsearchtile.py        |  8 ++++++++
 5 files changed, 57 insertions(+)
---
diff --git a/gnomemusic/albumartcache.py b/gnomemusic/albumartcache.py
index ec7ca541..bb7ec640 100644
--- a/gnomemusic/albumartcache.py
+++ b/gnomemusic/albumartcache.py
@@ -166,6 +166,24 @@ class DefaultIcon(GObject.GObject):
         return self._cache[(icon_type, art_size, scale)]
 
 
+class ArtistArt(GObject.GObject):
+
+    def __init__(self, coreartist):
+        super().__init__()
+
+        self._coreartist = coreartist
+
+        if self._in_cache():
+            return
+
+        # FIXME: Ugly.
+        grilo = self._coreartist._coremodel._grilo
+
+        grilo.get_artist_art(self._coreartist)
+
+    def _in_cache(self):
+        return False
+
 class Art(GObject.GObject):
     """Retrieves art for an album or song
 
diff --git a/gnomemusic/coreartist.py b/gnomemusic/coreartist.py
index fcb482bc..f6b58724 100644
--- a/gnomemusic/coreartist.py
+++ b/gnomemusic/coreartist.py
@@ -27,6 +27,7 @@ gi.require_version('Grl', '0.3')
 from gi.repository import Gio, Grl, GObject
 
 from gnomemusic import log
+from gnomemusic.albumartcache import ArtistArt
 import gnomemusic.utils as utils
 
 
@@ -44,6 +45,7 @@ class CoreArtist(GObject.GObject):
         self._coremodel = coremodel
         self._model = None
         self._selected = False
+        self._thumbnail = None
 
         self.update(media)
 
@@ -82,3 +84,11 @@ class CoreArtist(GObject.GObject):
         # is requested, it will trigger the filled model update as
         # well.
         self.props.model
+
+    @GObject.Property(type=str, default=None)
+    def thumbnail(self):
+        if self._thumbnail is None:
+            ArtistArt(self)
+
+        return ""
+
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index ee2448c4..940fc9fc 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -194,6 +194,10 @@ class CoreGrilo(GObject.GObject):
             self._wrappers["grl-tracker-source"].get_album_art_for_item(
                 coresong, callback)
 
+    def get_artist_art(self, coreartist):
+        if "grl-tracker-source" in self._wrappers:
+            self._wrappers["grl-tracker-source"].get_artist_art(coreartist)
+
     def stage_playlist_deletion(self, playlist):
         """Prepares playlist deletion.
 
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 8fa723c5..a44f014c 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -867,6 +867,23 @@ class GrlTrackerWrapper(GObject.GObject):
 
         return query
 
+    def get_artist_art(self, coreartist):
+        media = coreartist.props.media
+
+        def _resolve_cb(source, op_id, media, data, error):
+            print("operation finished")
+            print(media.get_artist())
+            print(media.get_thumbnail())
+            coreartist.props.media.set_thumbnail(media.get_thumbnail())
+
+        full_options = Grl.OperationOptions()
+        full_options.set_resolution_flags(
+            Grl.ResolutionFlags.FULL | Grl.ResolutionFlags.IDLE_RELAY)
+
+        self._source.resolve(
+            media, [Grl.METADATA_KEY_THUMBNAIL], full_options, _resolve_cb,
+            None)
+
     def stage_playlist_deletion(self, playlist):
         """Prepares playlist deletion.
 
diff --git a/gnomemusic/widgets/artistsearchtile.py b/gnomemusic/widgets/artistsearchtile.py
index c69b0da2..a3a9d341 100644
--- a/gnomemusic/widgets/artistsearchtile.py
+++ b/gnomemusic/widgets/artistsearchtile.py
@@ -70,6 +70,11 @@ class ArtistSearchTile(Gtk.FlowBoxChild):
         self._artist_label.props.label = artist
         # self._title_label.props.label = title
 
+        self._coreartist.connect(
+            "notify::thumbnail", self._on_thumbnail_changed)
+        # trigger
+        self._coreartist.props.thumbnail
+
         self.bind_property(
             "selected", self._check, "active",
             GObject.BindingFlags.BIDIRECTIONAL
@@ -86,6 +91,9 @@ class ArtistSearchTile(Gtk.FlowBoxChild):
 
         self.show()
 
+    def _on_thumbnail_changed(self, klass, data):
+        print("thumbnail changed", klass, data)
+
     @Gtk.Template.Callback()
     def _on_artist_event(self, evbox, event, data=None):
         modifiers = Gtk.accelerator_get_default_mod_mask()


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