def artwork_set_image(self, filename, artist, album, path, info_img_only=False): # Note: filename arrives here is in FILESYSTEM_CHARSET, not UTF-8! if (self.status_is_play_or_pause() and self.songinfo and self.songinfo.get('artist') == artist and self.songinfo.get('album') == album): if os.path.exists(filename): # We use try here because the file might exist, but might # still be downloading or corrupt: try: pix = gtk.gdk.pixbuf_new_from_file(filename) except: # If we have a 0-byte file, it should mean that # sonata reset the image file. Otherwise, it's a # bad file and should be removed. if os.stat(filename).st_size != 0: misc.remove_file(filename) return self.currentpb = pix if not info_img_only: # Store in cache cache_key = library_set_data(artist=artist, album=album, path=path) self.set_library_artwork_cached_filename(cache_key, filename) # Artwork for tooltip, left-top of player: (pix1, w, h) = img.get_pixbuf_of_size(pix, 75) pix1 = self.artwork_apply_composite_case(pix1, w, h) pix1 = img.pixbuf_add_border(pix1) pix1 = img.pixbuf_pad(pix1, 77, 77) self.albumimage.set_from_pixbuf(pix1) self.artwork_set_tooltip_art(pix1) del pix1 # Artwork for library, if current song matches: self.library_set_image_for_current_song(cache_key) # Artwork for fullscreen self.fullscreen_cover_art_set_image() # Artwork for info tab: if self.info_imagebox_get_size_request()[0] == -1: fullwidth = self.notebook_get_allocation()[2] - 50 (pix2, w, h) = img.get_pixbuf_of_size(pix, fullwidth) else: (pix2, w, h) = img.get_pixbuf_of_size(pix, 150) pix2 = self.artwork_apply_composite_case(pix2, w, h) pix2 = img.pixbuf_add_border(pix2) self.info_image.set_from_pixbuf(pix2) del pix2 del pix self.lastalbumart = filename self.schedule_gc_collect()
def artwork_set_image(self, filename, artist, album, path, info_img_only=False): # Note: filename arrives here is in FILESYSTEM_CHARSET, not UTF-8! if self.artwork_is_for_playing_song(filename): if os.path.exists(filename): # We use try here because the file might exist, but might # still be downloading or corrupt: try: pix = gtk.gdk.pixbuf_new_from_file(filename) except: # If we have a 0-byte file, it should mean that # sonata reset the image file. Otherwise, it's a # bad file and should be removed. if os.stat(filename).st_size != 0: misc.remove_file(filename) return self.currentpb = pix if not info_img_only: # Store in cache cache_key = library_set_data(artist=artist, album=album, path=path) self.set_library_artwork_cached_filename(cache_key, filename) # Artwork for tooltip, left-top of player: (pix1, w, h) = img.get_pixbuf_of_size(pix, 75) pix1 = self.artwork_apply_composite_case(pix1, w, h) pix1 = img.pixbuf_add_border(pix1) pix1 = img.pixbuf_pad(pix1, 77, 77) self.albumimage.set_from_pixbuf(pix1) self.artwork_set_tooltip_art(pix1) del pix1 # Artwork for library, if current song matches: self.library_set_image_for_current_song(cache_key) # Artwork for fullscreen self.fullscreen_cover_art_set_image() # Artwork for info tab: if self.info_imagebox_get_size_request()[0] == -1: fullwidth = self.notebook_get_allocation()[2] - 50 (pix2, w, h) = img.get_pixbuf_of_size(pix, fullwidth) else: (pix2, w, h) = img.get_pixbuf_of_size(pix, 150) pix2 = self.artwork_apply_composite_case(pix2, w, h) pix2 = img.pixbuf_add_border(pix2) self.info_image.set_from_pixbuf(pix2) del pix2 del pix self.lastalbumart = filename self.schedule_gc_collect()
def download_progress(self, dest_filename_curr, i): # This populates Main.imagelist for the remote image window if os.path.exists(dest_filename_curr): pix = gtk.gdk.pixbuf_new_from_file(dest_filename_curr) pix = pix.scale_simple(148, 148, gtk.gdk.INTERP_HYPER) pix = self.artwork_apply_composite_case(pix, 148, 148) pix = img.pixbuf_add_border(pix) if self.stop_art_update: del pix return False # don't continue to next image self.imagelist_append([i+1, pix]) del pix self.remotefilelist_append(dest_filename_curr) if i == 0: self.allow_art_search() ui.change_cursor(None) # XXX indented twice more? return True # continue to next image
def artwork_download_img_to_file(self, artist, album, dest_filename, all_images=False): # Returns False if no images found if not artist and not album: self.downloading_image = False return False self.downloading_image = True # Amazon currently doesn't support utf8 and suggests latin1 encoding instead: artist = urllib.quote(artist.encode('latin1', 'replace')) album = urllib.quote(album.encode('latin1', 'replace')) # Try searching urls from most specific (artist, title) to least specific (artist only) urls = [AMAZON_URI % (AMAZON_KEY, artist) + "&Title=" + album, AMAZON_URI % (AMAZON_KEY, artist) + "&Keywords=" + album, AMAZON_URI % (AMAZON_KEY, artist)] for url in urls: request = urllib2.Request(url) opener = urllib2.build_opener() try: body = opener.open(request).read() xml = ElementTree.fromstring(body) largeimgs = xml.getiterator(AMAZON_NS + "LargeImage") except: largeimgs = None if largeimgs: break elif url == urls[-1]: self.downloading_image = False return False imgs = misc.iunique(url.text for img in largeimgs for url in img.getiterator(AMAZON_NS + "URL")) imglist = list(imgs) if not all_images: urllib.urlretrieve(imglist[0], dest_filename) self.downloading_image = False return True else: try: imgfound = False for i in range(len(imglist)): dest_filename_curr = dest_filename.replace("<imagenum>", str(i+1)) urllib.urlretrieve(imglist[i], dest_filename_curr) # This populates Main.imagelist for the remote image window if os.path.exists(dest_filename_curr): pix = gtk.gdk.pixbuf_new_from_file(dest_filename_curr) pix = pix.scale_simple(148, 148, gtk.gdk.INTERP_HYPER) pix = self.artwork_apply_composite_case(pix, 148, 148) pix = img.pixbuf_add_border(pix) if self.stop_art_update: del pix self.downloading_image = False return imgfound self.imagelist_append([i+1, pix]) del pix imgfound = True self.remotefilelist_append(dest_filename_curr) if i == 0: self.allow_art_search() ui.change_cursor(None) except: pass self.downloading_image = False return imgfound
def artwork_download_img_to_file(self, artist, album, dest_filename, all_images=False): # Returns False if no images found if not artist and not album: self.downloading_image = False return False self.downloading_image = True # Amazon currently doesn't support utf8 and suggests latin1 encoding instead: artist = urllib.quote(artist.encode('latin1', 'replace')) album = urllib.quote(album.encode('latin1', 'replace')) # Try searching urls from most specific (artist, title) to least specific (artist only) urls = [ AMAZON_URI % (AMAZON_KEY, artist) + "&Title=" + album, AMAZON_URI % (AMAZON_KEY, artist) + "&Keywords=" + album, AMAZON_URI % (AMAZON_KEY, artist) ] for url in urls: request = urllib2.Request(url) opener = urllib2.build_opener() try: body = opener.open(request).read() xml = ElementTree.fromstring(body) largeimgs = xml.getiterator(AMAZON_NS + "LargeImage") except: largeimgs = None if largeimgs: break elif url == urls[-1]: self.downloading_image = False return False imgs = misc.iunique(url.text for img in largeimgs for url in img.getiterator(AMAZON_NS + "URL")) # Prevent duplicate images in remote art window: imglist = list(set(list(imgs))) if not all_images: urllib.urlretrieve(imglist[0], dest_filename) self.downloading_image = False return True else: try: imgfound = False for i, image in enumerate(imglist): dest_filename_curr = dest_filename.replace( "<imagenum>", str(i + 1)) urllib.urlretrieve(image, dest_filename_curr) # This populates Main.imagelist for the remote image window if os.path.exists(dest_filename_curr): pix = gtk.gdk.pixbuf_new_from_file(dest_filename_curr) pix = pix.scale_simple(148, 148, gtk.gdk.INTERP_HYPER) pix = self.artwork_apply_composite_case(pix, 148, 148) pix = img.pixbuf_add_border(pix) if self.stop_art_update: del pix self.downloading_image = False return imgfound self.imagelist_append([i + 1, pix]) del pix imgfound = True self.remotefilelist_append(dest_filename_curr) if i == 0: self.allow_art_search() ui.change_cursor(None) except: pass self.downloading_image = False return imgfound