コード例 #1
0
ファイル: artwork.py プロジェクト: Mic92/sonata
    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 = library.SongRecord(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.calc_info_image_size()
                    fullwidth = max(fullwidth, 150)
                    (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()
コード例 #2
0
ファイル: info.py プロジェクト: codebellaaj/sonata
    def get_lyrics_start(self, search_artist, search_title, filename_artist,
                         filename_title, song_dir, force_fetch=False):
        filename_artist = misc.strip_all_slashes(filename_artist)
        filename_title = misc.strip_all_slashes(filename_title)
        filename = self._check_for_local_lyrics(filename_artist,
                                                filename_title, song_dir)
        lyrics = ""
        if filename:
            # If the lyrics only contain "not found", delete the file and try
            # to fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki
            # that prevents lyrics from being found, storing the "not found"
            # will prevent a future release from correctly fetching the lyrics.
            try:
                with open(filename, 'r', encoding="utf-8") as f:
                    lyrics = f.read()
            except IOError:
                pass

            if lyrics == _("Lyrics not found"):
                force_fetch = True

        if force_fetch:
            # Remove all lyrics for this song
            while filename is not None:
                filename = self._check_for_local_lyrics(filename_artist,
                                                        filename_title,
                                                        song_dir)
                if filename is not None:
                    misc.remove_file(filename)

        if filename:
            # Re-use lyrics from file:
            try:
                with open(filename, 'r', encoding="utf-8") as f:
                    lyrics = f.read()
            except IOError:
                pass
            # Strip artist - title line from file if it exists, since we
            # now have that information visible elsewhere.
            header = "%s - %s\n\n" % (filename_artist, filename_title)
            if lyrics[:len(header)] == header:
                lyrics = lyrics[len(header):]
            self._show_lyrics(filename_artist, filename_title, lyrics=lyrics)
        else:
            def communicate(artist_then, title_then, lyrics=None, error=None):
                """Schedule actions from the plugin thread into the main
                thread"""
                GLib.idle_add(self._show_lyrics, artist_then, title_then,
                              lyrics, error)

            # Fetch lyrics from plugins.
            thread = threading.Thread(
                name="LyricsFetcher",
                target=FetchLyricsWorker,
                args=(self.config, communicate,
                      search_artist, search_title, song_dir))
            thread.start()
コード例 #3
0
    def get_lyrics_start(self,
                         search_artist,
                         search_title,
                         filename_artist,
                         filename_title,
                         song_dir,
                         force_fetch=False):
        filename_artist = misc.strip_all_slashes(filename_artist)
        filename_title = misc.strip_all_slashes(filename_title)
        filename = self._check_for_local_lyrics(filename_artist,
                                                filename_title, song_dir)
        lyrics = ""
        if filename:
            # If the lyrics only contain "not found", delete the file and try
            # to fetch new lyrics. If there is a bug in Sonata/SZI/LyricWiki
            # that prevents lyrics from being found, storing the "not found"
            # will prevent a future release from correctly fetching the lyrics.
            try:
                with open(filename, 'r', encoding="utf-8") as f:
                    lyrics = f.read()
            except IOError:
                pass

            if lyrics == _("Lyrics not found"):
                force_fetch = True

        if force_fetch:
            # Remove all lyrics for this song
            while filename is not None:
                filename = self._check_for_local_lyrics(
                    filename_artist, filename_title, song_dir)
                if filename is not None:
                    misc.remove_file(filename)

        if filename:
            # Re-use lyrics from file:
            try:
                with open(filename, 'r', encoding="utf-8") as f:
                    lyrics = f.read()
            except IOError:
                pass
            # Strip artist - title line from file if it exists, since we
            # now have that information visible elsewhere.
            header = "%s - %s\n\n" % (filename_artist, filename_title)
            if lyrics[:len(header)] == header:
                lyrics = lyrics[len(header):]
            self._show_lyrics(filename_artist, filename_title, lyrics=lyrics)
        else:
            # Fetch lyrics from plugins.
            thread = threading.Thread(target=self.fetch_lyrics_from_plugins,
                                      args=(search_artist, search_title,
                                            song_dir))
            thread.start()
コード例 #4
0
ファイル: artwork.py プロジェクト: andersbll/sonata
 def library_get_album_cover(self, dirname, artist, album, pb_size):
     _tmp, coverfile = self.artwork_get_local_image(dirname, artist, album)
     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 = self.artwork_apply_composite_case(coverpb, w, h)
         return (coverpb, coverfile)
     return (None, None)
コード例 #5
0
ファイル: artwork.py プロジェクト: windfail/sonata
    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()
コード例 #6
0
ファイル: artwork.py プロジェクト: codebellaaj/sonata
 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)
コード例 #7
0
ファイル: artwork.py プロジェクト: windfail/sonata
 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)
コード例 #8
0
ファイル: artwork.py プロジェクト: codebellaaj/sonata
    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()
コード例 #9
0
ファイル: artwork.py プロジェクト: andersbll/sonata
 def on_reset_image(self, _action):
     if self.songinfo:
         if "name" in self.songinfo:
             # Stream, remove file:
             misc.remove_file(self.artwork_stream_filename(self.songinfo.name))
         else:
             # Normal song:
             misc.remove_file(self.target_image_filename())
             misc.remove_file(self.target_image_filename(consts.ART_LOCATION_HOMECOVERS))
             # Use blank cover as the artwork
             dest_filename = self.target_image_filename(consts.ART_LOCATION_HOMECOVERS)
             try:
                 emptyfile = open(dest_filename, "w")
                 emptyfile.close()
             except IOError:
                 pass
         self.artwork_update(True)
コード例 #10
0
ファイル: artwork.py プロジェクト: codebellaaj/sonata
 def on_reset_image(self, _action):
     if self.songinfo:
         if 'name' in self.songinfo:
             # Stream, remove file:
             misc.remove_file(artwork_stream(self.songinfo.name))
         else:
             # Normal song:
             misc.remove_file(self.locator.path_from_song(self.songinfo))
             misc.remove_file(self.locator.path_from_song(
                 self.songinfo, consts.ART_LOCATION_HOMECOVERS))
             # Use blank cover as the artwork
             dest_filename = self.locator.path_from_song(
                 self.songinfo, consts.ART_LOCATION_HOMECOVERS)
             try:
                 emptyfile = open(dest_filename, 'w')
                 emptyfile.close()
             except IOError:
                 pass
         self.artwork_update(True)
コード例 #11
0
ファイル: artwork.py プロジェクト: windfail/sonata
 def on_reset_image(self, _action):
     if self.songinfo:
         if 'name' in self.songinfo:
             # Stream, remove file:
             misc.remove_file(artwork_stream(self.songinfo.name))
         else:
             # Normal song:
             misc.remove_file(self.locator.path_from_song(self.songinfo))
             misc.remove_file(
                 self.locator.path_from_song(
                     self.songinfo, consts.ART_LOCATION_HOMECOVERS))
             # Use blank cover as the artwork
             dest_filename = self.locator.path_from_song(
                 self.songinfo, consts.ART_LOCATION_HOMECOVERS)
             try:
                 emptyfile = open(dest_filename, 'w')
                 emptyfile.close()
             except IOError:
                 pass
         self.artwork_update(True)