- Fixes to last.fm interface so that it gets a good sized image, without download GIANT images
- Threading fixes for image downloads
This commit is contained in:
parent
e4db5ad53b
commit
456dc85551
|
@ -148,7 +148,7 @@ class InputQueue(gobject.GObject):
|
|||
self.queue_west = 0
|
||||
self.queue_north = 0
|
||||
|
||||
self.emit("queue-flushed")
|
||||
if not self.accelerating: self.emit("queue-flushed")
|
||||
|
||||
|
||||
def is_in_queue(self):
|
||||
|
@ -187,5 +187,6 @@ class InputQueue(gobject.GObject):
|
|||
return True
|
||||
|
||||
self.accelerating = False
|
||||
self.emit("queue-flushed")
|
||||
#print "Deceleration finished"
|
||||
return False
|
|
@ -12,6 +12,11 @@ class lastFM_interface:
|
|||
lastFM_album_xml_uri = lastFM_base_xml_uri + "album/"
|
||||
lastFM_track_xml_uri = lastFM_base_xml_uri + "track/"
|
||||
|
||||
#Maximum size of images returned
|
||||
#If images are larger than this, they will be downloaded and resized
|
||||
max_image_width = 800
|
||||
max_image_height = 600
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
|
@ -36,8 +41,9 @@ class lastFM_interface:
|
|||
if xml_string[0:len(error_string)] == error_string:
|
||||
return None
|
||||
|
||||
#We make a little manual change to the url, so that we get the BIG pic off last.FM rather than the 160x160 one
|
||||
xml_string = xml_string.replace("/160/", "/_/")
|
||||
#We make a little manual change to the url, so that we get a bigger pic off last.FM rather than the 160x160 one
|
||||
#xml_string = xml_string.replace("/160/", "/_/") #Force use this to get BIG images
|
||||
xml_string = xml_string.replace("/160/", "/500/") #Attempt to use the 500 size image
|
||||
|
||||
#Because we only read in 2 lines, we need to manually close the block
|
||||
xml_string += "</similarartists>"
|
||||
|
@ -51,6 +57,14 @@ class lastFM_interface:
|
|||
print "LastFM Error: URI Attempted '%s'" % (similar_uri)
|
||||
return None
|
||||
|
||||
#We do a check to see if a 500 size image exists
|
||||
#If not, fall back onto the _ size image (ie the Biggest Last.fm has)
|
||||
img_handle = urllib.urlopen(pic_url)
|
||||
img_size = int(img_handle.info().getheader("Content-Length"))
|
||||
if img_size == 0:
|
||||
pic_url = pic_url.replace("/500/", "/_/")
|
||||
img_handle.close()
|
||||
|
||||
return self.get_pixbuf_from_url(pic_url)
|
||||
|
||||
|
||||
|
@ -77,5 +91,18 @@ class lastFM_interface:
|
|||
print "Last.FM: '%s'" % (e)
|
||||
#print "Last.FM: Received invalid image file: '%s' " % (pic_url)
|
||||
|
||||
return loader.get_pixbuf()
|
||||
pixbuf = loader.get_pixbuf()
|
||||
|
||||
#If the image is larger than our maximum size, shrink it down
|
||||
#This should _generally_ not be needed, but will be used whenver last.fm returns a very large image by mistake
|
||||
if pixbuf.get_width() > self.max_image_width:
|
||||
yx_ratio = float(pixbuf.get_height()) / float(pixbuf.get_width())
|
||||
height = int(self.max_image_width * yx_ratio)
|
||||
pixbuf = pixbuf.scale_simple(self.max_image_width, height, gtk.gdk.INTERP_HYPER)
|
||||
elif pixbuf.get_height() > self.max_image_height:
|
||||
xy_ratio = float(pixbuf.get_width()) / float(pixbuf.get_height())
|
||||
width = int(self.max_image_height * xy_ratio)
|
||||
pixbuf = pixbuf.scale_simple(width, self.max_image_height, gtk.gdk.INTERP_HYPER)
|
||||
|
||||
return pixbuf
|
||||
|
|
@ -57,10 +57,13 @@ class artist(MusicObject):
|
|||
#We send a request off to LastFM to grab an image.
|
||||
#This will emit the "image-found" signal when and if it was successful
|
||||
#gobject.idle_add(self.get_image_from_lastFM)
|
||||
thread = threading.Thread(target=self.get_image_from_lastFM)
|
||||
thread.start()
|
||||
#thread.start_new_thread(self.get_image_from_lastFM, (None,))
|
||||
#pixbuf = self.get_image_from_lastFM()
|
||||
try:
|
||||
thread = threading.Thread(target=self.get_image_from_lastFM)
|
||||
thread.start()
|
||||
except thread.error, e:
|
||||
"Music_Player: Attempted to start too many threads"
|
||||
#Returning None forces the default image to be used
|
||||
return None
|
||||
return self.PENDING_DOWNLOAD
|
||||
|
||||
def get_image_from_lastFM(self):
|
||||
|
|
Loading…
Reference in New Issue