DEV Community

Cover image for Turn your Python skills into a lyrical maestro with a sleek GUI that fetches song lyrics at the click of a button
Sona
Sona

Posted on

Turn your Python skills into a lyrical maestro with a sleek GUI that fetches song lyrics at the click of a button

In this article, we’ll create a Python script to extract song lyrics and integrate it with a GUI application. We’ll use the lyrics-extractor library, which retrieves lyrics by searching various websites based on the song’s name. To begin, you’ll need to install the lyrics-extractor module. You can do this by running the following command in your terminal:

pip install lyrics-extractor

API Key and Engine ID: You need these from Google Custom Search JSON API.
Engine ID: Create a Custom Search Engine (CSE) to obtain your Engine ID here.
Set up your Programmable Search Engine (Google Custom Search Engine) and include links to fetch lyrics. Programmable Search Engine leverages Google’s search technology to locate information based on user queries.You can choose any of the following links to configure your search engine:
Genius
Lyricsted
Lyricsbell
Glamsham
Lyricsoff
Lyricsmint
JSON API: The Custom Search JSON API retrieves and displays results from your Programmable Search Engine. To use this API, you’ll need to create a Programmable Search Engine and obtain an API key (https://developers.google.com/custom-search/v1/overview#api_key).

Approach:
Import the necessary modules:

from lyrics_extractor import SongLyrics

Initialize the SongLyrics class with your Google Custom Search JSON API key and Engine ID:

extract_lyrics = SongLyrics(Your_API_KEY, GCS_ENGINE_ID)

Retrieve the lyrics by passing the song name to the get_lyrics() method:

lyrics = extract_lyrics.get_lyrics("Shape of You")

Get the API KEY and GCS_ENGINE_ID from here

Full Code:

`# importing modules
from lyrics_extractor import SongLyrics

pass the GCS_API_KEY, GCS_ENGINE_ID

extract_lyrics = SongLyrics("GCS_API_KEY","GCS_ENGINE_ID")

extract_lyrics.get_lyrics("Tujhse Naraj Nahi Zindagi Lyrics")`

Read More Below

https://codemagnet.in/2024/09/13/gui-to-extract-lyrics-from-song-using-python/

Top comments (0)