Closed ManuelBanza closed 3 years ago
I think genius.search_lyrics
is what you're looking for.
For example:
from lyricsgenius import Genius
access_token = 'MY_ACCESS_TOKEN'
genius = Genius(access_token)
search = genius.search_lyrics("test")
for hit in search['sections'][0]['hits']:
song = hit['result']
highlight = hit['highlights'][0]
lyrics = highlight['value']
artist = song['primary_artist']['name']
title = song['title']
song_id = song['id']
occurrences = len(highlight['ranges'])
print(f"Song: {artist} - {title} | Song ID: {song_id}")
print(f"highlighted Lyrics: {lyrics}")
print(f"Occurrence: {occurrences} times")
print("-" * 40)
yes this is exactly what I wanted @Allerter !
Can you also suggest a way to go through all the pages so I can get all the songs that have this specific word? I see that there is a field called next_page
Thanks
The snippet to get an artist's least popular song uses a while
loop to go through all the songs of an artist using the per_page
parameter. It'll be the same for traversing the pages of search_lyrics
as well.
@johnwmillr this issue is a good candidate if the Discussions tab were added.
Hi,
Is it possible to get all songs that have a specific word in their lyrics?
Ideally getting song name and artist.
Cheers