def __search(self, song, buffer, refresh, add): artist = song.comma("artist") title = song.comma("title") try: sock = urlopen( "http://lyricwiki.org/api.php?" "client=QuodLibet&func=getSong&artist=%s&song=%s&fmt=text" % ( quote(artist.encode('utf-8')), quote(title.encode('utf-8')))) text = sock.read() except Exception as err: encoding = util.get_locale_encoding() try: err = err.strerror.decode(encoding, 'replace') except: err = _("Unable to download lyrics.") GLib.idle_add(buffer.set_text, err) return sock.close() if text == 'Not found': GLib.idle_add( buffer.set_text, _("No lyrics found for this song.")) return else: GLib.idle_add(buffer.set_text, text) GLib.idle_add(refresh.set_sensitive, True)
def plugin_songs(self, songs): if not self.selected_tag: return l = dict.fromkeys([song(self.selected_tag) for song in songs]).keys() # If no tags values were found, show an error dialog if list(l) == ['']: ErrorMessage(app.window, _('Search failed'), _('Tag "%s" not found.') % self.selected_tag).run() return for a in l: # Only search for non-empty tags if a: a = quote(str(a).title().replace(' ', '_')) util.website(WIKI_URL % get_lang() + a)
def escape_filename(s): """Escape a string in a manner suitable for a filename. Args: s (text_type) Returns: fsnative """ s = text_type(s) s = quote(s.encode("utf-8"), safe=b"") if isinstance(s, text_type): s = s.encode("ascii") return bytes2fsn(s, "utf-8")
def __search(self, song, buffer, refresh, add): artist = song.comma("artist") title = song.comma("title") try: sock = urlopen( "http://lyricwiki.org/api.php?" "client=QuodLibet&func=getSong&artist=%s&song=%s&fmt=text" % (quote(artist.encode('utf-8')), quote(title.encode('utf-8')))) text = sock.read() except Exception as err: util.print_exc() GLib.idle_add(buffer.set_text, text_type(err)) return sock.close() if text == 'Not found': GLib.idle_add(buffer.set_text, _("No lyrics found for this song.")) return else: GLib.idle_add(buffer.set_text, text) GLib.idle_add(refresh.set_sensitive, True)
def change_song(self, path): """Queue up a song""" self.player_request("playlist clear") self.player_request("playlist insert %s" % (quote(path)))
def playlist_resume(self, name, resume, wipe=False): cmd = ("playlist resume %s noplay:%d wipePlaylist:%d" % (quote(name), int(not resume), int(wipe))) self.player_request(cmd, want_reply=False)
def playlist_save(self, name): self.player_request("playlist save %s" % (quote(name)), False)
def playlist_add(self, path): self.player_request("playlist add %s" % (quote(path)), False)
def create_api_search_url(song): artist, title = song("artist"), song("title") artist = quote(artist.encode('utf-8')) title = quote(title.encode('utf-8')) return LYRICS_WIKIA_URL % (artist, title)
def __view_online(self, add, song): artist = song.comma('artist').encode('utf-8') title = song.comma('title').encode('utf-8') util.website("http://lyrics.wikia.com/%s:%s" % (quote(artist), quote(title)))
def playlist_play(self, path): """Play song immediately""" self.player_request("playlist play %s" % (quote(path)))
def plugin_songs(self, songs): l = dict.fromkeys([song(self.k) for song in songs]).keys() for a in l: a = quote(str(a).title().replace(' ', '_')) website(WIKI_URL % get_lang() + a)
def __add(self, add, song): artist = song.comma('artist').encode('utf-8') util.website("http://lyricwiki.org/%s" % (quote(artist)))