Python YouTube Downloader

Sameera Abeysekara
1 min readJan 2, 2021

--

Downloading Videos from YouTube is a bit of a hectic task because of some application/website popup Ads or ask for registration or even we need to pay some amount to download. So for that using python, I have build a small application where users can download any public YouTube videos without any ads or registration or payments.Let’s go to the source code and see how i create it

First we need to install pytube

python -m pip install git+https://github.com/nficano/pytube

Source Code

from pytube.cli import on_progress
from pytube import YouTube
from pytube import Playlist
loopstatus = True
while loopstatus:
download_type = input("Download Type Single Or Playlist : ")
video_url = input("Please Enter YouTube URL : ")
Format=input('Audio Or Video :')
try:
if download_type == 'Playlist':
p = Playlist(video_url)
for url in p.video_urls:
video = YouTube(url,on_progress_callback=on_progress)
if Format=='Audio':
Filter = video.streams.filter(only_audio=True).first()
if Format=='Video':
Filter = video.streams.filter(file_extension='mp4').get_highest_resolution()
print('Now downloading:',Filter.title)
sizer=round(Filter.filesize/1000000)
print('Size:',sizer,'MB')
Filter.download()
if download_type == 'Single':
yt = YouTube(video_url,on_progress_callback=on_progress)
if Format=='Audio':
Filter = yt.streams.filter(only_audio=True).first()
if Format=='Video':
Filter = yt.streams.filter(file_extension='mp4').get_highest_resolution()

print('Now downloading:',Filter.title)
sizer=round(Filter.filesize/1000000)
print('Size:',sizer,'MB')
Filter.download()
except EOFError as err:
print(err)
else:
print("Download Complete")
next_video = input("Convert another URL (Y / N): ")
if next_video == 'N':
loopstatus = False

To Run python file open CMD and type :

python filename.py

--

--

No responses yet