johnwmillr / LyricsGenius

Download song lyrics and metadata from Genius.com 🎶🎤
http://www.johnwmillr.com/scraping-genius-lyrics/
MIT License
898 stars 159 forks source link

wrong output for .lyrics #106

Closed mrpandastic closed 4 years ago

mrpandastic commented 5 years ago

Hi John,

I tried the code you gave Chris regarding song-artist pairs and it doesn't seem to return the correct result:

import lyricsgenius

genius = lyricsgenius.Genius("--mykey--")

SongPairs = [['Rocket Man', 'Elton John'],['Till I collapse','Eminem'],['Californication','Red Hot Chili Peppers']]

 for pair in SongPairs:
 song = genius.search_song(pair[0], pair[1])
 lyrics = song.lyrics
 print(lyrics)

2nd and 3rd pair returns the correct lyrics but I don't understand why the first pair is getting "The One - Prodigy & The Alchemist" instead of "Rocket Man" by Elton John? If I search for a different song like "El Perdón" by Nicky Jam it results not even into a song lyrics but something completely different.

Do you know how I can avoid this bug? Or some kind of workaround that I can use?

I'm currently using the latest version lyricsgenius 1.6.0

Oh and another question: I have a list of songs with a Spotify ID. Do you think it's possible to directly link these id's to Genius' song id's? Or do I have to run my loop with search_song(title, artist)? Like this:

for i in first20.index:
    track = df.iloc[i]['Track Name']
    artist = df.iloc[i]['Artist']

    song = genius.search_song(track,artist)
    genius.remove_section_headers = True

    try:
        df.loc[i, "SongText"] = song.lyrics
    except: 
        df.loc[i, "SongText"] = ''

Thank you again for your great help! Really appreciate it! :)

johnwmillr commented 5 years ago

This is definitely a bug. I don't have an easy workaround at the moment. Essentially you're ending up with the first result you'd get when searching Genius.com, because you don't have the option to browse through multiple options like you do on the website.

There isn't a way to link the Spotify and Genius IDs, you'll have to search by name like you're doing.

allerter commented 4 years ago

The two songs you mentioned that weren't returning the right lyrics are found without any issues when I search for them. As for linking the linking Spotify and Genius IDs, there is no direct way to search by Spotify ID, but you could link the two by accessing the media key in the song information like this:

song = genius.search_song('Chandelier', artist='Sia')
for m in song.media:
    if m['provider'] == 'spotify':
        uri = m['native_uri']  # we could also use m['url']
        spotify_id = uri[uri.rfind(':') + 1:]
        break
else:
    spotify_id = None
    print('No Spotify ID found.')