13 lines
431 B
Python
13 lines
431 B
Python
# cache.py
|
|
import hashlib
|
|
import os
|
|
|
|
def cache_key(url: str, quality: str, audio: bool = False) -> str:
|
|
key_str = f"{url}_{quality}_{audio}"
|
|
return hashlib.sha256(key_str.encode()).hexdigest()
|
|
|
|
def cache_path(cache_dir: str, key: str, extension: str) -> str:
|
|
subdir = key[:2]
|
|
full_dir = os.path.join(cache_dir, subdir)
|
|
os.makedirs(full_dir, exist_ok=True)
|
|
return os.path.join(full_dir, f"{key}.{extension}") |