Download YouTube videos By Python in 5 lines !!!

abdfnx

abdfn

Posted on December 12, 2020

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

$ touch video.py audio.py
Enter fullscreen mode Exit fullscreen mode

We're going to install two packages

pafy & youtube.dl

so in terminal

$ pip install pafy youtube.dl
Enter fullscreen mode Exit fullscreen mode

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

from pafy import new
Enter fullscreen mode Exit fullscreen mode

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

url = input("Enter the url: ")
Enter fullscreen mode Exit fullscreen mode

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

video = new(url)
Enter fullscreen mode Exit fullscreen mode

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

dl = video.getbest()
dl.download()
Enter fullscreen mode Exit fullscreen mode

you can test it

$ py video.py
Enter fullscreen mode Exit fullscreen mode

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

from pafy import new
url = input("Enter the link: ")
video = new(url)
Enter fullscreen mode Exit fullscreen mode

let's define audio variable

audio = video.audiostreams
audio[0].download()
Enter fullscreen mode Exit fullscreen mode

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

good bye.

GitHub logo abdfnx-cemetery / klihub

KliHub is program you can by it download youtube vidoes

💖 💪 🙅 🚩
abdfnx
abdfn

Posted on December 12, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Learning Python
javascript Learning Python

November 28, 2024

Calculate savings with Python!
beginners Calculate savings with Python!

November 26, 2024

UV the game-changer package manager
programming UV the game-changer package manager

November 24, 2024

Beginners Guide for Classes
python Beginners Guide for Classes

November 20, 2024