Send cached V1.0.8

This commit is contained in:
Patryk Mazur
2026-04-22 20:38:03 +02:00
parent 2af618fde2
commit 8b06567b8b
2 changed files with 12 additions and 3 deletions
+11 -2
View File
@@ -26,12 +26,22 @@ def rotate_downloads(downloads_dir: str):
def download_video(yt_url: str) -> dict:
MAX_DUR = os.getenv('MAX_DURATION')
if not MAX_DUR.isnumeric():
return {'status': 'error', 'message': f'MAX_DUR: \"{MAX_DUR}\" - nie jest cyfrą.'}
return {'status': 'error', 'message': f'MAX_DUR: "{MAX_DUR}" - nie jest cyfrą.'}
MAX_DUR = int(MAX_DUR)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DOWNLOADS = os.path.join(BASE_DIR, 'downloads')
os.makedirs(DOWNLOADS, exist_ok=True)
url_hash = hashlib.sha1(yt_url.encode()).hexdigest()[:10]
existing = [f for f in os.listdir(DOWNLOADS) if url_hash in f]
if existing:
print(f'Znaleziono plik "{url_hash}" ({yt_url})')
return {
"status": "success",
"filename": os.path.join(DOWNLOADS, existing[0]),
"cached": True,
}
with yt_dlp.YoutubeDL({'quiet': True}) as ydl:
try:
@@ -50,7 +60,6 @@ def download_video(yt_url: str) -> dict:
}
rotate_downloads(DOWNLOADS)
url_hash = hashlib.sha1(yt_url.encode()).hexdigest()[:10]
ydl_opts = {
'format': 'bestvideo+bestaudio/best',