Python – Downloading YouTube videos

In todays write we’ll be creating a short and simple script that will download YouTube videos using a Python script. We will be using pytube which is a lightweight, Pythonic, dependency-free, library for downloading YouTube Videos. The library is very easy to use and quite intuitive.

We start by taking input which will be the URL of the YouTube video we are interested in, using this URL we then create a YouTube object. Next, we select the stream we are wanting (more information on this can be found here) before downloading the video itself.

from pytube import YouTube

while 1 == 1:
    URL = input("Please enter YouTube URL: ")
    yt = YouTube(URL)
    stream = yt.streams.get_by_itag(22)

Leave a Reply