diff --git a/youtube/__init__.py b/youtube/__init__.py deleted file mode 100644 index 51b4c82..0000000 --- a/youtube/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .youtube import download diff --git a/youtube/youtube.py b/youtube/youtube.py deleted file mode 100644 index b37f159..0000000 --- a/youtube/youtube.py +++ /dev/null @@ -1,35 +0,0 @@ -from os import path - -from youtube_dl import YoutubeDL - -from config import DURATION_LIMIT -from helpers.errors import DurationLimitError - -ydl_opts = { - "format": "bestaudio/best", - "verbose": True, - "addmetadata": True, - "geo-bypass": True, - "nocheckcertificate": True, - "outtmpl": "downloads/%(id)s.%(ext)s", -} - -ydl = YoutubeDL(ydl_opts) - - -def download(url: str) -> str: - global ydl - info = ydl.extract_info(url, False) - duration = round(info["duration"] / 60) - - if duration > DURATION_LIMIT: - raise DurationLimitError( - f"🛑 Videos longer than {DURATION_LIMIT} minute(s) aren't allowed, the provided video is {duration} minute(s)" - ) - try: - ydl.download([url]) - except: - raise DurationLimitError( - f"🛑 Videos longer than {DURATION_LIMIT} minute(s) aren't allowed, the provided video is {duration} minute(s)" - ) - return path.join("downloads", f"{info['id']}.{info['ext']}")