|
@ -98,10 +98,10 @@ class Song: |
|
|
def __init__(self, subpath, config, *, datadir=None): |
|
|
def __init__(self, subpath, config, *, datadir=None): |
|
|
if datadir is None: |
|
|
if datadir is None: |
|
|
self.datadir = "" |
|
|
self.datadir = "" |
|
|
|
|
|
# Only songs in datadirs may be cached |
|
|
self.use_cache = False |
|
|
self.use_cache = False |
|
|
else: |
|
|
else: |
|
|
self.datadir = datadir |
|
|
self.datadir = datadir |
|
|
# Only songs in datadirs are cached |
|
|
|
|
|
self.use_cache = ('_cache' in config) |
|
|
self.use_cache = ('_cache' in config) |
|
|
|
|
|
|
|
|
self.fullpath = os.path.join(self.datadir, subpath) |
|
|
self.fullpath = os.path.join(self.datadir, subpath) |
|
@ -145,11 +145,10 @@ class Song: |
|
|
|
|
|
|
|
|
def _cache_retrieved(self): |
|
|
def _cache_retrieved(self): |
|
|
"""If relevant, retrieve self from the cache.""" |
|
|
"""If relevant, retrieve self from the cache.""" |
|
|
if self.use_cache: |
|
|
if self.use_cache and os.path.exists(self.cached_name): |
|
|
self._filehash = hashlib.md5( |
|
|
self._filehash = hashlib.md5( |
|
|
open(self.fullpath, 'rb').read() |
|
|
open(self.fullpath, 'rb').read() |
|
|
).hexdigest() |
|
|
).hexdigest() |
|
|
if os.path.exists(self.cached_name): |
|
|
|
|
|
try: |
|
|
try: |
|
|
cached = pickle.load(open( |
|
|
cached = pickle.load(open( |
|
|
self.cached_name, |
|
|
self.cached_name, |
|
|