Beispiel #1
0
    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 = GdkPixbuf.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 = SongRecord(artist=artist,
                                           album=album,
                                           path=path)
                    self.cache.set(cache_key, filename)

                    # Artwork for tooltip, left-top of player:
                    (pix1, w, h) = img.get_pixbuf_of_size(pix, 75)
                    pix1 = img.do_style_cover(self.config, 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)

                self.emit('artwork-changed', pix)
                del pix

                self.lastalbumart = filename

                self.schedule_gc_collect()
Beispiel #2
0
 def library_get_album_cover(self, song_dir, artist, album, pb_size):
     _tmp, coverfile = self.locator.locate(artist, album, song_dir)
     if coverfile:
         try:
             coverpb = GdkPixbuf.Pixbuf.new_from_file_at_size(coverfile,
                                                         pb_size, pb_size)
         except:
             # Delete bad image:
             misc.remove_file(coverfile)
             return (None, None)
         w = coverpb.get_width()
         h = coverpb.get_height()
         coverpb = img.do_style_cover(self.config, coverpb, w, h)
         return (coverpb, coverfile)
     return (None, None)
Beispiel #3
0
 def library_get_album_cover(self, song_dir, artist, album, pb_size):
     _tmp, coverfile = self.locator.locate(artist, album, song_dir)
     if coverfile:
         try:
             coverpb = GdkPixbuf.Pixbuf.new_from_file_at_size(
                 coverfile, pb_size, pb_size)
         except:
             # Delete bad image:
             misc.remove_file(coverfile)
             return (None, None)
         w = coverpb.get_width()
         h = coverpb.get_height()
         coverpb = img.do_style_cover(self.config, coverpb, w, h)
         return (coverpb, coverfile)
     return (None, None)
Beispiel #4
0
    def get_pixbuf(self, key, size, default=None):
        self.logger.debug("Requesting pixbuf for %r", key)
        try:
            path = self._cache[key]
        except KeyError:
            return default

        if not os.path.exists(path):
            self._cache.pop(key, None)
            return default

        try:
            p = GdkPixbuf.Pixbuf.new_from_file_at_size(path, size, size)
        except:
            self.logger.exception("Unable to load %r at size (%d, %d)",
                                  path, size, size)
            raise
        return img.do_style_cover(self.config, p, size, size)
Beispiel #5
0
    def get_pixbuf(self, key, size, default=None):
        self.logger.debug("Requesting pixbuf for %r", key)
        try:
            path = self._cache[key]
        except KeyError:
            return default

        if not os.path.exists(path):
            self._cache.pop(key, None)
            return default

        try:
            p = GdkPixbuf.Pixbuf.new_from_file_at_size(path, size, size)
        except:
            self.logger.exception("Unable to load %r at size (%d, %d)", path,
                                  size, size)
            raise
        return img.do_style_cover(self.config, p, size, size)
Beispiel #6
0
    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 = GdkPixbuf.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 = SongRecord(artist=artist, album=album,
                                           path=path)
                    self.cache.set(cache_key, filename)

                    # Artwork for tooltip, left-top of player:
                    (pix1, w, h) = img.get_pixbuf_of_size(pix, 75)
                    pix1 = img.do_style_cover(self.config, 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)

                self.emit('artwork-changed', pix)
                del pix

                self.lastalbumart = filename

                self.schedule_gc_collect()
Beispiel #7
0
    def on_artwork_changed(self, artwork_obj, pixbuf):
        if self._imagebox.get_size_request()[0] == -1:
            notebook_width = self.info_song_grid.get_parent().get_allocation().width
            grid = self.info_song_grid
            grid_allocation = grid.get_allocation()
            grid_height = grid_allocation.height
            grid_width = grid.get_preferred_width_for_height(grid_height)[0]
            fullwidth = notebook_width - (grid_width + 120)
            new_width = max(fullwidth, 150)
        else:
            new_width = 150

        (pix2, w, h) = img.get_pixbuf_of_size(pixbuf, new_width)
        pix2 = img.do_style_cover(self.config, pix2, w, h)
        pix2 = img.pixbuf_add_border(pix2)

        self.image.set_from_pixbuf(pix2)
        del pix2
        del pixbuf
Beispiel #8
0
    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 = GdkPixbuf.Pixbuf.new_from_file(dest_filename_curr)
            pix = pix.scale_simple(148, 148, GdkPixbuf.InterpType.HYPER)
            pix = img.do_style_cover(self.config, 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)

        return True # continue to next image
Beispiel #9
0
    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 = GdkPixbuf.Pixbuf.new_from_file(dest_filename_curr)
            pix = pix.scale_simple(148, 148, GdkPixbuf.InterpType.HYPER)
            pix = img.do_style_cover(self.config, 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)

        return True  # continue to next image
Beispiel #10
0
    def on_artwork_changed(self, artwork_obj, pixbuf):
        if self._imagebox.get_size_request()[0] == -1:
            notebook_width = self.info_song_grid.get_parent().get_allocation(
            ).width
            grid = self.info_song_grid
            grid_allocation = grid.get_allocation()
            grid_height = grid_allocation.height
            grid_width = grid.get_preferred_width_for_height(grid_height)[0]
            fullwidth = notebook_width - (grid_width + 120)
            new_width = max(fullwidth, 150)
        else:
            new_width = 150

        (pix2, w, h) = img.get_pixbuf_of_size(pixbuf, new_width)
        pix2 = img.do_style_cover(self.config, pix2, w, h)
        pix2 = img.pixbuf_add_border(pix2)

        self.image.set_from_pixbuf(pix2)
        del pix2
        del pixbuf