Load files named AlbumArt.jpg in the playing album's directory. If it doesn't exist, fetch it from last.fm
git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@57 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
parent
bb0dbd0c27
commit
34f40a7165
|
@ -1,5 +1,6 @@
|
|||
import gtk
|
||||
import gobject
|
||||
import os
|
||||
|
||||
from label import Label
|
||||
from queue import Queue
|
||||
|
@ -20,6 +21,7 @@ class ContentPane(gtk.HBox):
|
|||
|
||||
self.divider = gtk.HPaned()
|
||||
self.divider.set_position(self.data.divider)
|
||||
self.divider.connect("notify",self.moveDivider)
|
||||
self.divider.show()
|
||||
self.add(self.divider)
|
||||
|
||||
|
@ -27,11 +29,25 @@ class ContentPane(gtk.HBox):
|
|||
self.makeRightSide()
|
||||
|
||||
self.show()
|
||||
# Load up the last saved song
|
||||
self.library.loadSong(self.data.library.files[self.data.curSong])
|
||||
self.gotoCurSong()
|
||||
|
||||
|
||||
# Left side is scrobbler, album art, maybe others at some point?
|
||||
def makeLeftSide(self):
|
||||
vbox = gtk.VBox(False,0)
|
||||
vbox.show()
|
||||
|
||||
self.albumArt = Image(None,None)
|
||||
#vbox.pack_start(self.albumArt,False,False,0)
|
||||
vbox.pack_start(self.albumArt,False,False,0)
|
||||
|
||||
self.data.scrobbler = Scrobbler(self.data)
|
||||
self.divider.add1(self.data.scrobbler)
|
||||
vbox.pack_start(self.data.scrobbler,False,False,0)
|
||||
|
||||
self.divider.add(vbox)
|
||||
#self.divider.add1(self.data.scrobbler)
|
||||
|
||||
|
||||
# Right side has tabs, current song info, controls, and more
|
||||
|
@ -112,7 +128,7 @@ class ContentPane(gtk.HBox):
|
|||
self.tabs.show()
|
||||
|
||||
# Ann array of function pointers that gets passed to List
|
||||
funcs = [self.next,self.setLabels,self.plause]
|
||||
funcs = [self.next,self.setLabels,self.plause,self.setAlbumArt]
|
||||
|
||||
self.queue = Queue(self.data,funcs)
|
||||
self.playlist = Playlist(self.data,self.queue,funcs)
|
||||
|
@ -164,16 +180,19 @@ class ContentPane(gtk.HBox):
|
|||
return image,button
|
||||
|
||||
|
||||
# Turn shuffle on/off
|
||||
def toggleRand(self,widgit):
|
||||
self.data.random = not self.data.random
|
||||
|
||||
|
||||
# A callback for when the user seeks into the song
|
||||
def pbarclick(self,widgit,data,pbar):
|
||||
if data.button==1:
|
||||
prcnt = float(data.x) / float(pbar.get_allocation()[2])
|
||||
self.data.song.seek(int(prcnt * self.data.song.info.duration * 1000000000))
|
||||
|
||||
|
||||
# Updates the progress bar to the current % of song
|
||||
def updatePBar(self,pbar):
|
||||
time = 0
|
||||
if not self.data.song:
|
||||
|
@ -188,16 +207,19 @@ class ContentPane(gtk.HBox):
|
|||
return True
|
||||
|
||||
|
||||
# Called when the play/pause button is clicked
|
||||
def plause(self,widgit,data):
|
||||
self.data.song.plause()
|
||||
self.changeImg()
|
||||
|
||||
|
||||
# Stop the song, change plause button
|
||||
def stop(self,widgit,data):
|
||||
self.data.song.stop()
|
||||
self.changeImg()
|
||||
|
||||
|
||||
# Advance to the next song, save updates
|
||||
def next(self,widgit,data):
|
||||
loaded = self.queue.getNext()
|
||||
#print loaded
|
||||
|
@ -213,7 +235,6 @@ class ContentPane(gtk.HBox):
|
|||
|
||||
# Scroll to the current song
|
||||
def gotoCurSong(self):
|
||||
print "here!"
|
||||
self.playlist.gotoCurSong()
|
||||
self.queue.gotoCurSong()
|
||||
self.library.gotoCurSong()
|
||||
|
@ -226,6 +247,22 @@ class ContentPane(gtk.HBox):
|
|||
self.plauseBtn.set_image(self.pauseImg)
|
||||
|
||||
|
||||
# Load album art
|
||||
def setAlbumArt(self,file):
|
||||
file = file.rsplit('/',1)[0]
|
||||
file = os.path.join(file,"AlbumArt.jpg")
|
||||
# Fetch album art if we don't have it yet
|
||||
if not os.path.exists(file):
|
||||
info = self.data.song.info
|
||||
self.data.scrobbler.fetchAlbumArt(info.artist,info.album,file)
|
||||
self.albumArt.set(file)
|
||||
self.resizeAlbumArt()
|
||||
|
||||
|
||||
def resizeAlbumArt(self):
|
||||
self.albumArt.scale(self.data.divider)
|
||||
|
||||
|
||||
# This is called when a user changes tabs
|
||||
# Do nothing if the user selects the same tab
|
||||
# Otherwise, hide objects on the old visible tab and show the new visible tab
|
||||
|
@ -310,3 +347,9 @@ class ContentPane(gtk.HBox):
|
|||
self.queue.storeCols()
|
||||
else:
|
||||
self.library.storeCols()
|
||||
|
||||
|
||||
def moveDivider(self,pane,event):
|
||||
if event.name=="position":
|
||||
self.data.divider = pane.get_position()
|
||||
self.resizeAlbumArt()
|
||||
|
|
|
@ -4,8 +4,30 @@ import gtk
|
|||
class Image(gtk.Image):
|
||||
def __init__(self,path,stock):
|
||||
gtk.Image.__init__(self)
|
||||
self.file = None
|
||||
if path:
|
||||
self.file = path
|
||||
self.set_from_file(path)
|
||||
else:
|
||||
self.pixbuf = self.get_pixbuf()
|
||||
elif stock:
|
||||
self.set_from_stock(stock,gtk.ICON_SIZE_SMALL_TOOLBAR)
|
||||
self.show()
|
||||
|
||||
|
||||
# Set image from a file
|
||||
def set(self,file):
|
||||
self.file = file
|
||||
self.pixbuf = gtk.gdk.pixbuf_new_from_file(file)
|
||||
self.set_from_pixbuf(self.pixbuf)
|
||||
|
||||
|
||||
# Scale the image
|
||||
def scale(self,divider):
|
||||
if self.file:
|
||||
self.set(self.file)
|
||||
w = self.pixbuf.get_width()
|
||||
h = self.pixbuf.get_height()
|
||||
# w * scale = divider
|
||||
scale = divider / float(w)
|
||||
self.pixbuf = self.pixbuf.scale_simple(int(w*scale),int(h*scale),gtk.gdk.INTERP_BILINEAR)
|
||||
self.set_from_pixbuf(self.pixbuf)
|
||||
|
|
|
@ -5,7 +5,7 @@ from menuItem import MenuItem
|
|||
from song import Song
|
||||
|
||||
class List(gtk.ScrolledWindow):
|
||||
def __init__(self,data,text,(nextFunc,labelFunc,plauseFunc)):
|
||||
def __init__(self,data,text,(nextFunc,labelFunc,plauseFunc,albumArtFunc)):
|
||||
gtk.ScrolledWindow.__init__(self)
|
||||
self.show()
|
||||
self.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
|
||||
|
@ -17,6 +17,7 @@ class List(gtk.ScrolledWindow):
|
|||
self.next = nextFunc
|
||||
self.labels = labelFunc
|
||||
self.plause = plauseFunc
|
||||
self.setAlbumArt = albumArtFunc
|
||||
|
||||
self.count = 0
|
||||
self.seconds = 0
|
||||
|
@ -203,12 +204,14 @@ class List(gtk.ScrolledWindow):
|
|||
self.sel.unselect_path(path)
|
||||
|
||||
|
||||
# Prepare the next song for playing
|
||||
def loadSong(self,file):
|
||||
if self.data.song:
|
||||
self.data.scrobbler.submit(self.data.song.timestamp)
|
||||
self.data.song.close()
|
||||
self.data.song = Song(file,self.next)
|
||||
self.data.curSong = file.id
|
||||
self.setAlbumArt(file.filename)
|
||||
self.labels()
|
||||
self.gotoCurSong()
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class main:
|
|||
if self.data.song:
|
||||
self.data.song.close()
|
||||
self.data.size = self.window.get_size()
|
||||
self.data.divider = self.window.contentPane.divider.get_position()
|
||||
#self.data.divider = self.window.contentPane.divider.get_position()
|
||||
self.window.contentPane.storeCols()
|
||||
self.data.dump()
|
||||
gtk.main_quit()
|
||||
|
|
|
@ -176,6 +176,7 @@ class Scrobbler(gtk.VBox):
|
|||
#print status
|
||||
|
||||
|
||||
# Fetch similar artists
|
||||
def fetchSimilar(self,artist):
|
||||
(url,list) = self.addMethod(self.url,"artist.getsimilar")
|
||||
(url,list) = self.addParam(url,list,"artist",artist)
|
||||
|
@ -191,6 +192,35 @@ class Scrobbler(gtk.VBox):
|
|||
#for node in status.firstChild.childNodes:
|
||||
# print node
|
||||
|
||||
|
||||
# Retreive album art from last.fm
|
||||
def fetchAlbumArt(self,artist,album,path):
|
||||
if self.data.lfm == None:
|
||||
return
|
||||
if self.session == None:
|
||||
self.handshake()
|
||||
(url,list) = self.addMethod(self.url,"album.getInfo")
|
||||
(url,list) = self.addParam(url,list,"artist",artist)
|
||||
(url,list) = self.addParam(url,list,"album",album)
|
||||
(url,list) = self.addParam(url,list,"api_key",self.key)
|
||||
status = self.parseRequest(url)
|
||||
list = status.childNodes
|
||||
imgUrl = ""
|
||||
for i in range(list.length):
|
||||
items = list.item(i).childNodes
|
||||
for node in items:
|
||||
if node.hasChildNodes() == True:
|
||||
if node.tagName == "image":
|
||||
imgUrl = node.firstChild.data
|
||||
print imgUrl
|
||||
imgIn = urllib2.urlopen(imgUrl)
|
||||
out = open(path,'w')
|
||||
out.write(imgIn.read())
|
||||
imgIn.close()
|
||||
out.close()
|
||||
|
||||
|
||||
|
||||
def authToken(self,t):
|
||||
return self.md5(self.data.lfmpass+t)
|
||||
|
||||
|
|
Loading…
Reference in New Issue