File size: 636 Bytes
21bc372
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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}")