I'm building basic spotipy
code that is creating playlist containing top songs of given artist. Code works for some artists, but e.g. for Adele it adds songs that aren't Adele's. Here is part of my code:
def get_songs_uris(self, top_artist_name, top_songs):
for i in range(len(top_songs)):
songs_data = self.sp.search(
q=f"artist: {top_artist_name}, track: {top_songs[i]}",
type="track", limit=1)
self.songs_URIs.append(songs_data["tracks"]["items"][0]["uri"])
return self.songs_URIs
Where top_artist_name="Adele"
and top_songs
is list of titles of most popular Adele's songs.
Code runs okay, but...
Playlist is created and all songs are added, but e.g. song "Someone Like You" have artist "Mason" instead of "Adele". Some other tracks are indeed Adele's, but not all.
Artist ID
An artist given may have more than meaning. It could be
id
(e.g.4dpARuHxo51G3z768sgnrY
) oruri
(spotify:artist:4dpARuHxo51G3z768sgnrY
). If not and we have only the name, we need to obtain one of those possibly via searching. I presume there should be some user interaction, because Spotify's search is somewhat unpredictable and not always reproducible.Artist's Top Tracks
Spotify provides an endpoint for acquiring artist's top track (by country) and
spotipy
has it implemented. Processing is somewhat straightforward:But it's only 10 tracks per an artist and may not meet your needs.
Filter search results
Another idea is to try filtering search results of tracks by an artist. Here is a sample implementation of that idea:
Can apply further actions to the result collected:
Sample output:
The result resembles a quick reference, however some tracks are missing due to a different Spotify's data. E.g. metadata of Ricsta - Be Divine feat. Adele doesn't hold any connection to Adele. But it could be not relevant to the top songs.