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

Properly get_full_info for songs and albums #181

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 20 additions & 21 deletions lyricsgenius/genius.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,10 @@ def search_album(self, name=None, artist="",
print('Searching for "{s}"...'.format(s=name))

if album_id:
search_term = "id:{id}".format(id=album_id)
Steffo99 marked this conversation as resolved.
Show resolved Hide resolved
album_info = self.album(album_id, text_format).get('album')
else:
search_term = "{s} {a}".format(s=name, a=artist).strip()
search_term = "'{s} {a}'".format(s=name, a=artist).strip()
Steffo99 marked this conversation as resolved.
Show resolved Hide resolved
response = self.search_all(search_term)
album_info = self._get_item_from_search_response(response, name,
type_="album",
Expand All @@ -319,9 +320,14 @@ def search_album(self, name=None, artist="",
# Otherwise, move forward with processing the search results
if album_info is None:
if self.verbose and name:
print("No results found for: '{s}'".format(s=search_term))
print("No results found for: {s}".format(s=search_term))
return None

# If the album was searched, query the API using the album id so the full info can be retrieved
if album_id is None and get_full_info:
album_info.update(self.album(album_info['id'], text_format)['album'])

# Set the album id to the value retrieved from the API
album_id = album_info['id']

tracks = []
Expand Down Expand Up @@ -349,10 +355,6 @@ def search_album(self, name=None, artist="",

next_page = tracks_list['next_page']

if album_id is None and get_full_info is True:
new_info = self.album(album_id, text_format=text_format)['album']
album_info.update(new_info)

return Album(self, album_info, tracks)

def search_song(self, title=None, artist="", song_id=None,
Expand Down Expand Up @@ -395,25 +397,26 @@ def search_song(self, title=None, artist="", song_id=None,
print('Searching for "{s}"...'.format(s=title))

if song_id:
result = self.song(song_id)['song']
search_term = "id:{id}".format(id=song_id).strip()
Steffo99 marked this conversation as resolved.
Show resolved Hide resolved
song_info = self.song(song_id)['song']
else:
search_term = "{s} {a}".format(s=title, a=artist).strip()
search_term = "'{s} {a}'".format(s=title, a=artist).strip()
Steffo99 marked this conversation as resolved.
Show resolved Hide resolved
search_response = self.search_all(search_term)
result = self._get_item_from_search_response(search_response,
title,
type_="song",
result_type="title")
song_info = self._get_item_from_search_response(search_response,
title,
type_="song",
result_type="title")

# Exit search if there were no results returned from API
# Otherwise, move forward with processing the search results
if result is None:
if song_info is None:
if self.verbose and title:
print("No results found for: '{s}'".format(s=search_term))
print("No results found for: {s}".format(s=search_term))
return None

# Reject non-songs (Liner notes, track lists, etc.)
# or songs with uncomplete lyrics (e.g. unreleased songs, instrumentals)
if self.skip_non_songs and not self._result_is_lyrics(result):
if self.skip_non_songs and not self._result_is_lyrics(song_info):
valid = False
else:
valid = True
Expand All @@ -423,13 +426,9 @@ def search_song(self, title=None, artist="", song_id=None,
print('Specified song does not contain lyrics. Rejecting.')
return None

song_id = result['id']

# Download full song info (an API call) unless told not to by user
song_info = result
if song_id is None and get_full_info is True:
new_info = self.song(song_id)['song']
song_info.update(new_info)
if song_id is None and get_full_info:
song_info.update(self.song(song_info['id'])['song'])

if (song_info['lyrics_state'] == 'complete'
and not song_info.get('instrumental')):
Expand Down