def delete_all_playlists(): input( 'ARE YOU SURE YOU WANT TO DELETE 50 PLAYLISTS? HIT CTRL+C TO STOP, OR ENTER TO CONTINUE.' ) access_token = spotify.get_access_token() sp = spotipy.Spotify(access_token) playlists = sp.current_user_playlists()['items'] for playlist in playlists: print("Deleting playlist '" + playlist['name'] + "'...") sp.user_playlist_unfollow(user=spotify_config.SONGBIRD_USER_ID, playlist_id=playlist['id']) os.remove('.spotipyoauthcache') print(str(len(playlists)) + " playlists deleted.")
def test_generate_playlist_pos_seeds_under_5_valid_only_genres(self): test_url = spotify.generate_playlist(handle='@SomePositiveSeeds', seeds=(["rock", "hip-hop"], [])) expected_prefix = spotify_config.PLAYLIST_PREFIX assert test_url.find(expected_prefix) == 0 assert len(test_url) > len(expected_prefix) sp = spotipy.Spotify(spotify.get_access_token()) test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url) assert len( test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE sp.user_playlist_unfollow( user=spotify_config.SONGBIRD_USER_ID, playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
def test_generate_playlist_neg_seeds_neg_feature(self): test_url = spotify.generate_playlist(handle='@LowAccousitcs', seeds=(["cheese", "rock"], ["acousticness"])) expected_prefix = spotify_config.PLAYLIST_PREFIX assert test_url.find(expected_prefix) == 0 assert len(test_url) > len(expected_prefix) sp = spotipy.Spotify(spotify.get_access_token()) test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url) assert len( test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE sp.user_playlist_unfollow( user=spotify_config.SONGBIRD_USER_ID, playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
def test_generate_playlist_only_handle(self): test_url = spotify.generate_playlist(handle='@SampleHandle') expected_prefix = spotify_config.PLAYLIST_PREFIX assert test_url.find(expected_prefix) == 0 assert len(test_url) > len(expected_prefix) sp = spotipy.Spotify(spotify.get_access_token()) test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url) correct_tracks = spotify_config.SOUNDS_OF_SILENCE assert len(test_playlist_tracks.get('items')) == 3 for test_track in test_playlist_tracks.get('items'): assert test_track.get('track').get('id') in correct_tracks sp.user_playlist_unfollow( user=spotify_config.SONGBIRD_USER_ID, playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
def test_generate_playlist_pos_seeds_genres_some_invalid(self): test_url = spotify.generate_playlist( handle='@AllInvalidSeeds', seeds=(["cheese", "valence", "loudness", "test", "Franklin"], [])) expected_prefix = spotify_config.PLAYLIST_PREFIX assert test_url.find(expected_prefix) == 0 assert len(test_url) > len(expected_prefix) sp = spotipy.Spotify(spotify.get_access_token()) test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url) correct_tracks = spotify_config.SOUNDS_OF_SILENCE assert len(test_playlist_tracks.get('items')) == 3 for test_track in test_playlist_tracks.get('items'): assert test_track.get('track').get('id') in correct_tracks sp.user_playlist_unfollow( user=spotify_config.SONGBIRD_USER_ID, playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
def test_generate_playlist_lots_of_seeds(self): test_url = spotify.generate_playlist( handle='@ManySeeds', seeds=([ "cheese", "valence", "loudness", "test", "Franklin", "rock", "hip-hop", "danceability", "metal", "alt-rock" ], ["classical", "loudness", "wow", "acousticness"])) expected_prefix = spotify_config.PLAYLIST_PREFIX assert test_url.find(expected_prefix) == 0 assert len(test_url) > len(expected_prefix) sp = spotipy.Spotify(spotify.get_access_token()) test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url) assert len( test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE sp.user_playlist_unfollow( user=spotify_config.SONGBIRD_USER_ID, playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
def test_generate_playlist_pos_seeds_over_5_invalid(self): test_url = spotify.generate_playlist( handle='@ManyPositiveInvalidSeeds', seeds=([ "valence", "rock", "hip-hop", "cheese", "classical", "disco", "electronic", "folk", "funk", "metal" ], [])) expected_prefix = spotify_config.PLAYLIST_PREFIX assert test_url.find(expected_prefix) == 0 assert len(test_url) > len(expected_prefix) sp = spotipy.Spotify(spotify.get_access_token()) test_playlist_tracks = sp.playlist_tracks(playlist_id=test_url) assert len( test_playlist_tracks.get('items')) >= spotify_config.MIN_SIZE sp.user_playlist_unfollow( user=spotify_config.SONGBIRD_USER_ID, playlist_id=test_url[len(spotify_config.PLAYLIST_PREFIX):])
def test_recommendation_sorcery(self): genres = ['rock', 'pop'] access_token = spotify.get_access_token() sp = spotipy.Spotify(access_token) # Can use the 'dict' object to pass in named arguments (keyword args) # KEY: name of parameter # VALUE: value of parameter # MUST USE ** to 'unpack' dict into parameter form magic = dict(seed_genres=genres, limit=spotify_config.PLAYLIST_SIZE) test = 'target_valence' magic[test] = 0.8 test_recs = sp.recommendations(**magic) assert test_recs is not None assert len(test_recs.get('tracks')) >= spotify_config.MIN_SIZE
def test_get_access_token(self): test_access_token = spotify.get_access_token() print(len(test_access_token)) print(test_access_token) assert test_access_token is not None