Skip to content

Commit

Permalink
Port song lyrics plugin to python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho authored and Jonathan Matthew committed Apr 21, 2013
1 parent 148183e commit 82aa9a7
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions plugins/lyrics/AstrawebParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def got_results (self, result, callback, *data):
body = re.split('(<tr><td bgcolor="#BBBBBB".*)(More Songs &gt)', results)[1]
entries = re.split('<tr><td bgcolor="#BBBBBB"', body)
entries.pop(0)
print "found %d entries; looking for [%s,%s]" % (len(entries), self.title, self.artist)
print("found %d entries; looking for [%s,%s]" % (len(entries), self.title, self.artist))
for entry in entries:
url = re.split('(\/display[^"]*)', entry)[1]
artist = re.split('(Artist:.*html">)([^<]*)', entry)[2].strip()
Expand All @@ -71,7 +71,7 @@ def got_results (self, result, callback, *data):

title_str = rb.string_match(self.title, title)

print "checking [%s,%s]: match strengths [%f,%f]" % (title.strip(), artist.strip(), title_str, artist_str)
print("checking [%s,%s]: match strengths [%f,%f]" % (title.strip(), artist.strip(), title_str, artist_str))
if title_str > title_match and artist_str > artist_match:
loader = rb.Loader()
loader.get_url ('http://display.lyrics.astraweb.com' + url, self.parse_lyrics, callback, *data)
Expand Down
10 changes: 5 additions & 5 deletions plugins/lyrics/LyricsConfigureDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def set_sites(self, widget):
if check.get_active():
sites.append(s['id'])

print "setting lyrics sites: " + str(sites)
print("setting lyrics sites: " + str(sites))
self.settings['sites'] = sites


Expand Down Expand Up @@ -112,11 +112,11 @@ def response_handler(widget, response):
def get_prefs (self):
try:
sites = self.settings['sites']
except GObject.GError, e:
print e
except GLib.GError as e:
print(e)
engines = []
folder = self.settings['folder']

print "lyric sites: " + str (sites)
print "lyric folder: " + folder
print("lyric sites: " + str (sites))
print("lyric folder: " + folder)
return (sites, folder)
8 changes: 4 additions & 4 deletions plugins/lyrics/LyricsParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ def __init__(self, artist, title):
try:
settings = Gio.Settings("org.gnome.rhythmbox.plugins.lyrics")
self.sites = settings['sites']
except GObject.GError, e:
print e
except GLib.GError as e:
print(e)
self.sites = []

def searcher(self, plexer, callback, *data):
for site in lyrics_sites:
if site['id'] not in self.sites:
print site['id'] + " search is disabled"
print(site['id'] + " search is disabled")
continue

plexer.clear()
parser = site['class'] (self.artist, self.title)
print "searching " + site['id'] + " for lyrics"
print("searching " + site['id'] + " for lyrics")

parser.search(plexer.send())
yield None
Expand Down
6 changes: 3 additions & 3 deletions plugins/lyrics/TerraParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
# Deal with html entitys and utf-8
# code taken from django/utils/text.py

from htmlentitydefs import name2codepoint
from html.entities import name2codepoint

pattern = re.compile("&(#?\w+?);")

Expand Down Expand Up @@ -72,7 +72,7 @@ def search(self, callback, *data):
join = urllib.quote(' - ')

wurl = 'winamp.php?t=%s%s%s' % (artist, join, title)
print "search URL: " + wurl
print("search URL: " + wurl)

loader = rb.Loader()
loader.get_url (path + wurl, self.got_lyrics, callback, *data)
Expand All @@ -85,7 +85,7 @@ def got_lyrics(self, result, callback, *data):
if result is not None:
result = result.decode('iso-8859-1').encode('UTF-8')
if re.search('M&uacute;sica n&atilde;o encontrada', result):
print "not found"
print("not found")
callback (None, *data)
elif re.search('<div id="letra">', result):
callback(self.parse_lyrics(result), *data)
Expand Down
12 changes: 6 additions & 6 deletions plugins/lyrics/WinampcnParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, artist, title):
def search(self, callback, *data):

# encode search string
title_encode = urllib.quote(detect_charset(self.title).encode('gbk').replace(' ', ''))
title_encode = urllib.quote(detect_charset(self.title).encode('gbk').replace(' ', ''))
artist_encode = urllib.quote(detect_charset(self.artist).encode('gbk').replace(' ',''))
url = 'http://www.winampcn.com/lyrictransfer/get.aspx?song=%s&artist=%s&lsong=%s&Datetime=20060601' % (title_encode, artist_encode, title_encode)

Expand All @@ -57,7 +57,7 @@ def search(self, callback, *data):
def got_lyrics(self, xmltext, callback, *data):
# retrieve xml content
if xmltext is None:
print "no response"
print("no response")
callback (None, *data)
return

Expand All @@ -69,13 +69,13 @@ def got_lyrics(self, xmltext, callback, *data):

lrcurl = root.getElementsByTagName('LyricUrl')[0].childNodes[0].data
if lrcurl is None:
print "no lyric urls"
print("no lyric urls")
callback (xmltext, *data)
return

# download the lyrics file
lrcurl = lrcurl.replace('%3A', ':');
print "url: %s" % lrcurl
print("url: %s" % lrcurl)

loader = rb.Loader()
loader.get_url (lrcurl, self.parse_lyrics, callback, *data)
Expand All @@ -86,7 +86,7 @@ def got_lyrics(self, xmltext, callback, *data):
def parse_lyrics(self, lyrics, callback, *data):

if lyrics is None:
print "no lyrics"
print("no lyrics")
callback (None, *data)
return

Expand All @@ -96,7 +96,7 @@ def parse_lyrics(self, lyrics, callback, *data):
lrcplaintext = re.sub('\[.*?\]', '', lrcplaintext)
lrcplaintext = lrcplaintext.decode('gbk').encode('UTF-8')
except:
print "unable to decode lyrics"
print("unable to decode lyrics")
callback (lrcplaintext, *data)
return

Expand Down
2 changes: 1 addition & 1 deletion plugins/lyrics/lyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def playing_entry_changed (self, sp, entry):
self.action.set_enabled (False)

def window_deleted (self, window):
print "lyrics window destroyed"
print("lyrics window destroyed")
self.window = None

def create_song_info (self, shell, song_info, is_multiple):
Expand Down

0 comments on commit 82aa9a7

Please sign in to comment.