Download YouTube videos By Python in 5 lines !!!

Howdy, today we’ll create a program by python in 5 line can download YouTube videos, so let’s get started.

Pre-requisites

you'll need :

Let’s Begin

We’ll create two files, video.py & audio.py

video.py

This file will download your video with pictures & audio

audio.py

And This’ll download the video only with audio.

Open your favorite editor, and type

We’re going to install two packages

pafy & youtube.dl

so in terminal

Little remains, in video.py we'll import pafy

new is a function download your video by add the URL on it, so create url variable and it's well be input

now create video variable and it's value is new function

the video has different quality, we want the best quality, define new variable

you can test it

now, go to audio.py, it's like video.py but has some differences

let’s define audio variable

that’s it, you can now go to YouTube and download your favorite video/s.

good bye.

source code