diff --git a/bot/__init__.py b/bot/__init__.py index bf3fb23..6dd51e1 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -1,6 +1,6 @@ import discord -__version__ = '1.0.7' +__version__ = '1.0.8' __author__ = 'Kartoniarz' diff --git a/bot/utils/helpers.py b/bot/utils/helpers.py index cc4eaa2..ff42043 100644 --- a/bot/utils/helpers.py +++ b/bot/utils/helpers.py @@ -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',