Example #1
0
    def get_lyrics_thread(self, callback, artist, title):
        # FIXME locking...
        global ServiceProxy
        if ServiceProxy is None:
            try:
                from ZSI import ServiceProxy
                # Make sure we have the right version..
                if not hasattr(ServiceProxy, 'ServiceProxy'):
                    ServiceProxy = None
            except ImportError:
                ServiceProxy = None
        if ServiceProxy is None:
            self.call_back(
                callback,
                None,
                None,
                error=_("ZSI not found, fetching lyrics support disabled."))
            return

        # FIXME locking...
        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:
                self.lyricServer = None
                socketsettimeout(timeout)
                error = _("Couldn't connect to LyricWiki")
                self.call_back(callback, error=error)
                return

        try:
            timeout = socketgettimeout()
            socketsettimeout(consts.LYRIC_TIMEOUT)
            lyrics = self.lyricServer.getSong(
                artist=self.lyricwiki_format(artist),
                song=self.lyricwiki_format(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")
                self.call_back(callback, lyrics=lyrics)
            else:
                error = _("Lyrics not found")
                self.call_back(callback, error=error)
        except:
            error = _("Fetching lyrics failed")
            self.call_back(callback, error=error)

        socketsettimeout(timeout)
Example #2
0
    def get_lyrics_thread(self, callback, artist, title):
        # FIXME locking...
        global ServiceProxy
        if ServiceProxy is None:
            try:
                from ZSI import ServiceProxy

                # Make sure we have the right version..
                if not hasattr(ServiceProxy, "ServiceProxy"):
                    ServiceProxy = None
            except ImportError:
                ServiceProxy = None
        if ServiceProxy is None:
            self.call_back(callback, None, None, error=_("ZSI not found, fetching lyrics support disabled."))
            return

            # FIXME locking...
        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:
                self.lyricServer = None
                socketsettimeout(timeout)
                error = _("Couldn't connect to LyricWiki")
                self.call_back(callback, error=error)
                return

        try:
            timeout = socketgettimeout()
            socketsettimeout(consts.LYRIC_TIMEOUT)
            lyrics = self.lyricServer.getSong(artist=self.lyricwiki_format(artist), song=self.lyricwiki_format(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")
                self.call_back(callback, lyrics=lyrics)
            else:
                error = _("Lyrics not found")
                self.call_back(callback, error=error)
        except:
            error = _("Fetching lyrics failed")
            self.call_back(callback, error=error)

        socketsettimeout(timeout)
Example #3
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 #4
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)