', result)
+ if m is None:
+ callback (None, *data)
+ return
- loader = rb.Loader()
- loader.get_url ('http://j-lyric.net' + m.group(1), self.parse_lyrics, callback, *data)
-
- def parse_lyrics (self, result, callback, *data):
- if result is None:
- callback (None, *data)
- return
+ loader = rb.Loader()
+ loader.get_url ('http://j-lyric.net' + m.group(1), self.parse_lyrics, callback, *data)
- lyrics = re.split ('', result)[1]
- lyrics = re.split ('
', lyrics)[0]
+ def parse_lyrics (self, result, callback, *data):
+ if result is None:
+ callback (None, *data)
+ return
- lyrics = re.sub('
', '', lyrics)
- lyrics = self.title + "\n\n" + lyrics
- lyrics += "\n\nLyrics provided by j-lyric.net"
+ result = result.decode('utf-8')
+ lyrics = re.split ('', result)[1]
+ lyrics = re.split ('
', lyrics)[0]
- callback (lyrics, *data)
+ lyrics = re.sub('
', '', lyrics)
+ lyrics = self.title + "\n\n" + lyrics
+ lyrics += "\n\nLyrics provided by j-lyric.net"
+ callback (lyrics, *data)
diff --git a/plugins/lyrics/LyricWikiParser.py b/plugins/lyrics/LyricWikiParser.py
index a333a9042..969e4ef69 100644
--- a/plugins/lyrics/LyricWikiParser.py
+++ b/plugins/lyrics/LyricWikiParser.py
@@ -25,7 +25,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-import urllib
+import urllib.parse
import rb
from xml.dom import minidom
@@ -35,8 +35,8 @@ def __init__(self, artist, title):
self.title = title
def search(self, callback, *data):
- artist = urllib.quote(self.artist.replace(' ', '_'))
- title = urllib.quote(self.title.replace(' ', '_'))
+ artist = urllib.parse.quote(self.artist.replace(' ', '_'))
+ title = urllib.parse.quote(self.title.replace(' ', '_'))
htstring = 'http://lyricwiki.org/api.php?artist=%s&song=%s&fmt=text' % (artist, title)
@@ -48,7 +48,7 @@ def got_lyrics(self, result, callback, *data):
callback (None, *data)
return
+ result = result.decode('iso-8859-1')
result += "\n\nLyrics provided by lyricwiki.org"
callback (result, *data)
-
diff --git a/plugins/lyrics/LyricsParse.py b/plugins/lyrics/LyricsParse.py
index 31034387e..572255160 100644
--- a/plugins/lyrics/LyricsParse.py
+++ b/plugins/lyrics/LyricsParse.py
@@ -24,9 +24,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-import urllib
-import re
-
import rb
from gi.repository import GObject, Gio
diff --git a/plugins/lyrics/TerraParser.py b/plugins/lyrics/TerraParser.py
index 1d42db8f7..d1316674f 100644
--- a/plugins/lyrics/TerraParser.py
+++ b/plugins/lyrics/TerraParser.py
@@ -26,12 +26,12 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-import urllib
+import urllib.parse
import rb
import re
import sys
-# Deal with html entitys and utf-8
+# Deal with html entities and utf-8
# code taken from django/utils/text.py
from html.entities import name2codepoint
@@ -47,12 +47,12 @@ def _replace_entity(match):
c = int(text[1:], 16)
else:
c = int(text)
- return unichr(c)
+ return chr(c)
except ValueError:
return match.group(0)
else:
try:
- return unichr(name2codepoint[text])
+ return chr(name2codepoint[text])
except (ValueError, KeyError):
return match.group(0)
@@ -65,11 +65,11 @@ def __init__(self, artist, title):
self.title = title
def search(self, callback, *data):
- path = 'http://letras.terra.com.br/'
+ path = 'http://letras.mus.br/'
- artist = urllib.quote(self.artist)
- title = urllib.quote(self.title)
- join = urllib.quote(' - ')
+ artist = urllib.parse.quote(self.artist)
+ title = urllib.parse.quote(self.title)
+ join = urllib.parse.quote(' - ')
wurl = 'winamp.php?t=%s%s%s' % (artist, join, title)
print("search URL: " + wurl)
@@ -83,7 +83,7 @@ def got_lyrics(self, result, callback, *data):
return
if result is not None:
- result = result.decode('iso-8859-1').encode('UTF-8')
+ result = result.decode('utf-8')
if re.search('Música não encontrada', result):
print("not found")
callback (None, *data)
@@ -107,6 +107,5 @@ def parse_lyrics(self, source):
lyrics = re.sub('<[Bb][Rr]/>', '', lyrics)
lyrics = unescape_entities(artistitle) + "\n" + unescape_entities(lyrics)
- lyrics += "\n\nEsta letra foi disponibilizada pelo site\nhttp://letras.terra.com.br"
-
+ lyrics += "\n\nEsta letra foi disponibilizada pelo site\nhttp://letras.mus.br"
return lyrics
diff --git a/plugins/lyrics/WinampcnParser.py b/plugins/lyrics/WinampcnParser.py
index 4f9a546b4..216e89dfb 100644
--- a/plugins/lyrics/WinampcnParser.py
+++ b/plugins/lyrics/WinampcnParser.py
@@ -25,20 +25,11 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
import sys
-import urllib
+import urllib.parse
import re
import rb
from xml.dom import minidom
-def detect_charset(s):
- charsets = ('iso-8859-1', 'gbk', 'utf-8')
- for charset in charsets:
- try:
- return unicode(unicode(s, 'utf-8').encode(charset), 'gbk')
- except:
- continue
- return s
-
class WinampcnParser(object):
def __init__(self, artist, title):
self.artist = artist
@@ -47,8 +38,8 @@ def __init__(self, artist, title):
def search(self, callback, *data):
# encode search string
- title_encode = urllib.quote(detect_charset(self.title).encode('gbk').replace(' ', ''))
- artist_encode = urllib.quote(detect_charset(self.artist).encode('gbk').replace(' ',''))
+ title_encode = urllib.parse.quote(self.title.replace(' ', '').encode('gbk'))
+ artist_encode = urllib.parse.quote(self.artist.replace(' ', '').encode('gbk'))
url = 'http://www.winampcn.com/lyrictransfer/get.aspx?song=%s&artist=%s&lsong=%s&Datetime=20060601' % (title_encode, artist_encode, title_encode)
loader = rb.Loader()
@@ -60,9 +51,9 @@ def got_lyrics(self, xmltext, callback, *data):
print("no response")
callback (None, *data)
return
+ xmltext = xmltext.decode('gbk')
try:
- xmltext = xmltext.decode('gbk').encode('UTF-8')
xmltext = xmltext.replace('encoding="gb2312"', 'encoding="UTF-8"')
xmldoc = minidom.parseString(xmltext)
root = xmldoc.documentElement
@@ -91,16 +82,13 @@ def parse_lyrics(self, lyrics, callback, *data):
return
# transform it into plain text
- lrcplaintext = lyrics
+ lrcplaintext = lyrics.decode('gbk')
try:
lrcplaintext = re.sub('\[.*?\]', '', lrcplaintext)
- lrcplaintext = lrcplaintext.decode('gbk').encode('UTF-8')
except:
print("unable to decode lyrics")
- callback (lrcplaintext, *data)
+ callback (None, *data)
return
- # callback and show
lrcplaintext += "\n\nLyrics provided by winampcn.com"
callback(lrcplaintext, *data)
-
diff --git a/plugins/lyrics/lyrics.py b/plugins/lyrics/lyrics.py
index cd0825517..31e68d5ce 100644
--- a/plugins/lyrics/lyrics.py
+++ b/plugins/lyrics/lyrics.py
@@ -27,7 +27,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
import os, re
-import urllib
+import urllib.request
import rb
from gi.repository import Gtk, Gio, GObject, Peas
@@ -150,7 +150,7 @@ def search_lyrics(self, callback, cache_only=False):
if status:
l = rb.Loader()
- l.get_url('file://' + urllib.pathname2url(self.cache_path), callback)
+ l.get_url('file://' + urllib.request.pathname2url(self.cache_path), callback)
elif cache_only:
self.callback(_("No lyrics found"))
elif self.artist == "" and self.title == "":
@@ -158,7 +158,7 @@ def search_lyrics(self, callback, cache_only=False):
else:
def lyric_callback (text):
if text is not None:
- f = file (self.cache_path, 'w')
+ f = open(self.cache_path, 'wt')
f.write (text)
f.close ()
self.callback(text)