Files
downloads-all-bot/bot/cache.py
2026-02-18 18:58:25 +07:00

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}")