def _on_button_clicked(self, button): """ Show file chooser @param button as Gtk.button """ dialog = Gtk.FileChooserDialog() dialog.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL) dialog.add_buttons(Gtk.STOCK_OPEN, Gtk.ResponseType.OK) dialog.set_transient_for(Lp().window) self._close_popover() response = dialog.run() if response == Gtk.ResponseType.OK: try: f = Gio.File.new_for_path(dialog.get_filename()) (status, data, tag) = f.load_contents() if not status: raise if self._album is not None: Lp().art.save_album_artwork(data, self._album.id) Lp().art.clean_album_cache(self._album) Lp().art.album_artwork_update(self._album.id) else: for suffix in ["lastfm", "wikipedia", "spotify"]: InfoCache.uncache_artwork(self._artist, suffix, button.get_scale_factor()) InfoCache.cache(self._artist, None, data, suffix) self._streams = {} except Exception as e: print("ArtworkSearch::_on_button_clicked():", e) dialog.destroy()
def set_content(self, prefix, content, image_url, suffix): """ populate widget with content @param prefix as str @param content as str @param image url as str @param suffix as str @thread safe """ try: data = None stream = None if content is not None: if image_url is not None: f = Gio.File.new_for_uri(image_url) (status, data, tag) = f.load_contents(self._cancel) if status: stream = Gio.MemoryInputStream.new_from_data(data, None) else: data = None InfoCache.cache(prefix, content, data, suffix) GLib.idle_add(self._set_content, content, stream) except Exception as e: print("InfoContent::set_content: %s" % e)
def _on_reset_confirm(self, button): """ Reset cover @param button as Gtk.Button """ self._infobar.hide() if self._album is not None: Lp().art.remove_album_artwork(self._album) Lp().art.clean_album_cache(self._album) Lp().art.emit('album-artwork-changed', self._album.id) else: for suffix in ["lastfm", "wikipedia", "spotify"]: InfoCache.uncache_artwork(self._artist, suffix, button.get_scale_factor()) InfoCache.cache(self._artist, None, None, suffix) Lp().art.emit('artist-artwork-changed', self._artist) self._close_popover()
def _on_activate(self, flowbox, child): """ Use pixbuf as cover Reset cache and use player object to announce cover change """ data = self._datas[child.get_child()] self._close_popover() if self._album is not None: Lp().art.save_album_artwork(data, self._album.id) Lp().art.clean_album_cache(self._album) Lp().art.album_artwork_update(self._album.id) else: for suffix in ["lastfm", "wikipedia", "spotify"]: InfoCache.uncache_artwork(self._artist, suffix, flowbox.get_scale_factor()) InfoCache.cache(self._artist, None, data, suffix) self._streams = {}
def _cache_artists_art(self): """ Cache artwork for all artists """ # We create cache if needed InfoCache.init() # Then cache artwork for lastfm/wikipedia/spotify # We cache content as the same time # TODO Make this code more generic for (artist_id, artist) in Lp().artists.get([]): debug("ArtDownloader::_cache_artists_art(): %s" % artist) if not Gio.NetworkMonitor.get_default().get_network_available() or\ InfoCache.exists_in_cache(artist): continue if Lp().lastfm is not None: try: (url, content) = Lp().lastfm.get_artist_infos(artist) if url is not None: s = Gio.File.new_for_uri(url) (status, data, tag) = s.load_contents() if status: InfoCache.cache(artist, content, data, "lastfm") except: InfoCache.cache(artist, None, None, "lastfm") if ArtDownloader.Wikipedia is not None: try: wp = ArtDownloader.Wikipedia() (url, content) = wp.get_page_infos(artist) if url is not None: s = Gio.File.new_for_uri(url) (status, data, tag) = s.load_contents() if status: InfoCache.cache(artist, content, data, "wikipedia") except: InfoCache.cache(artist, None, None, "wikipedia") url = self.get_spotify_artist_artwork(artist) if url is not None: s = Gio.File.new_for_uri(url) (status, data, tag) = s.load_contents() if status: InfoCache.cache(artist, None, data, "spotify") self._cache_artists_running = False
def _on_activate(self, flowbox, child): """ Use pixbuf as cover Reset cache and use player object to announce cover change """ try: data = self._datas[child.get_child()] self._close_popover() if self._album is not None: Lp().art.save_album_artwork(data, self._album.id) else: for suffix in ["lastfm", "wikipedia", "spotify"]: InfoCache.uncache_artwork(self._artist, suffix, flowbox.get_scale_factor()) InfoCache.cache(self._artist, None, data, suffix) Lp().art.emit('artist-artwork-changed', self._artist) self._streams = {} except: self._infobar_label.set_text(_("Reset artwork?")) self._infobar.show() # GTK 3.20 https://bugzilla.gnome.org/show_bug.cgi?id=710888 self._infobar.queue_resize()