Closed SidmoGoesBrrr closed 3 years ago
Hi. Before answering any of the questions, please take care to properly mask your access tokens. I've removed the one in the code you posted and suggest generating a new one since that has been exposed.
As for the first question, what you were getting is the intended behavior - you specified 0 songs and the package didn't fetch any songs for you. The print statement Searching for songs by Eminem
is misleading here.
For the second question, this isn't really related to LyricsGenius and it's more of a general Python issue. You're trying to save a string that contains a Unicode character while you haven't specified any encoding and that's why you're running into an issue. Besides that, handling files like that is dangerous and you need to take proper care to close files after you're done with them. I suggest learning the Pythonic way to handle I/O. As for the answer, this will solve the issue:
with open('lyrics.txt', encoding='utf8') as f:
f.write(lyrics)
Or better yet, you can let LyricsGenius handle saving the file by using Song.save_lyrics
:
song = genius.search_song("Rap God", "Eminem")
song.save_lyrics("lyrics.txt")
Hi! Two things 1) how to use only 1 song without searching for artists songs Image:
2)How to download lyrics to .txt I am getting error, suppose file path is C:\Users\user123\Desktop\Lyrics_1.txt
Here is error:
And Code `
import lyricsgenius
Fileobject = open("Lyrics_1.txt","w")
genius = lyricsgenius.Genius('GENIUS_ACCESS_TOKEN')
artist = genius.search_artist("Eminem", max_songs=0, sort="title")
song = genius.search_song("Godzilla", artist.name)
L=song.lyrics
print(L)
Fileobject.write("hello \n")`