def query(self, media): """Start the remote query :param Grl.Media media: The media object to search art for """ self._album = utils.get_album_title(media) self._artist = utils.get_artist_name(media) # FIXME: It seems this Grilo query does not always return, # especially on queries with little info. grilo.get_album_art_for_item(media, self._remote_album_art)
def cached_thumb_not_found(self, item, width, height, path, callback, itr, artist, album): try: uri = item.get_thumbnail() if uri is None: grilo.get_album_art_for_item(item, self.album_art_for_item_callback, (item, width, height, path, callback, itr, artist, album)) return t = Thread(target=self.download_worker, args=(item, width, height, path, callback, itr, artist, album, uri)) self.thread_queue.put(t) except Exception as e: logger.warn("Error: %s" % e)
def cached_thumb_not_found(self, item, width, height, path, callback, itr, artist, album): try: uri = item.get_thumbnail() if uri is None: grilo.get_album_art_for_item(item, self.album_art_for_item_callback, (item, width, height, path, callback, itr, artist, album)) return self.download_thumb(item, width, height, path, callback, itr, artist, album, uri) except Exception as e: logger.warn("Error: %s", e) self.finish(item, None, None, callback, itr, width, height, artist, album)
def cached_thumb_not_found(self, item, width, height, path, callback, itr, artist, album): try: uri = item.get_thumbnail() if uri is None: grilo.get_album_art_for_item(item, self.album_art_for_item_callback, (item, width, height, path, callback, itr, artist, album)) return t = Thread(target=self.download_worker, args=(item, width, height, path, callback, itr, artist, album, uri)) THREAD_QUEUE.append(t) self.emit('thread-added', len(THREAD_QUEUE) - 1) except Exception as e: logger.warn("Error: %s", e) self.finish(item, None, None, callback, itr, width, height, artist, album)
def cached_thumb_not_found(self, item, width, height, path, callback, itr, artist, album): try: uri = item.get_thumbnail() if uri is None: if path in self.queue: self.queue.remove(path) grilo.get_album_art_for_item(item, self.album_art_for_item_callback, (item, width, height, path, callback, itr, artist, album)) return start_new_thread(self.download_worker, (item, width, height, path, callback, itr, artist, album, uri)) except Exception as e: logger.warn("Error: %s" % e)
def query(self, media): """Start the remote query :param Grl.Media media: The media object to search art for """ self._album = utils.get_album_title(media) self._artist = utils.get_artist_name(media) self._media = media if not grilo.props.cover_sources: self.emit('no-remote-sources') grilo.connect('notify::cover-sources', self._on_grilo_cover_sources_changed) else: # FIXME: It seems this Grilo query does not always return, # especially on queries with little info. grilo.get_album_art_for_item(media, self._remote_album_art)
def query(self, media): """Start the remote query :param Grl.Media media: The media object to search art for """ self._album = utils.get_album_title(media) self._artist = utils.get_artist_name(media) self._media = media if not grilo.props.cover_sources: self.emit('no-remote-sources') grilo.connect( 'notify::cover-sources', self._on_grilo_cover_sources_changed) else: # FIXME: It seems this Grilo query does not always return, # especially on queries with little info. grilo.get_album_art_for_item(media, self._remote_album_art)
def _on_grilo_cover_sources_changed(self, klass, data): if grilo.props.cover_sources: grilo.get_album_art_for_item(self._media, self._remote_album_art)
def _lookup_remote(self, item, callback, itr, art_size): """Lookup remote art Lookup remote art through Grilo and if found copy locally. Call _lookup_local to finish retrieving suitable art. """ album = utils.get_album_title(item) artist = utils.get_artist_name(item) @log def delete_cb(src, result, data): try: src.delete_finish(result) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) @log def splice_cb(src, result, data): tmp_file, iostream = data try: src.splice_finish(result) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return success, cache_path = MediaArt.get_path(artist, album, "album") try: # FIXME: I/O blocking MediaArt.file_to_jpeg(tmp_file.get_path(), cache_path) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return art_retrieved(True) tmp_file.delete_async(GLib.PRIORITY_LOW, None, delete_cb, None) @log def async_read_cb(src, result, data): try: istream = src.read_finish(result) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return try: [tmp_file, iostream] = Gio.File.new_tmp() except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return ostream = iostream.get_output_stream() # FIXME: Passing the iostream here, otherwise it gets # closed. PyGI specific issue? ostream.splice_async( istream, Gio.OutputStreamSpliceFlags.CLOSE_SOURCE | Gio.OutputStreamSpliceFlags.CLOSE_TARGET, GLib.PRIORITY_LOW, None, splice_cb, [tmp_file, iostream]) @log def album_art_for_item_cb(source, param, item, count, error): if error: logger.warn("Grilo error %s", error) art_retrieved(False) return thumb_uri = item.get_thumbnail() if thumb_uri is None: art_retrieved(False) return src = Gio.File.new_for_uri(thumb_uri) src.read_async(GLib.PRIORITY_LOW, None, async_read_cb, None) @log def art_retrieved(result): if not result: if artist not in self.blacklist: self.blacklist[artist] = [] album_stripped = MediaArt.strip_invalid_entities(album) self.blacklist[artist].append(album_stripped) self.lookup(item, art_size, callback, itr) grilo.get_album_art_for_item(item, album_art_for_item_cb)
def _lookup_remote(self, item, callback, itr, art_size): """Lookup remote art Lookup remote art through Grilo and if found copy locally. Call _lookup_local to finish retrieving suitable art. """ album = utils.get_album_title(item) artist = utils.get_artist_name(item) @log def delete_cb(src, result, data): try: src.delete_finish(result) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) @log def splice_cb(src, result, data): tmp_file, iostream = data try: src.splice_finish(result) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return success, cache_path = MediaArt.get_path(artist, album, "album") try: # FIXME: I/O blocking MediaArt.file_to_jpeg(tmp_file.get_path(), cache_path) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return art_retrieved(True) tmp_file.delete_async(GLib.PRIORITY_LOW, None, delete_cb, None) @log def async_read_cb(src, result, data): try: istream = src.read_finish(result) except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return try: [tmp_file, iostream] = Gio.File.new_tmp() except Exception as err: logger.warn("Error: %s, %s", err.__class__, err) art_retrieved(False) return ostream = iostream.get_output_stream() # FIXME: Passing the iostream here, otherwise it gets # closed. PyGI specific issue? ostream.splice_async(istream, Gio.OutputStreamSpliceFlags.CLOSE_SOURCE | Gio.OutputStreamSpliceFlags.CLOSE_TARGET, GLib.PRIORITY_LOW, None, splice_cb, [tmp_file, iostream]) @log def album_art_for_item_cb(source, param, item, count, error): if error: logger.warn("Grilo error %s", error) art_retrieved(False) return thumb_uri = item.get_thumbnail() if thumb_uri is None: art_retrieved(False) return src = Gio.File.new_for_uri(thumb_uri) src.read_async(GLib.PRIORITY_LOW, None, async_read_cb, None) @log def art_retrieved(result): if not result: if artist not in self.blacklist: self.blacklist[artist] = [] album_stripped = MediaArt.strip_invalid_entities(album) self.blacklist[artist].append(album_stripped) self.lookup(item, art_size, callback, itr) grilo.get_album_art_for_item(item, album_art_for_item_cb)