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

Question how to access artist.songs #120

Closed ragrets closed 4 years ago

ragrets commented 4 years ago
import lyricsgenius as genius

api = genius.Genius(geniusCreds)    
artist = api.search_artist(artist_name, max_songs=2)
song_list = artist.songs
print(song_list)

songs = []
x = 0
while x < len(song_list):
    songs.append(f"{x + 1}: {(song_list)[x]}")
    x = x+1
print(songs)

Am I missing something? I initially printed song_list to see its content

[('I Miss You', '\u200b\u200bblink-182'), ('What’s My Age Again?', '\u200b\u200bblink-182')]

but I don't see where the 2nd print got the lyrics

[
    '1: "I Miss You" by \u200b\u200bblink-182:\n    [Intro: Mark Hoppus]\n    I miss you, I miss you\n    \n    
        [Verse 1: Mark Hoppus]\n    Hello there\n    The angel from my ni...', 
    '2: "What’s My Age Again?" by \u200b\u200bblink-182:\n    [Verse 1: Mark Hoppus]\n    I took her out\n    
        It was a Friday night\n    I wore cologne\n    To get the feeling right\n    ...'
    ]

Also, I get "Song object is not subscriptable" when i try to access the song names by:

x = 0
while x < len(song_list):
    songs.append(f"{x + 1}: {(song_list)[x][0]}")
    x = x+1
johnwmillr commented 4 years ago

I'm not quite sure what you're trying to accomplish. Do you want the songs variable to be a list of all of the lyrics?

In your songs.append(f"{x + 1}: {(song_list)[x][0]}") line, you are asking for the string representation of the Song class, so you're calling its __str__ method, which includes a snippet of the song's lyrics.

If you want just the song lyrics, try something like this:

x = 0
while x < len(song_list):
    songs.append(f"{x + 1}: {(song_list)[x].lyrics}")
    x = x + 1
print(songs)

Does that address your question?

johnwmillr commented 4 years ago

Closing this issue, as I believe the above code will fix the problem. Feel free to comment again or open a new issue if necessary.