Fix caching of top-level items

patches
Jerome Charaoui 2014-02-13 23:28:59 -05:00
parent ecbd6d5552
commit 52667388e9
2 changed files with 10 additions and 6 deletions

View File

@ -24,14 +24,16 @@ def trim_base_custom(path, base):
return path
def trim_base(path):
return trim_base_custom(path, trim_base.base)
def cache_base(path):
def cache_base(path, filepath=False):
if len(path) == 0:
return "root"
elif filepath and len(path.split(os.sep)) < 2:
path = "root-" + path
path = trim_base(path).replace('/', '-').replace(' ', '_').replace('(', '').replace('&', '').replace(',', '').replace(')', '').replace('#', '').replace('[', '').replace(']', '').replace('"', '').replace("'", '').replace('_-_', '-').lower()
while path.find("--") != -1:
path = path.replace("--", "-")
while path.find("__") != -1:
path = path.replace("__", "_")
if len(path) == 0:
path = "root"
return path
def json_cache(path):
return cache_base(path) + ".json"
@ -40,6 +42,8 @@ def image_cache(path, size, square=False):
suffix = str(size) + "s"
else:
suffix = str(size)
return cache_base(path) + "_" + suffix + ".jpg"
return cache_base(path, True) + "_" + suffix + ".jpg"
def video_cache(path):
return cache_base(path, True) + ".webm"
def file_mtime(path):
return datetime.fromtimestamp(int(os.path.getmtime(path)))

View File

@ -356,7 +356,7 @@ class Photo(object):
os.unlink(tfn)
def _video_transcode(self, transcode_path, original_path):
transcode_path = os.path.join(transcode_path, cache_base(self._path) + '.webm')
transcode_path = os.path.join(transcode_path, video_cache(self._path))
transcode_cmd = ['-i', original_path, '-c:v', 'libvpx', '-crf', '10', '-b:v', '800k', '-c:a', 'libvorbis', '-f', 'webm', '-threads', '2', '-loglevel', '0', '-y']
filters = []
info_string = "%s -> webm" % (os.path.basename(original_path))
@ -403,7 +403,7 @@ class Photo(object):
for size in Photo.thumb_sizes:
if size[1]:
caches.append(image_cache(self._path, size[0], size[1]))
caches.append(cache_base(self._path) + '.webm')
caches.append(video_cache(self._path))
else:
caches = [image_cache(self._path, size[0], size[1]) for size in Photo.thumb_sizes]
return caches