Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -rupN sonata/artwork.py sonata-patched/artwork.py
- --- sonata/artwork.py 2009-09-02 02:23:48.000000000 -0700
- +++ sonata-patched/artwork.py 2009-09-02 02:24:02.000000000 -0700
- @@ -9,10 +9,7 @@ import img, ui, misc, mpdhelper as mpdh
- from library import library_set_data
- from library import library_get_data
- from consts import consts
- -
- -AMAZON_KEY = "12DR2PGAQT303YTEWP02"
- -AMAZON_NS = "{http://webservices.amazon.com/AWSECommerceService/2005-10-05}"
- -AMAZON_URI = "http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=%s&Operation=ItemSearch&SearchIndex=Music&Artist=%s&ResponseGroup=Images"
- +from pluginsystem import pluginsystem
- class Artwork(object):
- def __init__(self, config, find_path, is_lang_rtl, info_imagebox_get_size_request, schedule_gc_collect, target_image_filename, imagelist_append, remotefilelist_append, notebook_get_allocation, allow_art_search, status_is_play_or_pause, album_filename, get_current_song_text):
- @@ -529,71 +526,38 @@ class Artwork(object):
- return False
- def artwork_download_img_to_file(self, artist, album, dest_filename, all_images=False):
- - # Returns False if no images found
- - if not artist and not album:
- - self.downloading_image = False
- - return False
- self.downloading_image = True
- - # Amazon currently doesn't support utf8 and suggests latin1 encoding instead:
- - artist = urllib.quote(artist.encode('latin1', 'replace'))
- - album = urllib.quote(album.encode('latin1', 'replace'))
- -
- - # Try searching urls from most specific (artist, title) to least specific (artist only)
- - urls = [AMAZON_URI % (AMAZON_KEY, artist) + "&Title=" + album,
- - AMAZON_URI % (AMAZON_KEY, artist) + "&Keywords=" + album,
- - AMAZON_URI % (AMAZON_KEY, artist)]
- -
- - for url in urls:
- - request = urllib2.Request(url)
- - opener = urllib2.build_opener()
- - try:
- - body = opener.open(request).read()
- - xml = ElementTree.fromstring(body)
- - largeimgs = xml.getiterator(AMAZON_NS + "LargeImage")
- - except:
- - largeimgs = None
- + # Fetch covers from amazon.com etc.
- + cover_fetchers = pluginsystem.get('cover_fetching')
- + imgfound = False
- + for _plugin, cb in cover_fetchers:
- + ret = cb(self.download_progress, artist, album, dest_filename, all_images)
- + if ret:
- + imgfound = True
- + break # XXX if all_images, merge results...
- - if largeimgs:
- - break
- - elif url == urls[-1]:
- - self.downloading_image = False
- - return False
- -
- - imgs = misc.iunique(url.text for img in largeimgs for url in img.getiterator(AMAZON_NS + "URL"))
- - # Prevent duplicate images in remote art window:
- - imglist = list(set(list(imgs)))
- -
- - if not all_images:
- - urllib.urlretrieve(imglist[0], dest_filename)
- - self.downloading_image = False
- - return True
- - else:
- - try:
- - imgfound = False
- - for i, image in enumerate(imglist):
- - dest_filename_curr = dest_filename.replace("<imagenum>", str(i+1))
- - urllib.urlretrieve(image, dest_filename_curr)
- - # This populates Main.imagelist for the remote image window
- - if os.path.exists(dest_filename_curr):
- - pix = gtk.gdk.pixbuf_new_from_file(dest_filename_curr)
- - pix = pix.scale_simple(148, 148, gtk.gdk.INTERP_HYPER)
- - pix = self.artwork_apply_composite_case(pix, 148, 148)
- - pix = img.pixbuf_add_border(pix)
- - if self.stop_art_update:
- - del pix
- - self.downloading_image = False
- - return imgfound
- - self.imagelist_append([i+1, pix])
- - del pix
- - imgfound = True
- - self.remotefilelist_append(dest_filename_curr)
- - if i == 0:
- - self.allow_art_search()
- - ui.change_cursor(None)
- - except:
- - pass
- - self.downloading_image = False
- - return imgfound
- + self.downloading_image = False
- + return imgfound
- +
- + def download_progress(self, dest_filename_curr, i):
- + # This populates Main.imagelist for the remote image window
- + if os.path.exists(dest_filename_curr):
- + pix = gtk.gdk.pixbuf_new_from_file(dest_filename_curr)
- + pix = pix.scale_simple(148, 148, gtk.gdk.INTERP_HYPER)
- + pix = self.artwork_apply_composite_case(pix, 148, 148)
- + pix = img.pixbuf_add_border(pix)
- + if self.stop_art_update:
- + del pix
- + return False # don't continue to next image
- + self.imagelist_append([i+1, pix])
- + del pix
- + self.remotefilelist_append(dest_filename_curr)
- + if i == 0:
- + self.allow_art_search()
- +
- + ui.change_cursor(None) # XXX indented twice more?
- +
- + return True # continue to next image
- def fullscreen_cover_art_set_image(self, force_update=False):
- if self.fullscreenalbumimage.get_property('visible') or force_update:
- diff -rupN sonata/main.py sonata-patched/main.py
- --- sonata/main.py 2009-09-02 02:23:48.000000000 -0700
- +++ sonata-patched/main.py 2009-09-02 02:24:02.000000000 -0700
- @@ -59,6 +59,7 @@ from consts import consts
- from pluginsystem import pluginsystem
- from preferences import *
- from config import Config
- +import rhapsodycovers
- import tagedit, artwork, about, scrobbler, info, library, streams, playlists, current
- import dbus_plugin as dbus
- @@ -230,6 +231,7 @@ class Base(object):
- # Artwork
- self.artwork = artwork.Artwork(self.config, self.find_path, misc.is_lang_rtl(self.window), lambda:self.info_imagebox.get_size_request(), self.schedule_gc_collect, self.target_image_filename, self.imagelist_append, self.remotefilelist_append, self.notebook.get_allocation, self.set_allow_art_search, self.status_is_play_or_pause, self.find_path('sonata-album.png'), self.get_current_song_text)
- + self.rhapsodycovers = rhapsodycovers.RhapsodyCovers()
- # Popup menus:
- actions = (
- diff -rupN sonata/pluginsystem.py sonata-patched/pluginsystem.py
- --- sonata/pluginsystem.py 2009-09-02 02:23:48.000000000 -0700
- +++ sonata-patched/pluginsystem.py 2009-09-02 02:24:02.000000000 -0700
- @@ -87,7 +87,22 @@ class Plugin(object):
- def force_loaded(self):
- return bool(self._get_module())
- -
- +
- +class BuiltinPlugin(Plugin):
- + def __init__(self, name, longname, description, capabilities, object):
- + self.name = name
- + self.longname = longname
- + self.description = description
- + self._capabilities = capabilities
- + self._module = object
- + self.version_string = "Built-in"
- + self.author = self.author_email = self.url = ""
- + self.iconurl = None
- + self._enabled = True
- +
- + def _get_module(self):
- + return self._module
- +
- class PluginSystem(object):
- def __init__(self):
- self.plugin_infos = []
- Binary files sonata/pluginsystem.pyc and sonata-patched/pluginsystem.pyc differ
- Binary files sonata/preferences.pyc and sonata-patched/preferences.pyc differ
- diff -rupN sonata/rhapsodycovers.py sonata-patched/rhapsodycovers.py
- --- sonata/rhapsodycovers.py 1969-12-31 16:00:00.000000000 -0800
- +++ sonata-patched/rhapsodycovers.py 2009-09-02 02:24:02.000000000 -0700
- @@ -0,0 +1,61 @@
- +import os
- +import urllib
- +import urllib2
- +from xml.etree import ElementTree
- +
- +from pluginsystem import pluginsystem, BuiltinPlugin
- +
- +class RhapsodyCovers(object):
- + def __init__(self):
- + pluginsystem.plugin_infos.append(BuiltinPlugin(
- + 'rhapsodycovers', "Rhapsody Covers",
- + "Fetch album covers from Rhapsody.com.",
- + {'cover_fetching': 'get_cover'}, self))
- +
- + def _sanitize_query(self, str):
- + return str.replace(" ", "").replace("'", "").replace("&","")
- +
- + def get_cover(self, progress_callback, artist, album, dest_filename,
- + all_images=False):
- + return self.artwork_download_img_to_file(progress_callback, artist, album, dest_filename, all_images)
- +
- + def artwork_download_img_to_file(self, progress_callback, artist, album, dest_filename, all_images=False):
- + if not artist and not album:
- + return False
- +
- + rhapsody_uri = "http://feeds.rhapsody.com"
- + url = "%s/%s/%s/data.xml" % (rhapsody_uri, artist, album)
- + url = self._sanitize_query(url)
- + request = urllib2.Request(url)
- + opener = urllib2.build_opener()
- + try:
- + print "in here"
- + body = opener.open(request).read()
- + xml = ElementTree.fromstring(body)
- + imgs = xml.getiterator("img")
- + except:
- + return False
- +
- + imglist = [img.attrib['src'] for img in imgs if img.attrib['src']]
- + print imglist
- + # Couldn't find any images
- + if not imglist:
- + return False
- +
- + if not all_images:
- + urllib.urlretrieve(imglist[0], dest_filename)
- + return True
- + else:
- + try:
- + imgfound = False
- + for i, image in enumerate(imglist):
- + dest_filename_curr = dest_filename.replace("<imagenum>", str(i+1))
- + urllib.urlretrieve(image, dest_filename_curr)
- + if not progress_callback(
- + dest_filename_curr, i):
- + return imgfound # cancelled
- + if os.path.exists(dest_filename_curr):
- + imgfound = True
- + except:
- + pass
- +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement