diff --git a/utils/__init__.py b/utils/__init__.py index bf38d22..25bf961 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -1,5 +1,5 @@ import spotipy -from time import localtime +from time import localtime, sleep REDIRECT="http://localhost:1337" SCOPE="playlist-modify-private playlist-modify-public playlist-read-private playlist-read-collaborative" TOKENS_FILE="tokens.json" @@ -9,6 +9,7 @@ YEAR=localtime()[0] GITHUB="https://github.com/retrohacking" +RATE_LIMIT=100 LIMIT_PLAYLIST_TRACK=100 DEFAULT_GENRES=["rock", "metal", "funk", "punk", "trap", "hip hop", "rap", "pop", "r&b", "reggae", "soul"] PLAYLISTS_PREFIX="GENSORT_" diff --git a/utils/gensort_functionalities.py b/utils/gensort_functionalities.py index 0f683ec..9d36df4 100644 --- a/utils/gensort_functionalities.py +++ b/utils/gensort_functionalities.py @@ -29,6 +29,8 @@ def collect_tracks(spotify,playlist): artist=spotify.artist(sp_track["artists"][0]["id"]) tracks[track["track"]["id"]]=artist["genres"] print(f'\rLoading{"."*((i%3)+1)}{" "*(3-(i%3)+1)}', end='') + if (i%RATE_LIMIT==0): + sleep(3.0) i+=1 return tracks @@ -87,6 +89,8 @@ def gensort_playlists(chosen, playlists, user_playlists, spotify): for song in playlists[sorted_playlists_name]: spotify.playlist_add_items(final_playlist_id, [song]) print(f'\rLoading{"."*((i%3)+1)}{" "*(3-(i%3)+1)}', end='') + if (i%RATE_LIMIT==0): + sleep(3.0) i+=1 else: new_playlist_id=spotify.user_playlist_create(username, final_playlist_name, public=False, collaborative=False, description=PLAYLISTS_DESCRIPTION)["id"] @@ -94,5 +98,7 @@ def gensort_playlists(chosen, playlists, user_playlists, spotify): for song in playlists[sorted_playlists_name]: spotify.playlist_add_items(new_playlist_id, [song]) print(f'\rLoading{"."*((i%3)+1)}{" "*(3-(i%3)+1)}', end='') + if (i%RATE_LIMIT==0): + sleep(3.0) i+=1 print(f"\r{len(playlists[sorted_playlists_name])} songs have been added to {final_playlist_name}") \ No newline at end of file