artist = song_arr[i][0] track = song_arr[i][1] uri = spot_client.search_song(artist, track) if uri is None: print(f"No song found for {artist} {track}") else: uri_list.append(uri) print(f"Found {artist} {track}") found_counter += 1 print(f"Found {found_counter} out of {len(song_arr)} songs on spotify") # Make request to add 100 songs to playlist (max) request_lists = [] start_i = 0 end_i = 100 for i in range(len(uri_list) // 100): request_lists.append(uri_list[start_i:end_i]) start_i += 100 end_i += 100 end_i -= 100 end_i += len(uri_list) % 100 request_lists.append(uri_list[start_i:end_i]) for request in request_lists: spot_client.add_songs(spot_playlist_id, request) print("Songs added")
from spotify_client import SpotifyClient # from looking at the KDE plots in plots.py, the darkest regions were in these bounds: max_energy = 0.8 min_energy = 0.6 max_valence = 0.63 min_valence = 0.47 max_tempo = 133 min_tempo = 77 new_songs = [] # now we want to go through our dataframe of liked songs and get our "ideal songs": # songs which fall into the bounds of the KDE plot highest density regions. name = "audio_features.csv" ideal_songs = DataAnalysis.ideal_song(pd, name, max_energy, max_valence, max_tempo, min_energy, min_valence, min_tempo) print("Obtained ideal songs to generate your recommendations successfully.") # now, using this list of ideal songs, we need to get our list of recommendations: # we will loop through so that we can get recommendations from all of our ideal songs: SpotifyClient.recommended_songs(sp, ideal_songs, new_songs, max_energy, max_valence, max_tempo, min_energy, min_valence, min_tempo) print("Found recommendations for you successfully.") # create the playlist to put our recommended songs into playlist = SpotifyClient.create_playlist(sp) # add the recommended songs to our new playlist SpotifyClient.add_songs(sp, playlist, new_songs)