johnwmillr / LyricsGenius

Download song lyrics and metadata from Genius.com 🎶🎤
http://www.johnwmillr.com/scraping-genius-lyrics/
MIT License
892 stars 158 forks source link

AttributeError when searching for albums that do not have full release date listed #195

Closed BrodyMcNutt closed 3 years ago

BrodyMcNutt commented 3 years ago

Describe the bug When using the search_album function, an attribute error occurs for albums that do not have the full release data listed on their Genius page. For example, the page for Joey Purp's album iiiDrops says "Released 2016", while most pages give an exact date.

Expected behavior I expect the function to retrieve the album information for the given album and provide either a null value or just the year for the release date if the exact release date is not known.

To Reproduce Search for any album that does not have a full release date. Using the same example given before:

import lyricsgenius
token = 'YOURTOKENHERE'
genius = lyricsgenius.Genius(token)
album = genius.search_album("iiiDrops", "Joey Purp")

Output:

Searching for "iiiDrops" by Joey Purp...

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-58-0284c1ae1410> in <module>
----> 1 album = genius.search_album("iiiDrops", "Joey Purp")

~/opt/anaconda3/envs/DataMining/lib/python3.8/site-packages/lyricsgenius/genius.py in search_album(self, name, artist, album_id, get_full_info, text_format)
    354             album_info.update(new_info)
    355 
--> 356         return Album(self, album_info, tracks)
    357 
    358     def search_song(self, title=None, artist="", song_id=None,

~/opt/anaconda3/envs/DataMining/lib/python3.8/site-packages/lyricsgenius/types/album.py in __init__(self, client, json_dict, tracks)
     15         self.artist = Artist(client, body['artist'])
     16         self.tracks = tracks
---> 17         self.release_date_components = convert_to_datetime(
     18             body['release_date_components']
     19         )

~/opt/anaconda3/envs/DataMining/lib/python3.8/site-packages/lyricsgenius/utils.py in convert_to_datetime(f)
     55         f = date
     56 
---> 57     if f.count('-') == 2:
     58         date_format = "%Y-%m-%d"
     59     elif f.count('-') == 1:

AttributeError: 'int' object has no attribute 'count'

Include the error message associated with the bug.

Version info

Additional context Based on the error message, I figured the issue likely had something to do with the date format. After checking manually, all of the albums I tried that produced this error had a release date like the example given here on their respective Genius pages, but it is possible that there may be other problematic date formats as well. This is the only problem I have had using the API so far, thank you for the great work you all have done on this!

BrodyMcNutt commented 3 years ago

My mistake, I now see this bug has been brought up before and a fix was suggested in this pull request, but has not been merged yet.