YouTube Video Downloader(Python)

Hasitha Chandula
Analytics Vidhya
Published in
2 min readJan 18, 2020


In this tutorial, I’m going to show you build your own Youtube video downloader using python (cmd app). And this is a very fun project.

To start with this project first you need to install python3 in your computer and also a text editor or IDE ( vs code, pycharm ). To build this app we use pytube library. you can check this library here. To install this library open your cmd and type and press pip install pytube. And also we are using virtualenv here so we need to install that too. pip inatall virtualenv

Now Environment setup is done. Now coding part. As an IDE I’m using vs code. Now go to your project folder and open cmd and type virtualenv venv. It will create a virtual environment to build our application. And we need to activate our virtual env. if your computer Linux or mac you can activate by typing source ./venv/bin/activate and if you are a windows user you can activate source ./venv/scripts/activate and press Enter.

Now open your project using vs code and create file. And code look like this.

from pytube import YouTube# Youtube video link you need to download
yt = YouTube("")
# Display all formats this video available

To run the file in cmd type and Press Enter python If you are seeing something like bellow you are good.


But sometimes it gives errors. In that error, there is a line copy that path and open that file. we need to modify that file. Delete all code lines in that file and paste bellow lines of codes and save.

Code is here.

And run again now all errors are gone.

As a result, you can see the itag in every Stream. It means the quality of the video. using this itag we can download videos.

from pytube import YouTubeyt = YouTube("") 
# Youtube video link you need to download
# Display all formats this video availableprint(yt.streams.all())# Download Video

Now run the file again. now you can see video file in your project directly.

Now you can modify this as you want. As an example, if we want to download more than one file we can use a list and for loop, code looks like this.

from pytube import YouTube# List of video links
video_list = ["","",""]
for link in video_list:
yt = YouTube(link)

That's it. I hope you enjoy this small project.

Thank you and Enjoy Python.



Hasitha Chandula
Analytics Vidhya

Senior Full Stack Engineer specializing in TypeScript & Go. I create scalable web apps, love learning new tech, and thrive on teamwork.