[gnome-music/wip/mschraal/coresong-thumbnail-prop: 171/179] start of songart



commit 7c5cb239df9d1de1cecda89af475338fc9c1ed28
Author: Marinus Schraal <mschraal gnome org>
Date:   Wed Dec 18 10:07:25 2019 +0100

    start of songart

 gnomemusic/coregrilo.py                       |  8 ++++
 gnomemusic/grilowrappers/grltrackerwrapper.py | 23 ++++++++++
 gnomemusic/songart.py                         | 60 +++++++++++++++++++++++++++
 3 files changed, 91 insertions(+)
---
diff --git a/gnomemusic/coregrilo.py b/gnomemusic/coregrilo.py
index 1713a9d8..d9906926 100644
--- a/gnomemusic/coregrilo.py
+++ b/gnomemusic/coregrilo.py
@@ -209,6 +209,14 @@ class CoreGrilo(GObject.GObject):
                 self._wrappers[wrapper_id].get_album_art(corealbum)
                 break
 
+    def get_song_art(self, coresong):
+        source = coresong.props.media.get_source()
+
+        for wrapper_id in self._wrappers.keys():
+            if wrapper_id == source:
+                self._wrappers[wrapper_id].get_song_art(coresong)
+                break
+
     def get_artist_art(self, coreartist):
         if "grl-tracker-source" in self._wrappers:
             self._wrappers["grl-tracker-source"].get_artist_art(coreartist)
diff --git a/gnomemusic/grilowrappers/grltrackerwrapper.py b/gnomemusic/grilowrappers/grltrackerwrapper.py
index 3c8f3c69..90656002 100644
--- a/gnomemusic/grilowrappers/grltrackerwrapper.py
+++ b/gnomemusic/grilowrappers/grltrackerwrapper.py
@@ -886,6 +886,29 @@ class GrlTrackerWrapper(GObject.GObject):
             query, self.METADATA_THUMBNAIL_KEYS, full_options,
             art_retrieved_cb)
 
+    def get_song_art(self, coresong):
+        def art_retrieved_cb(source, op_id, media, data, error):
+            if error:
+                print("ERROR", error)
+                coresong.props.thumbnail = "generic"
+                return
+
+            StoreAlbumArt(self._album_ids[media.get_id()], media)
+
+        song_id = coresong.props.media.get_id()
+
+        query = self._get_album_for_song_id(song_id)
+
+        full_options = Grl.OperationOptions()
+        full_options.set_resolution_flags(
+            Grl.ResolutionFlags.FULL
+            | Grl.ResolutionFlags.IDLE_RELAY)
+        full_options.set_count(1)
+
+        self._source.query(
+            query, self.METADATA_THUMBNAIL_KEYS, full_options,
+            art_retrieved_cb)
+
     def get_album_art_for_item(self, coresong, callback):
         """Placeholder until we got a better solution
         """
diff --git a/gnomemusic/songart.py b/gnomemusic/songart.py
new file mode 100644
index 00000000..9fba1b30
--- /dev/null
+++ b/gnomemusic/songart.py
@@ -0,0 +1,60 @@
+# Copyright 2019 The GNOME Music developers
+#
+# GNOME Music is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# GNOME Music is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with GNOME Music; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# The GNOME Music authors hereby grant permission for non-GPL compatible
+# GStreamer plugins to be used and distributed together with GStreamer
+# and GNOME Music.  This permission is above and beyond the permissions
+# granted by the GPL license by which GNOME Music is covered.  If you
+# modify this code, you may extend this exception to your version of the
+# code, but you are not obligated to do so.  If you do not wish to do so,
+# delete this exception statement from your version.
+
+import gi
+gi.require_version("MediaArt", "2.0")
+from gi.repository import GObject, MediaArt
+
+
+class SongArt(GObject.GObject):
+
+    def __init__(self, coresong, coremodel):
+        """Initialize the song Art retrieval object
+
+        :param CoreSong coresong: The CoreSong to use
+        :param CoreModel coremodel: The CoreModel object
+        """
+        super().__init__()
+
+        self._coresong = coresong
+        self._artist = coresong.props.artist
+        self._title = coresong.props.title
+
+        if self._in_cache():
+            return
+
+        coremodel.props.grilo.get_song_art(coresong)
+
+    def _in_cache(self):
+        success, thumb_file = MediaArt.get_file(
+            self._artist, self._title, "album")
+
+        # FIXME: Make async.
+        if (not success
+                or not thumb_file.query_exists()):
+            return False
+
+        self._coresong.props.thumbnail = thumb_file.get_path()
+
+        return True


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