Send cached V1.0.8
This commit is contained in:
+11
-2
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user