[gnome-music/wip/process-media-art: 2/2] albumArtCache: Convert downloaded media covers to JPEG
- From: Arnel A. Borja <arnelborja src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-music/wip/process-media-art: 2/2] albumArtCache: Convert downloaded media covers to JPEG
- Date: Wed, 16 Apr 2014 16:25:04 +0000 (UTC)
commit 975514f4bbc264214f20aec0b5cd1d5128766f11
Author: Arnel A. Borja <arnelborja src gnome org>
Date: Thu Apr 17 00:05:06 2014 +0800
albumArtCache: Convert downloaded media covers to JPEG
Use libmediaart to save the media covers so that they will be converted
to JPEG.
https://bugzilla.gnome.org/show_bug.cgi?id=728338
gnomemusic/albumArtCache.py | 42 +++++++++++++++++++++++++++++++++++-------
gnomemusic/grilo.py | 13 ++++++++-----
2 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/gnomemusic/albumArtCache.py b/gnomemusic/albumArtCache.py
index e88db3a..c899d86 100644
--- a/gnomemusic/albumArtCache.py
+++ b/gnomemusic/albumArtCache.py
@@ -28,7 +28,7 @@
# delete this exception statement from your version.
-from gi.repository import Gtk, GdkPixbuf, Gio, GLib, Gdk, MediaArt
+from gi.repository import Gtk, GdkPixbuf, Gio, GLib, Gdk, MediaArt, Grl
from gettext import gettext as _
import cairo
from math import pi
@@ -151,8 +151,9 @@ class AlbumArtCache:
height = height or -1
path = MediaArt.get_path(artist, album, "album", None)[0]
if not os.path.exists(path):
- self.cached_thumb_not_found(item, album, artist, path, callback, itr)
- self.read_cached_pixbuf(path, width, height, callback, itr)
+ self.cached_thumb_not_found(item, width, height, callback, itr, artist, album, path)
+ else:
+ self.read_cached_pixbuf(path, width, height, callback, itr)
except Exception as e:
logger.warn("Error: %s" % e)
@@ -172,7 +173,7 @@ class AlbumArtCache:
logger.warn("Error: %s" % e)
@log
- def cached_thumb_not_found(self, item, album, artist, path, callback, itr):
+ def cached_thumb_not_found(self, item, width, height, callback, itr, artist, album, path):
try:
uri = item.get_thumbnail()
if uri is None:
@@ -183,8 +184,35 @@ class AlbumArtCache:
self.finish(None, path, callback, itr)
return
- src = Gio.File.new_for_uri(uri)
- dest = Gio.File.new_for_path(path)
- src.copy(dest, Gio.FileCopyFlags.OVERWRITE)
+ data = [item, width, height, callback, itr, artist, album, path, uri]
+ if item.get_url() is None:
+ # No URL, probably an album. Get a single song.
+ grilo.populate_album_songs(item.get_id(), self._on_album_item_found, 1, data)
+ else:
+ self.process_media_art(data)
+ except Exception as e:
+ logger.warn("Error: %s" % e)
+
+ @log
+ def _on_album_item_found(self, source, param, item, remaining, data):
+ try:
+ item_album, width, height, callback, itr, artist, album, path, uri = data
+ data[0] = item
+ self.process_media_art(data)
+ except Exception as e:
+ logger.warn("Error: %s" % e)
+
+ @log
+ def process_media_art(self, data):
+ try:
+ item, width, height, callback, itr, artist, album, path, uri = data
+ f = Gio.File.new_for_uri(uri)
+ success, contents, etag = f.load_contents(None)
+ streamInfo = f.query_info('standard::content-type', FileQueryInfoFlags.NONE, None)
+ contentType = streamInfo.get_content_type()
+
+ MediaArt.process(contents, contentType, MediaArt.Type.ALBUM,
+ artist, album, item.get_url())
+ self.read_cached_pixbuf(path, width, height, callback, itr)
except Exception as e:
logger.warn("Error: %s" % e)
diff --git a/gnomemusic/grilo.py b/gnomemusic/grilo.py
index d3ff075..202aef9 100644
--- a/gnomemusic/grilo.py
+++ b/gnomemusic/grilo.py
@@ -158,19 +158,22 @@ class Grilo(GObject.GObject):
self.populate_items(Query.SONGS, offset, callback, count)
@log
- def populate_album_songs(self, album_id, callback, count=-1):
- self.populate_items(Query.album_songs(album_id), 0, callback, count)
+ def populate_album_songs(self, album_id, callback, count=-1, data=None):
+ self.populate_items(Query.album_songs(album_id), 0, callback, count, data)
@log
- def populate_items(self, query, offset, callback, count=50):
+ def populate_items(self, query, offset, callback, count=50, data=None):
options = self.options.copy()
options.set_skip(offset)
if count != -1:
options.set_count(count)
def _callback(source, param, item, remaining, data, offset):
- callback(source, param, item, remaining)
- self.tracker.query(query, self.METADATA_KEYS, options, _callback, None)
+ if data:
+ callback(source, param, item, remaining, data)
+ else:
+ callback(source, param, item, remaining)
+ self.tracker.query(query, self.METADATA_KEYS, options, _callback, data)
@log
def _search_callback(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]