libsaria: Set artwork from a local file

I set it in the new cache, rather than using the old one.
This commit is contained in:
Bryan Schumaker 2011-05-07 16:45:04 -04:00
parent 0f1b5550aa
commit 2a78d870ee
3 changed files with 11 additions and 15 deletions

View File

@ -68,20 +68,6 @@ def lfm_cache_album(artist, album, title, file):
pass
return False
def set_art_from_file(file, path):
try:
fin = open(path)
file.write(fin.read())
fin.close()
except:
return False
return True
def set_artwork_tags(artist, album, path):
cached = cache[artist]
cached.delete("%s.jpg" % album)
file = cached.get("%s.jpg" % album, set_art_from_file, path)
def get_album_art(file):
id, artist, album, title = sources.get_attrs("id", "artist", "album", "title")
file = cache.get_item(artist, album, title, "Folder.jpg", lfm_cache_album)
@ -89,3 +75,9 @@ def get_album_art(file):
def get_artwork(file):
threads.background(get_album_art, file)
def set_artwork(artist, album, img_path):
file = cache.open_file(artist, album, "Folder.jpg")
new_img = open(img_path)
file.write(new_img.read())
file.close()

View File

@ -190,7 +190,7 @@ def set_attr(id, attr, new_value):
if attr == "art":
from libsaria import lastfm
artist, album = get_attrs(id, "artist", "album")
lastfm.set_artwork_tags(artist, album, new_value)
lastfm.set_artwork(artist, album, new_value)
else:
rec.__dict__[attr] = new_value
save()

View File

@ -36,3 +36,7 @@ def get_item(artist, album, title, file, cache_func):
if not file_exists(cache_path):
cache_path = fill_cache(artist, album, title, cache_func, cache_path)
return cache_path
def open_file(artist, album, file):
cache_path = make_cache_path(artist, album, file)
return open(cache_path, 'w')