Download Video from Youtube with 2 lines of code

Posted by Afsal on 06-Jan-2023

Hello Pythonistas!

Today we will learn how to download a video from a link with 2 lines of Python code. We are using a package called pytube for this. Let's jump into the code.

Installation

pip install pytube

Code

from pytube import YouTube

YouTube("https://www.youtube.com/watch?v=fyMj73zcn3Y&t=1s").streams.filter(progressive=True, file_extension='mp4').first().download()

Output

Once this is run completely the mp4 file with the name same as the youtube title will be created in the same folder as the script.

I hope you have learned from this post. Please share your valuable suggestions with afsal@parseltongue.co.in