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 artwork_set_default_icon(self, artist=None, album=None, path=None): if self.albumimage.get_property('file') != self.sonatacd: gobject.idle_add(self.albumimage.set_from_file, self.sonatacd) gobject.idle_add(self.info_image.set_from_file, self.sonatacd_large) gobject.idle_add(self.fullscreen_cover_art_set_image, self.sonatacd_large) gobject.idle_add(self.artwork_set_tooltip_art, gtk.gdk.pixbuf_new_from_file(self.sonatacd)) self.lastalbumart = None # Also, update row in library: if artist is not None: cache_key = library_set_data(artist=artist, album=album, path=path) self.set_library_artwork_cached_filename(cache_key, self.album_filename) gobject.idle_add(self.library_set_image_for_current_song, cache_key, self.album_filename)
def artwork_set_default_icon(self, artist=None, album=None, path=None): if self.albumimage.get_property('file') != self.sonatacd: gobject.idle_add(self.albumimage.set_from_file, self.sonatacd) gobject.idle_add(self.info_image.set_from_file, self.sonatacd_large) gobject.idle_add(self.fullscreen_cover_art_reset_image) gobject.idle_add(self.artwork_set_tooltip_art, gtk.gdk.pixbuf_new_from_file(self.sonatacd)) self.lastalbumart = None # Also, update row in library: if artist is not None: cache_key = library_set_data(artist=artist, album=album, path=path) self.set_library_artwork_cached_filename(cache_key, self.album_filename) gobject.idle_add(self.library_set_image_for_current_song, cache_key)
def _library_artwork_update(self): while True: remote_art = False # Wait for items.. self.lib_art_cond.acquire() while(len(self.lib_art_rows_local) == 0 and len(self.lib_art_rows_remote) == 0): self.lib_art_cond.wait() self.lib_art_cond.release() # Try first element, giving precedence to local queue: if len(self.lib_art_rows_local) > 0: i, data, icon = self.lib_art_rows_local[0] remote_art = False elif len(self.lib_art_rows_remote) > 0: i, data, icon = self.lib_art_rows_remote[0] remote_art = True else: i = None if i is not None and self.lib_model.iter_is_valid(i): artist, album, path = library_get_data(data, 'artist', 'album', 'path') if artist is None or album is None: if remote_art: self.lib_art_rows_remote.pop(0) else: self.lib_art_rows_local.pop(0) cache_key = library_set_data(artist=artist, album=album, path=path) filename = None # Try to replace default icons with cover art: pb = self.get_library_artwork_cached_pb(cache_key, None) # No cached pixbuf, try local/remote search: if pb is None: if not remote_art: pb, filename = self.library_get_album_cover(path, artist, album, self.lib_art_pb_size) else: filename = self.target_image_filename(None, path, artist, album) self.artwork_download_img_to_file(artist, album, filename) pb, filename = self.library_get_album_cover(path, artist, album, self.lib_art_pb_size) # Set pixbuf icon in model; add to cache if pb is not None: if filename is not None: self.set_library_artwork_cached_filename(cache_key, filename) gobject.idle_add(self.library_set_cover, i, pb, data) # Remote processed item from queue: if not remote_art: if len(self.lib_art_rows_local) > 0 and (i, data, icon) == self.lib_art_rows_local[0]: self.lib_art_rows_local.pop(0) if pb is None and self.config.covers_pref == consts.ART_LOCAL_REMOTE: # No local art found, add to remote queue for later self.lib_art_rows_remote.append((i, data, icon)) else: if len(self.lib_art_rows_remote) > 0 and (i, data, icon) == self.lib_art_rows_remote[0]: self.lib_art_rows_remote.pop(0) if pb is None: # No remote art found, store self.albumpb filename in cache self.set_library_artwork_cached_filename(cache_key, self.album_filename)
def _library_artwork_update(self): while True: remote_art = False # Wait for items.. self.lib_art_cond.acquire() while (len(self.lib_art_rows_local) == 0 and len(self.lib_art_rows_remote) == 0): self.lib_art_cond.wait() self.lib_art_cond.release() # Try first element, giving precedence to local queue: if len(self.lib_art_rows_local) > 0: i, data, icon = self.lib_art_rows_local[0] remote_art = False elif len(self.lib_art_rows_remote) > 0: i, data, icon = self.lib_art_rows_remote[0] remote_art = True else: i = None if i is not None and self.lib_model.iter_is_valid(i): artist, album, path = library_get_data(data, 'artist', 'album', 'path') if artist is None or album is None: if remote_art: self.lib_art_rows_remote.pop(0) else: self.lib_art_rows_local.pop(0) cache_key = library_set_data(artist=artist, album=album, path=path) filename = None # Try to replace default icons with cover art: pb = self.get_library_artwork_cached_pb(cache_key, None) # No cached pixbuf, try local/remote search: if pb is None: if not remote_art: pb, filename = self.library_get_album_cover( path, artist, album, self.lib_art_pb_size) else: filename = self.target_image_filename( None, path, artist, album) self.artwork_download_img_to_file( artist, album, filename) pb, filename = self.library_get_album_cover( path, artist, album, self.lib_art_pb_size) # Set pixbuf icon in model; add to cache if pb is not None: if filename is not None: self.set_library_artwork_cached_filename( cache_key, filename) gobject.idle_add(self.library_set_cover, i, pb, data) # Remote processed item from queue: if not remote_art: if len(self.lib_art_rows_local) > 0 and ( i, data, icon) == self.lib_art_rows_local[0]: self.lib_art_rows_local.pop(0) if pb is None and self.config.covers_pref == consts.ART_LOCAL_REMOTE: # No local art found, add to remote queue for later self.lib_art_rows_remote.append((i, data, icon)) else: if len(self.lib_art_rows_remote) > 0 and ( i, data, icon) == self.lib_art_rows_remote[0]: self.lib_art_rows_remote.pop(0) if pb is None: # No remote art found, store self.albumpb filename in cache self.set_library_artwork_cached_filename( cache_key, self.album_filename)