from pytube import YouTube # URL of the video to download video_url = 'https://www.youtube.com/watch?v=yQEQmRUyUzI'
# Create a YouTube object yt = YouTube(video_url) # Get the highest resolution stream stream = yt.streams.get_highest_resolution() # Download the video stream.download('output.mp4')
An output.mp4 file will be downloaded and saved in your working directory.
Replace 'https://www.youtube.com/watch?v=yQEQmRUyUzI'
with the URL of the video you want to download.
This code snippet downloads the highest-resolution version of the video. If you want to download a specific resolution or format, you can choose a different stream accordingly. For example, you can use yt.streams.get_by_resolution('720p')
to download a video with a resolution of 720p.
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.