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

Assigning artists or lyrics to a variable #146

Closed Aschinea closed 4 years ago

Aschinea commented 4 years ago

Hello, I would like to add the songs that appear after using artist = genius.search_artist(arg, max_songs=3, sort="title") to variables, to make them more easy to manipulate and send seperately. Is there a way to do it? If yes, how? If not, it would be a really good idea to add it.

Also, when getting artist.songs, the string sent has the [, ( and ' characters on it, how can I remove them?

allerter commented 4 years ago

Since artist.songs is a list of Song objects, you can access the artist's songs by iterating over the list. I don't know if adding each song as an attribute to the Artist object would be a good idea or even useful since you can easily iterate over the list and do whatever you want. As for the second question, the [, ( and ' are there because you're printing a list object. There are a few ways to print a list without brackets in a single row:

# using join and list comprehension
print(', '.join([song.title for song in artist.songs]))
# using * and list comprehension
print(*[song.title for song in artist.songs], sep=', ')
johnwmillr commented 4 years ago

Thank you, @Allerter!