pip install youtube-dl
python
import youtube_dl
def download_video(url):
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
video_url = "https://www.youtube.com/watch?v=your_video_id"
download_video(video_url)
python
import youtube_dl
def download_video(url):
ydl_opts = {
'format': 'best',
'outtmpl': './downloads/%(title)s.%(ext)s',
'postprocessors': [{
'key': 'FFmpegVideoConvertor',
'preferedformat': 'mp4'
}]
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
video_url = "https://www.youtube.com/watch?v=your_video_id"
download_video(video_url)
python
import youtube_dl
def get_video_info(url):
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
info_dict = ydl.extract_info(url, download=False)
return info_dict
video_url = "https://www.youtube.com/watch?v=your_video_id"
video_info = get_video_info(video_url)
print(video_info)