-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotify_follow_artists.py
64 lines (53 loc) · 1.56 KB
/
spotify_follow_artists.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Script to automatically follow Spotify artists by their Spotify IDs
#
# Requirements:
# Python 3
# spotipy (pip install spotipy)
#
# Usage:
# - Replace SPOTIPY_CLIENT_ID, SPOTIPY_CLIENT_SECRET, SPOTIPY_REDIRECT_URI
# with values for your app (you can get these from Spotify API page)
# - replace username variable with your username
# - create file artists.txt in same folder as this python script consisting
# of one artist ID per line in Spotify ID format (ex. 1yDI9pWnlrJmi9kZn3gkCb)
# - run ./spotify_follow_artists.py
import pprint
import sys
import time
import spotipy
import spotipy.util as util
import spotipy.oauth2 as oauth2
SPOTIPY_CLIENT_ID=''
SPOTIPY_CLIENT_SECRET=''
SPOTIPY_REDIRECT_URI=''
username = ''
scope = 'user-follow-modify'
artist_ids = []
artist_ids_sub = []
artist_ids_final = []
artist_counter = 0
file = open("artists.txt", "r", encoding="utf8")
for line in file:
artist_ids.append(line.rstrip())
for artist_id in artist_ids:
if artist_counter == 49:
artist_ids_final.append(artist_ids_sub)
artist_counter = 0
artist_ids_sub = []
artist_ids_sub.append(artist_id)
artist_counter += 1
token = util.prompt_for_user_token(
username=username,
scope=scope,
client_id=SPOTIPY_CLIENT_ID,
client_secret=SPOTIPY_CLIENT_SECRET,
redirect_uri=SPOTIPY_REDIRECT_URI
)
if token:
sp = spotipy.Spotify(auth=token)
# sp.trace = True
for artist_id_new in artist_ids_final:
sp.user_follow_artists(artist_id_new)
time.sleep(10)
else:
print("Can't get token for", username)