39 lines
1017 B
Python
39 lines
1017 B
Python
# Bryan Schumaker (5 / 6 / 2011)
|
|
|
|
import os
|
|
import libsaria
|
|
|
|
join = os.path.join
|
|
sep = os.path.sep
|
|
isfile = os.path.isfile
|
|
isdir = os.path.isdir
|
|
getsize = os.path.getsize
|
|
|
|
def file_exists(cache_path):
|
|
if not isfile(cache_path):
|
|
return False
|
|
return getsize(cache_path) != 0
|
|
|
|
def make_cache_path(artist, album, file):
|
|
cache_dir = libsaria.storage.full_path("cache")
|
|
cache_file = "%s%s%s%s" % (artist, sep, album, sep)
|
|
cache_path = join(cache_dir, cache_file)
|
|
if not isdir(cache_path):
|
|
os.makedirs(cache_path)
|
|
return join(cache_path, file)
|
|
|
|
def read_cache(artist, album, title, cache_func, cache_path):
|
|
f = open(cache_path, 'w')
|
|
cache_func(f, artist, album, title)
|
|
f.close()
|
|
if not file_exists(cache_path):
|
|
os.remove(cache_path)
|
|
return None
|
|
return cache_path
|
|
|
|
def get_item(artist, album, title, file, cache_func):
|
|
cache_path = make_cache_path(artist, album, file)
|
|
if not file_exists(cache_path):
|
|
cache_path = fill_cache(artist, album, title, cache_func, cache_path)
|
|
return cache_path
|