📥Fetching lyrics using the API
install dependencies
[1]:
%pip install lrclibapi
from IPython.display import clear_output
clear_output()
Initialize the API
using the user_agent is recommended by the API documentation
[2]:
from lrclib import LrcLibAPI
# Create an instance of the API
api = LrcLibAPI(user_agent="my-app/0.0.1")
# Get lyrics for a track
lyrics = api.get_lyrics(
track_name="I Want to Live",
artist_name="Borislav Slavov",
album_name="Baldur's Gate 3 (Original Game Soundtrack)",
duration=233,
)
found_lyrics = lyrics.synced_lyrics or lyrics.plain_lyrics
print("\n".join(found_lyrics.split("\n")[:5]))
[00:17.12] I feel your breath upon my neck
[00:20.41] A soft caress as cold as death
[00:29.60] I didn't know you well back then
[00:32.82] I blame it all on luck and vain
[00:41.37] Your blood like wine, I wanted in
Don’t know exactly what to search for?
Use the search endpoint
[3]:
# Search for a lyrics
results = api.search_lyrics(
track_name="I Want to Live",
)
# Print the results
for result in results[:5]:
print(f"{result.artist_name} - {result.track_name} ({result.album_name})")
Exile - I Don't Want To Be A Memory (Live At Billy Bob's Texas)
Don Williams - I Wouldn't Want To Live If You Didn't Love Me (Volume Three)
Don Williams - I Wouldn't Want To Live If You Didn't Love Me (The Definitive Collection)
Ben Harper - I Want To Be Ready (The Will To Live)
Ben Harper - I Want to Be Ready (The Will to Live)
Fetch lyrics for a song using id
[4]:
lyrics = api.get_lyrics_by_id(results[0].id)
found_lyrics = lyrics.synced_lyrics or lyrics.plain_lyrics
print("\n".join(found_lyrics.split("\n")[:5]))
[00:06.98] I don't want to be a memory
[00:11.59] Just a shadow in your mind
[00:15.25] Wanna be the one you always need
[00:19.85] Not the one you left behind
[00:23.54] I don't want to be a notch in your handle