From 621e1eb21eb096c095d805c02a2fa5d6f96aa4ec Mon Sep 17 00:00:00 2001 From: ritiek Date: Fri, 12 Jan 2018 21:52:43 +0530 Subject: [PATCH] Some cleanup --- core/spotify_tools.py | 2 ++ spotdl.py | 5 ----- test/test_username.py | 9 +++++---- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/core/spotify_tools.py b/core/spotify_tools.py index 3104e98..3a616be 100644 --- a/core/spotify_tools.py +++ b/core/spotify_tools.py @@ -18,6 +18,8 @@ def generate_token(): token = credentials.get_access_token() return token +# token is mandatory when using Spotify's API +# https://developer.spotify.com/news-stories/2017/01/27/removing-unauthenticated-calls-to-the-web-api/ token = generate_token() spotify = spotipy.Spotify(auth=token) diff --git a/spotdl.py b/spotdl.py index 95298d4..17e5e65 100755 --- a/spotdl.py +++ b/spotdl.py @@ -192,11 +192,6 @@ def grab_single(raw_song, number=None): log.error('No audio streams available') -# token is mandatory when using Spotify's API -# https://developer.spotify.com/news-stories/2017/01/27/removing-unauthenticated-calls-to-the-web-api/ -token = spotify_tools.generate_token() -spotify = spotipy.Spotify(auth=token) - if __name__ == '__main__': const.args = handle.get_arguments() internals.filter_path(const.args.folder) diff --git a/test/test_username.py b/test/test_username.py index 4e78f3d..4065f76 100644 --- a/test/test_username.py +++ b/test/test_username.py @@ -4,25 +4,26 @@ import spotdl username = 'alex' +spotify = spotdl.spotify_tools.spotify def test_user(): expect_playlists = 7 - playlists = spotdl.spotify.user_playlists(username) + playlists = spotify.user_playlists(username) playlists = len(playlists['items']) assert playlists == expect_playlists def test_playlist(): expect_tracks = 14 - playlist = spotdl.spotify.user_playlists(username)['items'][0] + playlist = spotify.user_playlists(username)['items'][0] tracks = playlist['tracks']['total'] assert tracks == expect_tracks def test_tracks(): - playlist = spotdl.spotify.user_playlists(username)['items'][0] + playlist = spotify.user_playlists(username)['items'][0] expect_lines = playlist['tracks']['total'] - result = spotdl.spotify.user_playlist( + result = spotify.user_playlist( playlist['owner']['id'], playlist['id'], fields='tracks,next') tracks = result['tracks']