-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspotify_convert_artists.py
48 lines (40 loc) · 1.32 KB
/
spotify_convert_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
# Script to convert music artist names to 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_plain.txt in same folder as this python script consisting
# of one artist name per line (ex. The Prodigy)
# - run ./spotify_convert_artists.py
# - after finishing you'll find a new file artist_converted.txt with spotify IDs
# in same folder as script
import spotipy
import sys
import pprint
import spotipy
import spotipy.util as util
import spotipy.oauth2 as oauth2
SPOTIPY_CLIENT_ID=''
SPOTIPY_CLIENT_SECRET=''
SPOTIPY_REDIRECT_URI=''
username = ''
scope = 'user-library-modify'
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
)
sp = spotipy.Spotify(auth=token)
file = open("artists_plain.txt", "r", encoding="utf8")
for line in file:
with open("artists_converted.txt", "a") as myfile:
result = sp.search(line, limit=1, type='artist')
if result['artists']['items']:
myfile.write(result['artists']['items'][0]['id'] + "\n")