Some cleanup

This commit is contained in:
ritiek
2018-01-12 21:52:43 +05:30
parent 8c6cc1cc22
commit 621e1eb21e
3 changed files with 7 additions and 9 deletions

View File

@@ -18,6 +18,8 @@ def generate_token():
token = credentials.get_access_token() token = credentials.get_access_token()
return 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() token = generate_token()
spotify = spotipy.Spotify(auth=token) spotify = spotipy.Spotify(auth=token)

View File

@@ -192,11 +192,6 @@ def grab_single(raw_song, number=None):
log.error('No audio streams available') 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__': if __name__ == '__main__':
const.args = handle.get_arguments() const.args = handle.get_arguments()
internals.filter_path(const.args.folder) internals.filter_path(const.args.folder)

View File

@@ -4,25 +4,26 @@ import spotdl
username = 'alex' username = 'alex'
spotify = spotdl.spotify_tools.spotify
def test_user(): def test_user():
expect_playlists = 7 expect_playlists = 7
playlists = spotdl.spotify.user_playlists(username) playlists = spotify.user_playlists(username)
playlists = len(playlists['items']) playlists = len(playlists['items'])
assert playlists == expect_playlists assert playlists == expect_playlists
def test_playlist(): def test_playlist():
expect_tracks = 14 expect_tracks = 14
playlist = spotdl.spotify.user_playlists(username)['items'][0] playlist = spotify.user_playlists(username)['items'][0]
tracks = playlist['tracks']['total'] tracks = playlist['tracks']['total']
assert tracks == expect_tracks assert tracks == expect_tracks
def test_tracks(): def test_tracks():
playlist = spotdl.spotify.user_playlists(username)['items'][0] playlist = spotify.user_playlists(username)['items'][0]
expect_lines = playlist['tracks']['total'] expect_lines = playlist['tracks']['total']
result = spotdl.spotify.user_playlist( result = spotify.user_playlist(
playlist['owner']['id'], playlist['id'], fields='tracks,next') playlist['owner']['id'], playlist['id'], fields='tracks,next')
tracks = result['tracks'] tracks = result['tracks']