import yt_dlp | |
def download_video_with_caption(url: str, download_path: str = "./downloads/"): | |
ydl_opts = { | |
"outtmpl": f"{download_path}%(title)s.%(ext)s", | |
"quiet": True, | |
"noplaylist": True, | |
"format": "best", | |
} | |
with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
info = ydl.extract_info(url, download=True) | |
video_title = info.get("title", "Video") | |
video_path = ydl.prepare_filename(info) | |
return video_path, video_title | |
url = "https://vt.tiktok.com/ZSrV6uQme/" | |
video_path, caption = download_video_with_caption(url) | |
print(f"Downloaded to: {video_path}\nCaption: {caption}") | |