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.set_markup('')
            self._editlyricslabel.set_markup('')
            if error:
                self.lyricsText.set_markup(error)
            elif lyrics:
                self.lyricsText.set_markup(lyrics)
            else:
                self.lyricsText.set_markup('')
            return

        # Verify that we are displaying the correct lyrics:
        songinfo = self.get_playing_song()
        if not songinfo:
            return
        artist_now = misc.strip_all_slashes(mpdh.get(songinfo, 'artist', None))
        title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None))
        if artist_now == artist_then and title_now == title_then:
            self._searchlabel.set_markup(
                misc.link_markup(_('search'), True, True, self.linkcolor))
            self._editlyricslabel.set_markup(
                misc.link_markup(_('edit'), True, True, self.linkcolor))
            if error:
                self.lyricsText.set_markup(error)
            elif lyrics:
                try:
                    self.lyricsText.set_markup(misc.escape_html(lyrics))
                except:  # XXX why would this happen?
                    self.lyricsText.set_text(lyrics)
            else:
                self.lyricsText.set_markup('')
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.set_markup("")
            self._editlyricslabel.set_markup("")
            if error:
                self.lyricsText.get_buffer().set_text(error)
            elif lyrics:
                self.lyricsText.get_buffer().set_text(lyrics)
            else:
                self.lyricsText.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(mpdh.get(songinfo, 'artist', None))
        title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None))
        if artist_now == artist_then and title_now == title_then:
            self._searchlabel.set_markup(misc.link_markup(
                _("search"), True, True, self.linkcolor))
            self._editlyricslabel.set_markup(misc.link_markup(
                _("edit"), True, True, self.linkcolor))
            if error:
                self.lyricsText.get_buffer().set_text(error)
            elif lyrics:
                self._set_lyrics(lyrics)
            else:
                self.lyricsText.get_buffer().set_text("")
Example #3
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.set_markup('')
            self._editlyricslabel.set_markup('')
            if error:
                self.lyricsText.set_markup(error)
            elif lyrics:
                self.lyricsText.set_markup(lyrics)
            else:
                self.lyricsText.set_markup('')
            return

        # Verify that we are displaying the correct lyrics:
        songinfo = self.get_playing_song()
        if not songinfo:
            return
        artist_now = misc.strip_all_slashes(mpdh.get(songinfo, 'artist', None))
        title_now = misc.strip_all_slashes(mpdh.get(songinfo, 'title', None))
        if artist_now == artist_then and title_now == title_then:
            self._searchlabel.set_markup(misc.link_markup(
                _('search'), True, True, self.linkcolor))
            self._editlyricslabel.set_markup(misc.link_markup(
                _('edit'), True, True, self.linkcolor))
            if error:
                self.lyricsText.set_markup(error)
            elif lyrics:
                try:
                    self.lyricsText.set_markup(misc.escape_html(lyrics))
                except:  # XXX why would this happen?
                    self.lyricsText.set_text(lyrics)
            else:
                self.lyricsText.set_markup('')
Example #4
0
 def get_lyrics_start(self, search_artist, search_title, filename_artist,
                      filename_title, song_dir):
     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') as f:
                 lyrics = f.read()
         except IOError:
             pass
         if lyrics == _("Lyrics not found"):
             misc.remove_file(filename)
             filename = self._check_for_local_lyrics(filename_artist,
                                                     filename_title,
                                                     song_dir)
     if filename:
         # Re-use lyrics from file:
         try:
             with open(filename, 'r') 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 lyricwiki.org etc.
         lyrics_fetchers = pluginsystem.get('lyrics_fetching')
         callback = lambda * args: self.get_lyrics_response(
             filename_artist, filename_title, song_dir, *args)
         if lyrics_fetchers:
             msg = _("Fetching lyrics...")
             for _plugin, cb in lyrics_fetchers:
                 cb(callback, search_artist, search_title)
         else:
             msg = _("No lyrics plug-in enabled.")
         self._show_lyrics(filename_artist, filename_title,
                       lyrics=msg)
Example #5
0
	def info_show_lyrics(self, lyrics, artist, title, force=False):
		if force:
			# For error messages where there is no appropriate artist or 
			# title, we pass force=True:
			self.lyricsText.set_text(lyrics)
		elif self.get_playing_song():
			# Verify that we are displaying the correct lyrics:
			songinfo = self.get_playing_song()
			try:
				if misc.strip_all_slashes(mpdh.get(songinfo, 'artist')) == artist and misc.strip_all_slashes(mpdh.get(songinfo, 'title')) == title:
					try:
						self.lyricsText.set_markup(misc.escape_html(lyrics))
					except:
						self.lyricsText.set_text(lyrics)
			except:
				pass
