I am working on getting the songs lyrics from genius using API. I am having an issue with extract titles and lyrics from JSON file once it is saved. please see my code below.
import lyricsgenius as genius
api=genius.Genius('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
artist=api.search_artist('Beyonce') #max_songs=3, sort="title"
aux=artist.save_lyrics(filename='artist.txt',overwrite=True,skip_duplicates=True,verbose=True)
titles=[song['title'] for song in aux['songs']]
lyrics=[song['lyrics'] for song in aux['songs']]
The error I am having is:
TypeError Traceback (most recent call last)
<ipython-input-21-4a24319b20b5> in <module>
----> 1 titles=[song['title'] for song in aux['songs']]
2 lyrics=[song['lyrics'] for song in aux['songs']]
TypeError: 'NoneType' object is not subscriptable
Your help will be much appreciated. Thank you in advance!
Regards,
viku
The query output is saved to a
json
(ortxt
) file, i.e.:But you can also use:
References: