X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/6f51733275b7a709d519adf2505dd0dc1b886466..778bdfb196e004691368624d3f5af04b4cdad640:/src/youtube/utils.py diff --git a/src/youtube/utils.py b/src/youtube/utils.py index 3b64018..d219dde 100644 --- a/src/youtube/utils.py +++ b/src/youtube/utils.py @@ -1,3 +1,4 @@ +import hashlib import os import shutil import subprocess @@ -31,7 +32,16 @@ def process_to_file(cmdline, prefix='', suffix='', cache_key=None, output_path=N output_path = tmp.name if cache_key: - cache_path = FILE_CACHE + cache_key.replace('/', '__') + cache_path = cache_key.replace('/', '__') + if len(cache_path) > 255: + parts = cache_path.rsplit('.', 1) + limit = 255 - 9 + if len(parts) > 1: + limit -= len(parts[1]) + 1 + cache_path = parts[0][:limit] + '.' + hashlib.sha1(cache_key.encode('utf-8')).hexdigest()[:8] + if len(parts) > 1: + cache_path += '.' + parts[1] + cache_path = FILE_CACHE + cache_path if cache_key and os.path.exists(cache_path): link_or_copy(cache_path, output_path)