Automate Youtube with Python
In this article, we are going to see how to automate Youtube using Python.
- Selenium: It controlling a web browser through the program
- pyttsx3: It is a text-to-speech conversion library in Python
- speech_recognition: Speech Recognition is an important feature in several applications used such as home automation, artificial intelligence, etc
- pyaudio: It is used to play and record audio on a variety of platforms
Make sure that you have noted the location where the chromedriver has been downloaded (as it is used in our python script). Now After downloading extract the zip file and please note the file location of the extracted file as we have needed it later in python code. (You can find the location by clicking on properties and then details).
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course
- Import the library which we have installed.
- Then we have to take the input search query using the speech_recognition library. we can do this by making an instance of speech_recognition library as sr.Recognizer() .
- After this adjusting the threshold frequency and convert the voice input into a string.
- Then, the main part comes into the picture, we have created a function automateYoutube() which plays the required video from Youtube.
- In this function create we driver instance using function webdriver.Chrome() which takes the path of chromedriver as the parameter.
- Finally, find the name or id or class or CSS selector of the search bar and search button by right-clicking inspect search bar and .search button.
- Now, just call the automateYoutube() function to see the output.
- Now we have to automate play/pause buttons for that we again find the CSS selector of play/pause button using selenium.
Below is the Full Implementation