YouTube Video Downloader in Python

YouTube is a very big platform for watching and uploading the video. I know sometimes you use YouTube Video downloader websites to download any video. But today we build our own YouTube video downloader in python.

For this, we use “pytube” python module. pytube is a lightweight, dependency-free Python library which is used for downloading videos from the web.

pytube is not the native library. You need to install it before using it. Installation is easy when you have pip. In the Terminal or Command Prompt, type the following command to install pytube.

Installation

pip install pytube

Let’s code.

Code

Make sure you are connected to the internet to download the videos. Otherwise it will raise an error.

Downloading a single video

# to dowload single video from youtube

from pytube import YouTube

link = input("Enter the link: ")
yt = YouTube(link)
# ---------------------------------path to save, by default current path-------------------
yt.streams.first().download("/media/arpit/STUDY/python pro/youtube-downloader")

Downloading multiple videos

# to download multiple videos

from pytube import YouTube

# link of the video to be downloaded
links = [
    "https://youtu.be/ACxQ6djzAJI",
    "https://www.youtube.com/watch?v=Wch3gJG2GJ4&ab_channel=BRIGHTSIDE",
]

for link in links:
    yt = YouTube(link)
    yt.streams.first().download("/media/arpit/STUDY/python pro/youtube-downloader")

Now you can download youtube videos using python. Hope you like the code. Now make your own YouTube downloader in python. It’s very easy.

more about pytube: https://pypi.org/project/pytube/

Share with your friends. thank you :)

You may also like,