libsaria: Don't automatically create cache file
The cache filler function will pass back a string to be written to this file. If this string != None, then I create the file and fill it.
This commit is contained in:
parent
e6849dc5cd
commit
7319767ac3
|
@ -48,7 +48,7 @@ class LastFmRequest(dict):
|
|||
else:
|
||||
return None
|
||||
|
||||
def lfm_cache_album(artist, album, title, file):
|
||||
def lfm_cache_album(artist, album, title):
|
||||
req = LastFmRequest("album.getInfo")
|
||||
req["album"] = album
|
||||
req["artist"] = artist
|
||||
|
@ -61,16 +61,16 @@ def lfm_cache_album(artist, album, title, file):
|
|||
return
|
||||
try:
|
||||
url = web.Url(node.data)
|
||||
for line in url.open():
|
||||
file.write(line)
|
||||
return True
|
||||
text = url.open().read()
|
||||
return text
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
return None
|
||||
|
||||
def get_album_art(attrs):
|
||||
file = cache.get_item(attrs["artist"], attrs["album"], attrs["title"], "Folder.jpg", lfm_cache_album)
|
||||
callbacks.get_art(file, attrs["id"])
|
||||
file = cache.get_item(attrs["artist"], attrs["album"], attrs["title"], "Folder.jpg", lfm_cache_album, "images/ocarina.png")
|
||||
if file != None:
|
||||
callbacks.get_art(file, attrs["id"])
|
||||
|
||||
def get_artwork(attrs):
|
||||
threading.Thread(target=get_album_art, args=(attrs,)).start()
|
||||
|
|
|
@ -30,18 +30,21 @@ def make_cache_path(artist, album, file):
|
|||
return join(cache_path, file)
|
||||
|
||||
def fill_cache(artist, album, title, cache_func, cache_path):
|
||||
f = open(cache_path, 'w')
|
||||
cache_func(artist, album, title, f)
|
||||
f.close()
|
||||
if file_empty(cache_path):
|
||||
os.remove(cache_path)
|
||||
return None
|
||||
return cache_path
|
||||
text = cache_func(artist, album, title)
|
||||
if text != None:
|
||||
f = open(cache_path, 'w')
|
||||
f.write(text)
|
||||
f.close()
|
||||
return True
|
||||
return False
|
||||
|
||||
def get_item(artist, album, title, file, cache_func):
|
||||
def get_item(artist, album, title, file, cache_func, default):
|
||||
cache_path = make_cache_path(artist, album, file)
|
||||
filled = True
|
||||
if not file_exists(cache_path):
|
||||
cache_path = fill_cache(artist, album, title, cache_func, cache_path)
|
||||
filled = fill_cache(artist, album, title, cache_func, cache_path)
|
||||
if filled == False:
|
||||
return default
|
||||
return cache_path
|
||||
|
||||
def test_item(artist, album, file, default):
|
||||
|
|
Loading…
Reference in New Issue