GUI to extract Lyrics from a song Using Tkinter in PythonIn this tutorial, we will create a Python program to extract a song's lyrics and connect them to the GUI application. By just entering the song's name, lyrics-extractor will extract the song's title and lyrics from a variety of websites and return them to us. It is a project for novices in which we will get knowledge on how to extract data from JSON web APIs and use these ideas in a practical project. About the application :The words of a song are extracted using a lyric extractor. In our project, the user will input the music title, and our application will then use requests and JSON libraries to extract the song's lyrics from a certain set of links. All of this will be made possible by building a GUI to perform this operation. We will need to install the lyrics-extractor module before continuing with the program. And we will be using our terminal to execute this command. Requirements :We will be needing a Google Custom Search JSON API Engine ID and an API key. Engine ID :
To acquire your search engine, select any of the following links : The JSON API :
Approach :
Code for this approach :Output : Note : While entering the API key and the Engine ID in the code we must enter our own key and ID to avoid error generation.Extracting Lyrics GUI using Tkinter :The project is quite easy to work on and makes use of the modules like requests, tkinter and google API client. To establish a connection and retrieve the necessary search result, we utilise the Google API Client, and we use Tkinter to build the GUI. To extract the lyrics from the obtained result, requests are employed. This is a built-in library called Requests. We will also require an Engine ID and API Key when building the project. When extracting the lyrics, the SongLyrics() function will use them. With the help of the websites provided below, we may generate our own API key and Engine ID. The link mentioned earlier can be used to get your unique API key and this link can be used to get your unique Engine ID - https://cse.google.com/cse/create/new For security purposes, it is advisable to generate a fresh API key and Engine ID. We must include the name of the website we will be utilising to extract the lyrics when generating the Engine ID. To get better results, enter many website urls like we have mentioned earlier. Walking through the code :Firstly, we imported the modules that are required in our program like Tkinter and lyrics_extractor class from SongLyrics into our code. Then, we defines a function getting_lyrics() to extract the song's lyrics along with entering the API key and the Engine ID using the songLyrics() method. Then, we created a new variable called var for extracting the lyrics and holding them temporarily and finally stored the result in final variable permanently. Next, we set the main code and defined the GUI window as base as an instance of Tkinter library and set the background colour of the window to light grey, using the configure() method. Then, we created a new variable called result to store the outcome. Then, we created a few labels using the Label widgets for entering song name and displaying resulting lyrics. To create it precisely, we mentioned the parameters base, text and bg, Moreover, to position them, we used the grid() method with parameters row and sticky. Then, we added another label using Label widget and a few entry boxes using the Entry widget to enter and display text and positioned them using the grid() method along with the parameters like row, column and sticky. And lastly, we created a Show button using the Button widget for showing the extracted lyrics of the song. We used the grid() method to position it on the GUI window with the help of various parameters like row, column, columnspan, rowspan, padx and pady. Complete Code : Output : The output of the GUI to extract lyrics from a song is attached below in the form of a screenshot. Conclusion :As a result, we started from scratch with a basic Python Extract Song Lyrics Project. The project serves as a fantastic introduction to web scraping, tkinter GUI design, and utilising a Google API client to build a customized search engine. |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India