DEV Community

Cover image for Download YouTube videos using Python
Manitej ⚡
Manitej ⚡

Posted on • Originally published at manitej.hashnode.dev

Download YouTube videos using Python

Hey guys, in this short post lets see how we can download youtube videos using Python.

To make this possible, we use a package called pytube

What is pytube?

Their official docs says,

pytube is a very serious, lightweight, dependency-free Python library (and command-line utility) for downloading YouTube Videos.

Installing pytube

Run the below command to install the pytube package.

pip install pytube
Enter fullscreen mode Exit fullscreen mode

Now, pytube is successfully installed on your system.

To download a video, simply copy the URL of that video and run the below code

from pytube import YouTube
url = "http://youtube.com/watch?v=9bZkp7q19f0"
YouTube(url).streams.first().download()
Enter fullscreen mode Exit fullscreen mode

Thats it folks :)

To learn more about pytube visit their docs

Top comments (2)

Collapse
 
hectorpascual profile image
Héctor Pascual

wow.. how easy!

Collapse
 
manitej profile image
Manitej ⚡

Python 🔥