[rhythmbox] Port artsearch plugin to python 3



commit 6f4b1f0f207b17d639bd0ff362f7ee9e83453da4
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Apr 15 10:50:17 2013 +0200

    Port artsearch plugin to python 3

 plugins/artsearch/embedded.py    | 12 ++++++------
 plugins/artsearch/lastfm.py      | 20 ++++++++++----------
 plugins/artsearch/local.py       | 22 +++++++++++-----------
 plugins/artsearch/musicbrainz.py | 18 +++++++++---------
 plugins/artsearch/oldcache.py    |  4 ++--
 5 files changed, 38 insertions(+), 38 deletions(-)
---
diff --git a/plugins/artsearch/embedded.py b/plugins/artsearch/embedded.py
index 169536f..136d584 100644
--- a/plugins/artsearch/embedded.py
+++ b/plugins/artsearch/embedded.py
@@ -37,15 +37,15 @@ class EmbeddedSearch(object):
                for tagname in ('image', 'preview-image'):
                        (found, sample) = tags.get_sample(tagname)
                        if not found:
-                               print "no %s" % tagname
+                               print("no %s" % tagname)
                                continue
 
                        pixbuf = RB.gst_process_embedded_image(tags, tagname)
                        if not pixbuf:
-                               print "no pixbuf in %s" % tagname
+                               print("no pixbuf in %s" % tagname)
                                continue
 
-                       print "trying to store pixbuf from %s" % tagname
+                       print("trying to store pixbuf from %s" % tagname)
                        key = RB.ExtDBKey.create_storage("album", self.search_key.get_field("album"))
                        artists = self.search_key.get_field_values("artist")
                        key.add_field("artist", artists[0])
@@ -56,12 +56,12 @@ class EmbeddedSearch(object):
        def search (self, key, last_time, store, callback, args):
                location = key.get_info("location")
                if location is None:
-                       print "not searching, we don't have a location"
+                       print("not searching, we don't have a location")
                        callback(args)
                        return
 
                if location.startswith("file://") is False:
-                       print "not searching in non-local file %s" % location
+                       print("not searching in non-local file %s" % location)
                        callback(args)
                        return
 
@@ -72,7 +72,7 @@ class EmbeddedSearch(object):
                self.store = store
                self.search_key = key
 
-               print "discovering %s" % location
+               print("discovering %s" % location)
                self.discoverer = GstPbutils.Discoverer(timeout=Gst.SECOND*5)
                self.discoverer.connect('finished', self.finished_cb)
                self.discoverer.connect('discovered', self.discovered_cb)
diff --git a/plugins/artsearch/lastfm.py b/plugins/artsearch/lastfm.py
index 8ad267a..8244e55 100644
--- a/plugins/artsearch/lastfm.py
+++ b/plugins/artsearch/lastfm.py
@@ -27,7 +27,7 @@
 import urllib
 import xml.dom.minidom as dom
 import re
-import ConfigParser
+import configparser
 import os
 import time
 
@@ -65,7 +65,7 @@ def user_has_account():
        if os.path.exists(session_file) == False:
                return False
 
-       sessions = ConfigParser.RawConfigParser()
+       sessions = configparser.RawConfigParser()
        sessions.read(session_file)
        try:
                return (sessions.get('Last.fm', 'username') != "")
@@ -85,7 +85,7 @@ class LastFMSearch (object):
 
                album.strip()
 
-               print "searching for (%s, %s, %s)" % (artist, album, album_mbid)
+               print("searching for (%s, %s, %s)" % (artist, album, album_mbid))
                url = API_URL + "?method=album.getinfo&"
                if artist != None:
                        url = url + "artist=%s&" % (urllib.quote_plus(artist))
@@ -95,13 +95,13 @@ class LastFMSearch (object):
                        url = url + "mbid=%s&" % (urllib.quote_plus(album_mbid))
 
                url = url + "api_key=%s" % API_KEY
-               print "last.fm query url = %s" % url
+               print("last.fm query url = %s" % url)
                return url
 
 
        def album_info_cb (self, data):
                if data is None:
-                       print "last.fm query returned nothing"
+                       print("last.fm query returned nothing")
                        self.search_next()
                        return
 
