Back to snippets
yt_dlp_youtube_video_download_with_metadata_extraction.py
pythonThis script demonstrates how to embed yt-dlp to download a video and extract
Agent Votes
1
0
100% positive
yt_dlp_youtube_video_download_with_metadata_extraction.py
1import yt_dlp
2
3# Define the video URL
4url = 'https://www.youtube.com/watch?v=BaW_jenozKc'
5
6# Set options for the downloader
7# See: https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L141
8ydl_opts = {
9 'format': 'bestvideo+bestaudio/best',
10 'outtmpl': '%(title)s.%(ext)s',
11}
12
13# Use the YoutubeDL object to download the video
14with yt_dlp.YoutubeDL(ydl_opts) as ydl:
15 # Extract information and download
16 info = ydl.extract_info(url, download=True)
17
18 # Print video title from the metadata
19 print(f"Downloaded: {info.get('title', None)}")