Python Power(Youtube Downloader)

Hey Guys! I’m Himanshu Awasthi & today I’m going to share how to download video’s from YouTube using small Python Script. As we all know that Python is most powerful language and we can do any thing using Python so lets start :

import All from todays_Blog

We need to download two Python Module for start write code for youtube downloader :

  1.  youtube-dl (Download Here)
  2.  pafy (Download Here)
  3.  pytube (Download Here)

We can use any one of these module for our code but I’m going to use pytube .

Why we need these modules ?

youtubedl is a command-line program to download videos from YouTube.com and a few more sites. learn more about it from Here

Pafy is very comprehensive python module, allowing download in both video and audio format. There are other features of Pafy which is not used in this module.

Pytube is a python package written for the main purpose of downloading videos from the famous video website Youtube.

lets move towards code :
import pytube
print("Enter the video link")
link = input()
yt = pytube.YouTube(link)
videos = yt.get_videos()
s = 1
for v in videos:
print(str(s)+". "+str(v))
s += 1
print("Enter the number of the video: ")
n = int(input())
vid = videos[n-1]
print("Enter the destination: ")
destination = input()
vid.download(destination)
print(yt.filename+"\nHas been successfully downloaded")

Output:

/usr/bin/python3.5 /home/him/PycharmProjects/online_Downloader/youtube_download.py
Enter the video link
https://www.youtube.com/watch?v=uSosZCcLr_U
1. <Video: MPEG-4 Visual (.3gp) – 144p – Simple>
2. <Video: MPEG-4 Visual (.3gp) – 240p – Simple>
3. <Video: H.264 (.mp4) – 360p – Baseline>
4. <Video: H.264 (.mp4) – 720p – High>
5. <Video: VP8 (.webm) – 360p – N/A>
Enter the number of the video:
3
Enter the destination:
/home/him/PycharmProjects/online_Downloader
Make Youtube Video Downloader with Python in 5 minutes
Has been successfully downloaded

Process finished with exit code 0

So enjoy your downloading using this script & Don’t forget to be the part of these upcoming great Python events in India .

Upcoming Python Events :

PyConf Hyderabad 2017

Pycon India 2017

Happy Coding!

Leave a comment