diff --git a/libsaria/path/lastfm.py b/libsaria/path/lastfm.py index 99c51c05..fea8cbad 100644 --- a/libsaria/path/lastfm.py +++ b/libsaria/path/lastfm.py @@ -68,13 +68,19 @@ def lfm_cache_album(artist, album, title, file): pass return False -def get_album_art(file): - attrs = sources.all_attrs() +def get_album_art(attrs): + print attrs file = cache.get_item(attrs["artist"], attrs["album"], attrs["title"], "Folder.jpg", lfm_cache_album) callbacks.get_art(file, attrs["id"]) -def get_artwork(file): - threading.Thread(target=get_album_art, args=(file,)).start() +def get_artwork(attrs): + threading.Thread(target=get_album_art, args=(attrs,)).start() + +def test_artwork(attrs): + path = cache.test_item(attrs["artist"], attrs["album"], "Folder.jpg", "images/ocarina.png") + if path == "images/ocarina.png": + get_artwork(attrs) + return path def set_artwork(artist, album, img_path): cache.copy_in_file(artist, album, "Folder.jpg", img_path) diff --git a/libsaria/sources/__init__.py b/libsaria/sources/__init__.py index 3486c8b8..b2cdaaa7 100644 --- a/libsaria/sources/__init__.py +++ b/libsaria/sources/__init__.py @@ -79,6 +79,7 @@ def all_attrs(): if found != False: res["like"] = attrs.get_like("like") res["count"] = attrs.get_count("count") + res["art"] = libsaria.path.lastfm.test_artwork(res) return res def filter(text): diff --git a/libsaria/storage/cache.py b/libsaria/storage/cache.py index 695f6822..17a15f61 100644 --- a/libsaria/storage/cache.py +++ b/libsaria/storage/cache.py @@ -39,6 +39,12 @@ def get_item(artist, album, title, file, cache_func): cache_path = fill_cache(artist, album, title, cache_func, cache_path) return cache_path +def test_item(artist, album, file, default): + cache_path = make_cache_path(artist, album, file) + if not file_exists(cache_path): + return default + return cache_path + def copy_in_file(artist, album, file, orig_file): cache_path = make_cache_path(artist, album, file) orig = open(orig_file)