Skip to content

Search all songs containing keyword #180

Answered by allerter
ManuelBanza asked this question in Q&A
Discussion options

You must be logged in to vote

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)

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by allerter
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #174 on February 10, 2021 02:24.