libsaria: Get artwork when songs are loaded

I may change this to something that has to be requested by the front
end, rather than always fetching it.  We'll see.
This commit is contained in:
Bryan Schumaker 2011-04-30 13:41:08 -04:00
parent 889e17fab9
commit d0198cdd1a
5 changed files with 17 additions and 8 deletions

View File

@ -1,5 +1,7 @@
# Bryan Schumaker (4 / 30 / 2011) # Bryan Schumaker (4 / 30 / 2011)
import libsaria
def null_cb(*args): def null_cb(*args):
pass pass
@ -14,6 +16,7 @@ def pause():
on_load = null_cb on_load = null_cb
def load_file(file): def load_file(file):
on_load(file) on_load(file)
libsaria.path.lastfm.get_artwork(file)
on_like = null_cb on_like = null_cb
def like_song(like): def like_song(like):
@ -22,3 +25,7 @@ def like_song(like):
on_set_volume = null_cb on_set_volume = null_cb
def set_volume(prcnt): def set_volume(prcnt):
on_set_volume(prcnt) on_set_volume(prcnt)
on_get_art = null_cb
def get_art(file, id):
on_get_art(file, id)

View File

@ -4,6 +4,8 @@ import libsaria
from libsaria import sources from libsaria import sources
from libsaria import web from libsaria import web
from libsaria import xm from libsaria import xm
from libsaria import callbacks
from libsaria import threads
file_id = libsaria.path.file_id file_id = libsaria.path.file_id
cache = libsaria.cache cache = libsaria.cache
@ -89,8 +91,10 @@ def get_artwork_id(id):
artist, album = sources.get_attrs("artist", "album") artist, album = sources.get_attrs("artist", "album")
return get_artwork_tags(artist, album) return get_artwork_tags(artist, album)
def get_artwork(filepath): def get_artwork_bg(file):
id = sources.get_attrs("id") id = sources.get_attrs("id")
file = get_artwork_id(id) file = get_artwork_id(id)
libsaria.event.start("POSTGETART", file, id) callbacks.get_art(file, id)
libsaria.event.invite("POSTLOAD", get_artwork, True)
def get_artwork(file):
threads.background(get_artwork_bg, file)

View File

@ -15,9 +15,7 @@ class BG_Thread(Thread):
self.func = func self.func = func
self.args = args self.args = args
def run(self): def run(self):
print "running func %s with args %s" % (self.func, self.args)
self.func(*self.args) self.func(*self.args)
print "exiting func %s" % self.func
def background(func, *args): def background(func, *args):

View File

@ -25,7 +25,7 @@ import queue
import library import library
import callbacks import callbacks
callbacks.on_getart("images/ocarina.png", 0) callbacks.on_get_art("images/ocarina.png", 0)
libsaria.startup() libsaria.startup()
print "Startup took:", uptime() print "Startup took:", uptime()
gtk.main() gtk.main()

View File

@ -28,12 +28,12 @@ def on_like(like):
footer.on_like(like) footer.on_like(like)
callbacks.on_like = on_like callbacks.on_like = on_like
def on_getart(path, id): def on_get_art(path, id):
cur_id = libsaria.sources.get_attrs("id") cur_id = libsaria.sources.get_attrs("id")
if id != cur_id: if id != cur_id:
path = "images/ocarina.png" path = "images/ocarina.png"
footer.set_art(path) footer.set_art(path)
invite("POSTGETART", on_getart) callbacks.on_get_art = on_get_art
def on_load_playlist(*args): def on_load_playlist(*args):
playlist.refresh() playlist.refresh()