V1.0 working version
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
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
|
||||
Reference in New Issue
Block a user