Example #1
0
    def _show_lyrics(self, artist_then, title_then, lyrics=None, error=None):
        # For error messages where there is no appropriate info:
        if not artist_then or not title_then:
            self._searchlabel.hide()
            if error:
                self.lyrics_text.get_buffer().set_text(error)
            elif lyrics:
                self.lyrics_text.get_buffer().set_text(lyrics)
            else:
                self.lyrics_text.get_buffer().set_text("")
            return

        # Verify that we are displaying the correct lyrics:
        songinfo = self.get_playing_song()
        if not songinfo:
            return
        artist_now = misc.strip_all_slashes(songinfo.artist)
        title_now = misc.strip_all_slashes(songinfo.title)
        if artist_now == artist_then and title_now == title_then:
            self._searchlabel.show()
            if error:
                self.lyrics_text.get_buffer().set_text(error)
            elif lyrics:
                self._set_lyrics(lyrics)
            else:
                self.lyrics_text.get_buffer().set_text("")
Example #2
0
    def _show_lyrics(self, artist_then, title_then, lyrics=None, error=None):
        # For error messages where there is no appropriate info:
        if not artist_then or not title_then:
            self._searchlabel.hide()
            if error:
                self.lyrics_text.get_buffer().set_text(error)
            elif lyrics:
                self.lyrics_text.get_buffer().set_text(lyrics)
            else:
                self.lyrics_text.get_buffer().set_text("")
            return

        # Verify that we are displaying the correct lyrics:
        songinfo = self.get_playing_song()
        if not songinfo:
            return
        artist_now = misc.strip_all_slashes(songinfo.artist)
        title_now = misc.strip_all_slashes(songinfo.title)
        if artist_now == artist_then and title_now == title_then:
            self._searchlabel.show()
            if error:
                self.lyrics_text.get_buffer().set_text(error)
            elif lyrics:
                self._set_lyrics(lyrics)
            else:
                self.lyrics_text.get_buffer().set_text("")
Example #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:
            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()
Example #4
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()
Example #5
0
 def prompt_for_playlist_name(self, title, role, oldname=None):
     """Prompt user for playlist name"""
     plname = None
     if self.connected():
         if not self.playlist_name_dialog:
             self.playlist_name_dialog = self.builder.get_object(
                 'playlist_name_dialog')
         self.playlist_name_dialog.set_transient_for(self.window)
         self.playlist_name_dialog.set_title(title)
         self.playlist_name_dialog.set_role(role)
         entry = self.builder.get_object('playlist_name_entry')
         if oldname:
             entry.set_text(oldname)
         else:
             entry.set_text("")
         self.playlist_name_dialog.show_all()
         response = self.playlist_name_dialog.run()
         if response == Gtk.ResponseType.ACCEPT:
             plname = misc.strip_all_slashes(entry.get_text())
         self.playlist_name_dialog.hide()
     return plname
Example #6
0
 def prompt_for_playlist_name(self, title, role, oldname=None):
     """Prompt user for playlist name"""
     plname = None
     if self.connected():
         if not self.playlist_name_dialog:
             self.playlist_name_dialog = self.builder.get_object(
                 'playlist_name_dialog')
         self.playlist_name_dialog.set_transient_for(self.window)
         self.playlist_name_dialog.set_title(title)
         self.playlist_name_dialog.set_role(role)
         entry = self.builder.get_object('playlist_name_entry')
         if oldname:
             entry.set_text(oldname)
         else:
             entry.set_text("")
         self.playlist_name_dialog.show_all()
         response = self.playlist_name_dialog.run()
         if response == Gtk.ResponseType.ACCEPT:
             plname = misc.strip_all_slashes(entry.get_text())
         self.playlist_name_dialog.hide()
     return plname