Files
mateusz/bot/utils/helpers.py
T
2026-04-22 01:00:59 +02:00

21 lines
550 B
Python

import os
import yt_dlp
def download_video(yt_url: str) -> str:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
DOWNLOADS = os.path.join(BASE_DIR, "downloads")
ydl_opts = {
'format': 'bestvideo+bestaudio/best',
'merge_output_format': 'mp4',
'outtmpl': f'{DOWNLOADS}/%(title)s.%(ext)s',
}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
os.makedirs(DOWNLOADS, exist_ok=True)
info = ydl.extract_info(yt_url, download=True)
filename = ydl.prepare_filename(info)
return filename