Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artist.save_lyrics failing #71

Closed
TwistedAsylumMC opened this issue Dec 3, 2018 · 6 comments · Fixed by #75
Closed

Artist.save_lyrics failing #71

TwistedAsylumMC opened this issue Dec 3, 2018 · 6 comments · Fixed by #75
Assignees
Labels

Comments

@TwistedAsylumMC
Copy link

Describe the bug
Using the code artist.save_lyrics() I am given an error when running the script

Expected behavior
I expected the lyrics of a chosen song to be saved to a file

To Reproduce
Describe the steps required to reproduce the behavior.
Use the following code:

import lyricsgenius as genius

api = genius.Genius("MY TOKEN") # Replaced my api token with "MY TOKEN"
artist = api.search_artist("Ariana Grande", max_songs=1)
song = api.search_song("thank u, next", artist.name)
artist.add_song(song)
artist.save_lyrics()

Include the error message associated with the bug.

Traceback (most recent call last):
  File "C:\Users\sebfa\PycharmProjects\TTS\main.py", line 8, in <module>
    artist.save_lyrics()
  File "C:\Users\sebfa\PycharmProjects\TTS\venv\lib\site-packages\lyricsgenius\artist.py", line 109, in save
_lyrics
    filename = "Lyrics_{}.{}".format(self.artist.replace(" ", ""), format_)
AttributeError: 'Artist' object has no attribute 'artist'

Version info

  • Package version: 1.0.0
  • OS: Windows 10

Additional context
Add any other context about the problem here.

@johnwmillr
Copy link
Owner

Ah, thanks for catching this bug! I think the fix is as changing self.artist to self.name. I'll try to make the fix and update the code tonight.

@johnwmillr
Copy link
Owner

Hopefully that small change fixes the bug! I had written a test for Artist.save_lyrics, but the test supplies a filename to the function; this bug only shows up when the user doesn't pass a filename in.

@robot3498712
Copy link

Hi, something appears being off still. Minimal script is failing:

import lyricsgenius as genius
access_token = 'XXXX'
api = genius.Genius(access_token)
artist = api.search_artist("The Beatles", max_songs=3)
artist.save_lyrics(format_='json', filename='out.json')


.\python\lyrics>py -3 ./genius.py
Searching for songs by The Beatles...

Song 1: "12-Bar Original"
Song 2: "1822!"
"1 [Booklet]" is not valid. Skipping.
"20 Greatest Hits - Art and Tracklist" is not valid. Skipping.
Song 3: ""Abbey Road" side two"

Reached user-specified song limit (3).
Done. Found 3 songs.
Traceback (most recent call last):
File "./genius.py", line 19, in
artist.save_lyrics(format_='json', filename='out.json')
File "C:\Python3\lib\site-packages\lyricsgenius\artist.py", line 129, in save_lyrics
lyrics_to_write['songs'][-1]['album'] = song.album
File "C:\Python3\lib\site-packages\lyricsgenius\song.py", line 45, in album
if 'album' in self._body and 'name' in self._body['album']:
TypeError: argument of type 'NoneType' is not iterable

.\python\lyrics>py -3 --version
Python 3.6.2

Repository owner deleted a comment from dorg-jmiller Dec 4, 2018
@johnwmillr
Copy link
Owner

Shoot, okay. I'll try to take another look in the next couple of days. Thanks for following up.

@johnwmillr johnwmillr reopened this Dec 4, 2018
@johnwmillr johnwmillr changed the title Artist.SaveLyrics() doesn't work artist.save_lyrics failing Dec 4, 2018
@johnwmillr johnwmillr changed the title artist.save_lyrics failing Artist.save_lyrics failing Dec 4, 2018
@johnwmillr johnwmillr self-assigned this Dec 7, 2018
@johnwmillr johnwmillr added the bug label Dec 7, 2018
@johnwmillr
Copy link
Owner

@robot3498712 hopefully #75 fixes this bug for you. I was using a sloppy method of accessing elements within the Song object's self._body dictionary, causing an error when the requested field wasn't present in the dict. Let me know if you do run into any more bugs!

@robot3498712
Copy link

@johnwmillr Thank you, I can confirm issue is fixed. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants