Download YouTube Video using Python

 


from pytube import YouTube

# Replace 'video_url' with the URL of the YouTube video you want to download
video_url = 'https://youtu.be/X3AnBaNa1Tw?si=DzVE_VHj9_H-CxsA'

# Create a YouTube object
yt = YouTube(video_url)

# Filter streams to get the one with the desired resolution (e.g., 1080p)
# video_stream = yt.streams.filter(res='1080p', file_extension='mp4').first()
video_stream = yt.streams.filter(progressive=True, file_extension='mp4').order_by('resolution').desc().first()

# Download the video to the current directory
#video_stream.download()
# Download the video to the specific directory
video_stream.download(output_path='G:\Test')

print(f"Downloaded: {yt.title}")

Comments