Example #6
0
 def prompt_for_playlist_name(self, title, role):
     plname = None
     if self.connected():
         # Prompt user for playlist name:
         dialog = ui.dialog(
             title=title,
             parent=self.window,
             flags=gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT,
             buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT, gtk.STOCK_SAVE,
                      gtk.RESPONSE_ACCEPT),
             role=role,
             default=gtk.RESPONSE_ACCEPT)
         hbox = gtk.HBox()
         hbox.pack_start(ui.label(text=_('Playlist name') + ':'), False,
                         False, 5)
         entry = ui.entry()
         entry.set_activates_default(True)
         hbox.pack_start(entry, True, True, 5)
         dialog.vbox.pack_start(hbox)
         ui.show(dialog.vbox)
         response = dialog.run()
         if response == gtk.RESPONSE_ACCEPT:
             plname = misc.strip_all_slashes(entry.get_text())
         dialog.destroy()
     return plname
Example #7
0
 def prompt_for_playlist_name(self, title, role):
     plname = None
     if self.connected():
         # Prompt user for playlist name:
         dialog = ui.dialog(title=title, parent=self.window,
                            flags=gtk.DIALOG_MODAL |
                            gtk.DIALOG_DESTROY_WITH_PARENT,
                            buttons=(gtk.STOCK_CANCEL,
                                     gtk.RESPONSE_REJECT,
                                     gtk.STOCK_SAVE,
                                     gtk.RESPONSE_ACCEPT),
                            role=role, default=gtk.RESPONSE_ACCEPT)
         hbox = gtk.HBox()
         hbox.pack_start(ui.label(text=_('Playlist name:')), False, False,
                         5)
         entry = ui.entry()
         entry.set_activates_default(True)
         hbox.pack_start(entry, True, True, 5)
         dialog.vbox.pack_start(hbox)
         ui.show(dialog.vbox)
         response = dialog.run()
         if response == gtk.RESPONSE_ACCEPT:
             plname = misc.strip_all_slashes(entry.get_text())
         dialog.destroy()
     return plname
Example #8
0
	def info_show_lyrics(self, lyrics, artist, title, force=False):
		if force:
			# For error messages where there is no appropriate artist or 
			# title, we pass force=True:
			self.lyricsText.set_text(lyrics)
		elif self.get_playing_song():
			# Verify that we are displaying the correct lyrics:
			songinfo = self.get_playing_song()
			try:
				if misc.strip_all_slashes(mpdh.get(songinfo, 'artist')) == artist and misc.strip_all_slashes(mpdh.get(songinfo, 'title')) == title:
					try:
						self.lyricsText.set_markup(misc.escape_html(lyrics))
					except:
						self.lyricsText.set_text(lyrics)
			except:
				pass
Example #9
0
 def get_lyrics_start(self, search_artist, search_title, filename_artist,
                      filename_title, song_dir):
     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') as f:
                 lyrics = f.read()
         except IOError:
             pass
         if lyrics == _('Lyrics not found'):
             misc.remove_file(filename)
             filename = self._check_for_local_lyrics(
                 filename_artist, filename_title, song_dir)
     if filename:
         # Re-use lyrics from file:
         try:
             with open(filename, 'r') 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 lyrics.wikia.org etc.
         lyrics_fetchers = pluginsystem.get('lyrics_fetching')
         callback = lambda *args: self.get_lyrics_response(
             filename_artist, filename_title, song_dir, *args)
         if lyrics_fetchers:
             msg = _('Fetching lyrics...')
             for _plugin, cb in lyrics_fetchers:
                 cb(callback, search_artist, search_title)
         else:
             msg = _('No lyrics plug-in enabled.')
         self._show_lyrics(filename_artist, filename_title, lyrics=msg)
Example #10
0
	def get_lyrics_thread(self, search_artist, search_title, filename_artist, filename_title, song_dir):
		filename_artist = misc.strip_all_slashes(filename_artist)
		filename_title = misc.strip_all_slashes(filename_title)
		filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir)
		search_str = misc.link_markup(_("search"), True, True, self.linkcolor)
		edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor)
		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.
			f = open(filename, 'r')
			lyrics = f.read()
			f.close()
			if lyrics == _("Lyrics not found"):
				misc.remove_file(filename)
				filename = self.info_check_for_local_lyrics(filename_artist, filename_title, song_dir)
		if filename:
			# Re-use lyrics from file:
			f = open(filename, 'r')
			lyrics = f.read()
			f.close()
			# Strip artist - title line from file if it exists, since we
			# now have that information visible elsewhere.
			header = filename_artist + " - " + filename_title + "\n\n"
			if lyrics[:len(header)] == header:
				lyrics = lyrics[len(header):]
			gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
			gobject.idle_add(self.info_searchlabel.set_markup, search_str)
			gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
		else:
			# Use default filename:
			filename = self.target_lyrics_filename(filename_artist, filename_title, song_dir)
			# Fetch lyrics from lyricwiki.org
			gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."), filename_artist, filename_title)
			if self.lyricServer is None:
				wsdlFile = "http://lyricwiki.org/server.php?wsdl"
				try:
					self.lyricServer = True
					timeout = socketgettimeout()
					socketsettimeout(consts.LYRIC_TIMEOUT)
					self.lyricServer = ServiceProxy.ServiceProxy(wsdlFile, cachedir=os.path.expanduser("~/.service_proxy_dir")) 
				except:
					socketsettimeout(timeout)
					lyrics = _("Couldn't connect to LyricWiki")
					gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
					self.lyricServer = None
					gobject.idle_add(self.info_searchlabel.set_markup, search_str)
					gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
					return
			try:
				timeout = socketgettimeout()
				socketsettimeout(consts.LYRIC_TIMEOUT)
				lyrics = self.lyricServer.getSong(artist=self.lyricwiki_format(search_artist), song=self.lyricwiki_format(search_title))['return']["lyrics"]
				if lyrics.lower() != "not found":
					lyrics = misc.unescape_html(lyrics)
					lyrics = misc.wiki_to_html(lyrics)
					lyrics = lyrics.encode("ISO-8859-1")
					gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
					# Save lyrics to file:
					misc.create_dir('~/.lyrics/')
					f = open(filename, 'w')
					lyrics = misc.unescape_html(lyrics)
					try:
						f.write(lyrics.decode(self.enc).encode('utf8'))
					except:
						f.write(lyrics)
					f.close()
				else:
					lyrics = _("Lyrics not found")
					gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
			except:
				lyrics = _("Fetching lyrics failed")
				gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist, filename_title)
			gobject.idle_add(self.info_searchlabel.set_markup, search_str)
			gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
			socketsettimeout(timeout)
