From d0198cdd1ad1efe515b9c387c4599319c960dc61 Mon Sep 17 00:00:00 2001 From: Bryan Schumaker Date: Sat, 30 Apr 2011 13:41:08 -0400 Subject: [PATCH] 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. --- libsaria/callbacks.py | 7 +++++++ libsaria/path/lastfm.py | 10 +++++++--- libsaria/threads.py | 2 -- ocarina/__init__.py | 2 +- ocarina/callbacks.py | 4 ++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/libsaria/callbacks.py b/libsaria/callbacks.py index fcd1bc97..24158c2d 100644 --- a/libsaria/callbacks.py +++ b/libsaria/callbacks.py @@ -1,5 +1,7 @@ # Bryan Schumaker (4 / 30 / 2011) +import libsaria + def null_cb(*args): pass @@ -14,6 +16,7 @@ def pause(): on_load = null_cb def load_file(file): on_load(file) + libsaria.path.lastfm.get_artwork(file) on_like = null_cb def like_song(like): @@ -22,3 +25,7 @@ def like_song(like): on_set_volume = null_cb def set_volume(prcnt): on_set_volume(prcnt) + +on_get_art = null_cb +def get_art(file, id): + on_get_art(file, id) diff --git a/libsaria/path/lastfm.py b/libsaria/path/lastfm.py index f877a6d8..258b9d63 100644 --- a/libsaria/path/lastfm.py +++ b/libsaria/path/lastfm.py @@ -4,6 +4,8 @@ import libsaria from libsaria import sources from libsaria import web from libsaria import xm +from libsaria import callbacks +from libsaria import threads file_id = libsaria.path.file_id cache = libsaria.cache @@ -89,8 +91,10 @@ def get_artwork_id(id): artist, album = sources.get_attrs("artist", "album") return get_artwork_tags(artist, album) -def get_artwork(filepath): +def get_artwork_bg(file): id = sources.get_attrs("id") file = get_artwork_id(id) - libsaria.event.start("POSTGETART", file, id) -libsaria.event.invite("POSTLOAD", get_artwork, True) + callbacks.get_art(file, id) + +def get_artwork(file): + threads.background(get_artwork_bg, file) diff --git a/libsaria/threads.py b/libsaria/threads.py index fd50d5ad..e1ff1f1e 100644 --- a/libsaria/threads.py +++ b/libsaria/threads.py @@ -15,9 +15,7 @@ class BG_Thread(Thread): self.func = func self.args = args def run(self): - print "running func %s with args %s" % (self.func, self.args) self.func(*self.args) - print "exiting func %s" % self.func def background(func, *args): diff --git a/ocarina/__init__.py b/ocarina/__init__.py index a5111d49..04168bce 100644 --- a/ocarina/__init__.py +++ b/ocarina/__init__.py @@ -25,7 +25,7 @@ import queue import library import callbacks -callbacks.on_getart("images/ocarina.png", 0) +callbacks.on_get_art("images/ocarina.png", 0) libsaria.startup() print "Startup took:", uptime() gtk.main() diff --git a/ocarina/callbacks.py b/ocarina/callbacks.py index c252e98c..d5bee5d4 100644 --- a/ocarina/callbacks.py +++ b/ocarina/callbacks.py @@ -28,12 +28,12 @@ def on_like(like): footer.on_like(like) callbacks.on_like = on_like -def on_getart(path, id): +def on_get_art(path, id): cur_id = libsaria.sources.get_attrs("id") if id != cur_id: path = "images/ocarina.png" footer.set_art(path) -invite("POSTGETART", on_getart) +callbacks.on_get_art = on_get_art def on_load_playlist(*args): playlist.refresh()