How to play and download YouTube videos through python
Now a days everyone spent very much time on social media, But the YouTube is the only one platform where every smartphone user or laptop/desktop user go once in a day search something and watch it.
If he/she thought that that is good video then he/she want to download it. But if we download in YouTube download section then after a long time it need a refreshment and due to this it takes the data and for normal user that is not good.
For the mobile user it is very easy to download a video downloader and download the video from anywhere, but for the laptop/desktop user it is very difficult, and if you are a programmer then that is your work to do the programming for make the works easy and short.
So, for the laptop/desktop user this program is very useful if they love programming😊.
YouTube Video Downloader

This program is very helpful to automate the downloading section of the YouTube, this is use to watch video, to download it using Python Programming.
This program is run through the voice command.
According to the popularity everyone knows Iron Man movie, or watch this movie, in this Movie there is a virtual assistant that’s do everything for his master according to his voice command.
Same like this, I try to make this program, this program does the task according to the voice command.
The name of the program is Edith.
Code of the Program
from pytube import YouTube
from time import sleep
import pywhatkit as kit
import pyttsx3
import speech_recognition as sr
from pyautogui import click
def speak(audio):
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty("rate", 170)
engine.say(audio)
engine.runAndWait()
def listening():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening....")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing....")
query = r.recognize_google(audio, language='en-in')
print(f"Sir say:{query}\n")
except Exception as e:
speak("sorry sir i can not recognize")
speak("Say that again please....")
return "None"
query = query.lower()
return query
speak("Hello sir, I am EDITH, I am here to assist you, You want to watch the video or download the video")
vid = listening().lower()
if "watch" in vid:
speak("What you want to watch")
topic = listening().lower()
kit.playonyt(topic)
elif "download" in vid:
speak("What is the name of the video")
name = listening().lower()
a = kit.playonyt(name)
sleep(2)
click(x=1049, y=525)
sleep(3)
speak("Can i download this video")
down = listening().lower()
if "yes" in down:
speak("Ok, I am On it")
link = a
video = YouTube(link)
stream = video.streams.get_highest_resolution()
stream.download()
speak("Download completed")
print("Download done")
elif "no" in down:
speak("Ok")
quit()
else:
speak("Try again")
Modules

pyttsx3: This module is use for text to speech, this is use to speak the text that is written by us in program.
pytube: This module is use to use the features of YouTube.
pyautogui: This module is use for the automation.
pywhatkit: This module is use to enable the play mode in YouTube.
time: this module is use for set the sleep in the program.
speech_recognition: This module is use to recognize the command of user.
Functions

def(speak): This is defined function; this is use for the speak of text messages in program.
def(listening): This is also defined function that is use for listening the command that is given by the user.
print(): This function is use to print the statement that is present in it.
Output of the program

Try this program in your laptop or desktop by using any ide, I recommend PyCharm.
Click here to download it: https://www.jetbrains.com/pycharm/download/#section=windows\
Note: Choose community if you want it for free, if you want paid then choose professional
You must be logged in to post a comment.