Example #11
0
 def get_lyrics_thread(self, search_artist, search_title, filename_artist,
                       filename_title, song_dir):
     filename_artist = misc.strip_all_slashes(filename_artist)
     filename_title = misc.strip_all_slashes(filename_title)
     filename = self.info_check_for_local_lyrics(filename_artist,
                                                 filename_title, song_dir)
     search_str = misc.link_markup(_("search"), True, True, self.linkcolor)
     edit_str = misc.link_markup(_("edit"), True, True, self.linkcolor)
     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.
         f = open(filename, 'r')
         lyrics = f.read()
         f.close()
         if lyrics == _("Lyrics not found"):
             misc.remove_file(filename)
             filename = self.info_check_for_local_lyrics(
                 filename_artist, filename_title, song_dir)
     if filename:
         # Re-use lyrics from file:
         f = open(filename, 'r')
         lyrics = f.read()
         f.close()
         # Strip artist - title line from file if it exists, since we
         # now have that information visible elsewhere.
         header = filename_artist + " - " + filename_title + "\n\n"
         if lyrics[:len(header)] == header:
             lyrics = lyrics[len(header):]
         gobject.idle_add(self.info_show_lyrics, lyrics, filename_artist,
                          filename_title)
         gobject.idle_add(self.info_searchlabel.set_markup, search_str)
         gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
     else:
         # Use default filename:
         filename = self.target_lyrics_filename(filename_artist,
                                                filename_title, song_dir)
         # Fetch lyrics from lyricwiki.org
         gobject.idle_add(self.info_show_lyrics, _("Fetching lyrics..."),
                          filename_artist, filename_title)
         if self.lyricServer is None:
             wsdlFile = "http://lyricwiki.org/server.php?wsdl"
             try:
                 self.lyricServer = True
                 timeout = socketgettimeout()
                 socketsettimeout(consts.LYRIC_TIMEOUT)
                 self.lyricServer = ServiceProxy.ServiceProxy(
                     wsdlFile,
                     cachedir=os.path.expanduser("~/.service_proxy_dir"))
             except:
                 socketsettimeout(timeout)
                 lyrics = _("Couldn't connect to LyricWiki")
                 gobject.idle_add(self.info_show_lyrics, lyrics,
                                  filename_artist, filename_title)
                 self.lyricServer = None
                 gobject.idle_add(self.info_searchlabel.set_markup,
                                  search_str)
                 gobject.idle_add(self.info_editlyricslabel.set_markup,
                                  edit_str)
                 return
         try:
             timeout = socketgettimeout()
             socketsettimeout(consts.LYRIC_TIMEOUT)
             lyrics = self.lyricServer.getSong(
                 artist=self.lyricwiki_format(search_artist),
                 song=self.lyricwiki_format(
                     search_title))['return']["lyrics"]
             if lyrics.lower() != "not found":
                 lyrics = misc.unescape_html(lyrics)
                 lyrics = misc.wiki_to_html(lyrics)
                 lyrics = lyrics.encode("ISO-8859-1")
                 gobject.idle_add(self.info_show_lyrics, lyrics,
                                  filename_artist, filename_title)
                 # Save lyrics to file:
                 misc.create_dir('~/.lyrics/')
                 f = open(filename, 'w')
                 lyrics = misc.unescape_html(lyrics)
                 try:
                     f.write(lyrics.decode(self.enc).encode('utf8'))
                 except:
                     f.write(lyrics)
                 f.close()
             else:
                 lyrics = _("Lyrics not found")
                 gobject.idle_add(self.info_show_lyrics, lyrics,
                                  filename_artist, filename_title)
         except:
             lyrics = _("Fetching lyrics failed")
             gobject.idle_add(self.info_show_lyrics, lyrics,
                              filename_artist, filename_title)
         gobject.idle_add(self.info_searchlabel.set_markup, search_str)
         gobject.idle_add(self.info_editlyricslabel.set_markup, edit_str)
         socketsettimeout(timeout)