[rhythmbox/wip/python3] Port song lyrics plugin to python 3



commit 5a2476db237e9cbd8763edc8cd800183cf960f17
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Tue Apr 16 09:47:37 2013 +0200

    Port song lyrics plugin to python 3

 plugins/lyrics/AstrawebParser.py        |  4 ++--
 plugins/lyrics/LyricsConfigureDialog.py | 10 +++++-----
 plugins/lyrics/LyricsParse.py           |  8 ++++----
 plugins/lyrics/TerraParser.py           |  6 +++---
 plugins/lyrics/WinampcnParser.py        | 12 ++++++------
 plugins/lyrics/lyrics.py                |  2 +-
 6 files changed, 21 insertions(+), 21 deletions(-)
---
diff --git a/plugins/lyrics/AstrawebParser.py b/plugins/lyrics/AstrawebParser.py
index c94c1bf..b2b0d86 100644
--- a/plugins/lyrics/AstrawebParser.py
+++ b/plugins/lyrics/AstrawebParser.py
@@ -58,7 +58,7 @@ class AstrawebParser (object):
                        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()
@@ -71,7 +71,7 @@ class AstrawebParser (object):
 
                                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)
diff --git a/plugins/lyrics/LyricsConfigureDialog.py b/plugins/lyrics/LyricsConfigureDialog.py
index 32359c3..147ce27 100644
--- a/plugins/lyrics/LyricsConfigureDialog.py
+++ b/plugins/lyrics/LyricsConfigureDialog.py
@@ -84,7 +84,7 @@ class LyricsConfigureDialog (GObject.Object, PeasGtk.Configurable):
                        if check.get_active():
                                sites.append(s['id'])
 
-               print "setting lyrics sites: " + str(sites)
+               print("setting lyrics sites: " + str(sites))
                self.settings['sites'] = sites
 
 
@@ -112,11 +112,11 @@ class LyricsConfigureDialog (GObject.Object, PeasGtk.Configurable):
        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)
diff --git a/plugins/lyrics/LyricsParse.py b/plugins/lyrics/LyricsParse.py
index c7bd9f5..3103438 100644
--- a/plugins/lyrics/LyricsParse.py
+++ b/plugins/lyrics/LyricsParse.py
@@ -40,19 +40,19 @@ class Parser (object):
                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
diff --git a/plugins/lyrics/TerraParser.py b/plugins/lyrics/TerraParser.py
index 657fb8e..1d42db8 100644
--- a/plugins/lyrics/TerraParser.py
+++ b/plugins/lyrics/TerraParser.py
@@ -34,7 +34,7 @@ import sys
 # 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+?);")
 
@@ -72,7 +72,7 @@ class TerraParser (object):
                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)
@@ -85,7 +85,7 @@ class TerraParser (object):
                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)
diff --git a/plugins/lyrics/WinampcnParser.py b/plugins/lyrics/WinampcnParser.py
index 7ea139b..4f9a546 100644
--- a/plugins/lyrics/WinampcnParser.py
+++ b/plugins/lyrics/WinampcnParser.py
@@ -47,7 +47,7 @@ class WinampcnParser(object):
        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)
                
@@ -57,7 +57,7 @@ class WinampcnParser(object):
        def got_lyrics(self, xmltext, callback, *data):
                # retrieve xml content
                if xmltext is None:
-                       print "no response"
+                       print("no response")
                        callback (None, *data)
                        return
 
@@ -69,13 +69,13 @@ class WinampcnParser(object):
 
                        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)
@@ -86,7 +86,7 @@ class WinampcnParser(object):
        def parse_lyrics(self, lyrics, callback, *data):
 
                if lyrics is None:
-                       print "no lyrics"
+                       print("no lyrics")
                        callback (None, *data)
                        return
 
@@ -96,7 +96,7 @@ class WinampcnParser(object):
                        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
 
diff --git a/plugins/lyrics/lyrics.py b/plugins/lyrics/lyrics.py
index 50e86e7..cd08255 100644
--- a/plugins/lyrics/lyrics.py
+++ b/plugins/lyrics/lyrics.py
@@ -398,7 +398,7 @@ class LyricsDisplayPlugin(GObject.Object, Peas.Activatable):
                        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):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]