@@ -111,13 +111,13 @@ class LastFMSearch (object):
                image_urls = []
                for tag in parsed.getElementsByTagName('image'):
                        if tag.firstChild is None:
-                               print "got useless image tag"
+                               print("got useless image tag")
                                continue
 
                        url = tag.firstChild.data
                        url.strip()
                        if url != "":
-                               print "found image url: %s" % url
+                               print("found image url: %s" % url)
                                image_urls.append(url)
 
                if len(image_urls) > 0:
@@ -147,12 +147,12 @@ class LastFMSearch (object):
 
        def search(self, key, last_time, store, callback, args):
                if last_time > (time.time() - REPEAT_SEARCH_PERIOD):
-                       print "we already tried this one"
+                       print("we already tried this one")
                        callback (args)
                        return
 
                if user_has_account() == False:
-                       print "can't search: no last.fm account details"
+                       print("can't search: no last.fm account details")
                        callback (args)
                        return
 
@@ -165,7 +165,7 @@ class LastFMSearch (object):
                        album = None
 
                if album == None or len(artists) == 0:
-                       print "can't search: no useful details"
+                       print("can't search: no useful details")
                        callback (args)
                        return
 
diff --git a/plugins/artsearch/local.py b/plugins/artsearch/local.py
index 0d8cd5b..5821403 100644
--- a/plugins/artsearch/local.py
+++ b/plugins/artsearch/local.py
@@ -70,7 +70,7 @@ class LocalSearch:
                                        nkey = RB.ExtDBKey.create_storage("album", album)
                                        nkey.add_field("artist", artist)
                                        uri = parent.resolve_relative_path(f_name).get_uri()
-                                       print "found album+artist match " + uri
+                                       print("found album+artist match " + uri)
                                        self.store.store_uri(nkey, RB.ExtDBSourceType.USER, uri)
 
                # if that didn't work, look for the longest shared prefix
@@ -85,7 +85,7 @@ class LocalSearch:
 
                if match is not None:
                        uri = parent.resolve_relative_path(match).get_uri()
-                       print "found prefix match " + uri
+                       print("found prefix match " + uri)
                        self.store.store_uri(key, RB.ExtDBSourceType.USER, uri)
 
                self.callback(self.callback_args)
@@ -93,15 +93,15 @@ class LocalSearch:
        def _close_enum_cb(self, fileenum, result, results):
                try:
                        fileenum.close_finish(result)
-               except Exception, e:
-                       print "couldn't close file enumerator: %s" % e
+               except Exception as e:
+                       print("couldn't close file enumerator: %s" % e)
                
 
        def _enum_dir_cb(self, fileenum, result, results):
                try:
                        files = fileenum.next_files_finish(result)
                        if files is None or len(files) == 0:
-                               print "okay, done; got %d files" % len(results)
+                               print("okay, done; got %d files" % len(results))
                                fileenum.close_async(GLib.PRIORITY_DEFAULT, None, self._close_enum_cb, None)
                                self.finished(results)
                                return
@@ -116,8 +116,8 @@ class LocalSearch:
                                        results.append(f.get_name())
 
                        fileenum.next_files_async(ITEMS_PER_NOTIFICATION, GLib.PRIORITY_DEFAULT, None, 
self._enum_dir_cb, results)
-               except Exception, e:
-                       print "okay, probably done: %s" % e
+               except Exception as e:
+                       print("okay, probably done: %s" % e)
                        import sys
                        sys.excepthook(*sys.exc_info())
                        self.finished(results)
@@ -128,8 +128,8 @@ class LocalSearch:
                try:
                        enumfiles = parent.enumerate_children_finish(result)
                        enumfiles.next_files_async(ITEMS_PER_NOTIFICATION, GLib.PRIORITY_DEFAULT, None, 
self._enum_dir_cb, [])
-               except Exception, e:
-                       print "okay, probably done: %s" % e
+               except Exception as e:
+                       print("okay, probably done: %s" % e)
                        if not isinstance(e, GLib.GError):
                                import sys
                                sys.excepthook(*sys.exc_info())
@@ -141,7 +141,7 @@ class LocalSearch:
 
                location = key.get_info("location")
                if location is None:
-                       print "not searching, we don't have a location"
+                       print("not searching, we don't have a location")
                        callback(args)
                        return
 
