Python Video Processing: Download YouTube Videos Using pytube

In this tutorial, we will use some steps to introduce how to download youtube videos using python pytube library.

Python Video Processing: Download YouTube Videos Using pytube

1.Install pytube

As to python 3, you can install as follows:

pip install pytube3

as to python 2, you can do:

pip install pytube

Then we can start to download youtube videos.

2.Import library

import pytube

3.Create a youtube object by video url

url = 'https://www.youtube.com/watch?v=-t1_ffaFXao'
youtube = pytube.YouTube(url)

4.Get youtube video

video = youtube.streams.first()
# or the best quality:
video = youtube.streams.get_highest_resolution()

5.Start to download youtube video

video.download('videos')

6.Get youtube video infomration

video.age_restricted
video.title
video.id

Meanwhile, some videos you can not download, you can try python pafy library. Here is the tutorial:

Python Video Processing: Download YouTube Videos Using pafy