Download Youtube Video Using Python
Youtube videos can be easily downloaded using Python. We use a library named Pytube to download video.
from pytube import Youtube
Now we will define the save path and url to download video from youtube.
#where to save
SAVE_PATH = "H:/Youtube Downloads/" #to_do
#link of the video to be downloaded
link='https://www.youtube.com/watch?v=-9UjK-mWm7s'
Now we will download video using YouTube
#object creation using YouTube which was imported in the beginning
yt = YouTube(link)
#filters out all the files with "mp4" extension
yt = yt.streams.first()
try:
#downloading the video
yt.download(SAVE_PATH)
except:
print("error")
# On complete print success Message
print("Task Completed")
So whole code will look like this
from pytube import Youtube
#where to save
SAVE_PATH = "H:/Youtube Downloads/" #to_do
#link of the video to be downloaded
link='https://www.youtube.com/watch?v=-9UjK-mWm7s'
#object creation using YouTube which was imported in the beginning
yt = YouTube(link)
#filters out all the files with "mp4" extension
yt = yt.streams.first()
try:
#downloading the video
yt.download(SAVE_PATH)
except:
print("error")
# On complete print success Message
print("Task Completed")
No comments