-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadder.py
78 lines (64 loc) · 2.26 KB
/
adder.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
64
65
66
67
68
69
70
71
72
73
74
75
76
import sys
import spotipy
import spotipy.util as util
import os
p = os.getcwd()
scope = 'playlist-modify-private'
username = '~'
token = util.prompt_for_user_token(username,scope,client_id='~',client_secret='~',redirect_uri='http://localhost:3000/')
songs = []
notDone = []
if token:
sp = spotipy.Spotify(auth=token)
sp.trace = False
with open(p+"/songs1.txt","r") as infile:
counter = 0
for line in infile:
if counter == 0:
playlist_name = "~"
counter+=1
continue
else:
l = line.split("---")
try:
artistName = l[0]
trackName = l[1]
except IndexError:
print(l)
continue
q = "artist:"+artistName+" track:"+trackName
print(q)
res = sp.search(q, type="track", limit=5)
try:
a = (res['tracks']['items'][0])
print(counter)
counter+=1
songs.append(a['uri'])
except IndexError:
print("DOUBLE CHECKING")
q = "track:"+trackName
res = sp.search(q, type="track", limit=5)
try:
a = (res['tracks']['items'][0])
print(counter)
counter+=1
songs.append(a['uri'])
except IndexError:
notDone.append(q)
with open('tracks.txt','w') as of:
for s in songs:
of.write(s+"\n")
with open('orphans.txt','w') as ef:
for s in notDone:
ef.write(s)
print(songs)
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[0:100])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[100:200])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[200:300])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[300:400])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[400:500])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[500:600])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[600:700])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[700:800])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[800:900])
sp.user_playlist_add_tracks(username, playlist_id="4TDOprH7yaCBiz81JGcxWI", tracks=songs[900:1000])