@@ -153,6 +153,6 @@ class LocalSearch:
                self.callback = callback
                self.callback_args = args
 
-               print 'searching for local art for %s' % (self.file.get_uri())
+               print('searching for local art for %s' % (self.file.get_uri()))
                parent = self.file.get_parent()
                enumfiles = 
parent.enumerate_children_async("standard::content-type,access::can-read,standard::name", 0, 0, None, 
self._enum_children_cb, None)
diff --git a/plugins/artsearch/musicbrainz.py b/plugins/artsearch/musicbrainz.py
index 8b271d6..41ff232 100644
--- a/plugins/artsearch/musicbrainz.py
+++ b/plugins/artsearch/musicbrainz.py
@@ -48,7 +48,7 @@ class MusicBrainzSearch(object):
        def get_release_cb (self, data, args):
                (key, store, callback, cbargs) = args
                if data is None:
-                       print "musicbrainz release request returned nothing"
+                       print("musicbrainz release request returned nothing")
                        callback(*cbargs)
                        return
 
@@ -66,7 +66,7 @@ class MusicBrainzSearch(object):
                                        nametags = artist_tags[0].getElementsByTagName('name')
                                        if len(nametags) > 0:
                                                artistname = nametags[0].firstChild.data
-                                               print "got musicbrainz artist name %s" % artistname
+                                               print("got musicbrainz artist name %s" % artistname)
                                                storekey.add_field('artist', artistname)
 
 
@@ -75,16 +75,16 @@ class MusicBrainzSearch(object):
                        if len(asin_tags) > 0:
                                asin = asin_tags[0].firstChild.data
 
-                               print "got ASIN %s" % asin
+                               print("got ASIN %s" % asin)
                                image_url = AMAZON_IMAGE_URL % asin
 
                                store.store_uri(storekey, RB.ExtDBSourceType.SEARCH, image_url)
                        else:
-                               print "no ASIN for this release"
+                               print("no ASIN for this release")
 
                        callback(*cbargs)
-               except Exception, e:
-                       print "exception parsing musicbrainz response: %s" % e
+               except Exception as e:
+                       print("exception parsing musicbrainz response: %s" % e)
                        callback(*cbargs)
 
        def try_search_artist_album (self, key, store, callback, *args):
@@ -92,7 +92,7 @@ class MusicBrainzSearch(object):
                artist = key.get_field("artist")
 
                if not album or not artist:
-                       print "artist or album information missing"
+                       print("artist or album information missing")
                        callback(*args)
                        return
 
@@ -106,7 +106,7 @@ class MusicBrainzSearch(object):
                key = key.copy()        # ugh
                album_id = key.get_info("musicbrainz-albumid")
                if album_id is None:
-                       print "no musicbrainz release ID for this track"
+                       print("no musicbrainz release ID for this track")
                        self.try_search_artist_album(key, store, callback, args)
                        return
 
@@ -116,7 +116,7 @@ class MusicBrainzSearch(object):
                if album_id.endswith(MUSICBRAINZ_RELEASE_SUFFIX):
                        album_id = album_id[:-len(MUSICBRAINZ_RELEASE_SUFFIX)]
 
-               print "stripped release ID: %s" % album_id
+               print("stripped release ID: %s" % album_id)
 
                url = MUSICBRAINZ_RELEASE_URL % (album_id)
                loader = rb.Loader()
diff --git a/plugins/artsearch/oldcache.py b/plugins/artsearch/oldcache.py
index f689e07..9d7d8e3 100644
--- a/plugins/artsearch/oldcache.py
+++ b/plugins/artsearch/oldcache.py
@@ -49,12 +49,12 @@ class OldCacheSearch(object):
                album = key.get_field("album")
                artists = key.get_field_values("artist") or []
 
-               print "looking for %s by %s" % (album, str(artists))
+               print("looking for %s by %s" % (album, str(artists)))
                for artist in artists:
                        for ext in ('jpg', 'png'):
                                path = self.filename(album, artist, ext)
                                if os.path.exists(path):
-                                       print "found %s" % path
+                                       print("found %s" % path)
                                        uri = "file://" + urllib.pathname2url(path)
                                        storekey = RB.ExtDBKey.create_storage('album', album)
                                        storekey.add_field("artist", artist)


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