forked from bee-san/Spotify-Twilio-songs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspootipy.py
144 lines (136 loc) · 6.36 KB
/
spootipy.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
from __future__ import print_function
import sys
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy.util as util
import json
client_id = '04ba7c46b6224c5f9e3721469ea10bb3'
client_secret = '43077ed6c459406c8bc4d984c7fec45e'
redirect_uri = 'http://localhost:8888/'
username = 'ryankrage77'
user_id = '21gwsd5wok363feqdz27rgu2q'
playlist = '7rDiVWYOh2abdvBB6Zcxva'
scope = 'playlist-modify-private user-library-read user-library-modify playlist-modify-public playlist-read-collaborative playlist-read-private'
token = util.prompt_for_user_token(client_id, scope)
sp = spotipy.Spotify(auth=token)
searched = []
debug = False;
def req():
if token:
util.prompt_for_user_token(username, scope, client_id, client_secret, redirect_uri)
sp.trace = debug
sp.trace_out = debug
print("args: g(et), s(et), q(uit)")
answer1 = input()
if answer1 == 'get' or answer1 == 'g':
print("args: u(ser), p(laylist), s(earch), q(uit)")
answer2 = input()
if answer2 == 'user' or answer2 == 'u':
sp.current_user()
with open('data/user.info', 'r+') as userinfo:
json.dump(sp.current_user(), userinfo, ensure_ascii=False)
if answer2 == 'playlist' or answer2 == 'p':
sp.user_playlist(user_id, playlist)
with open('data/playlist.info', 'r+') as playlistinfo:
json.dump(sp.user_playlist(user_id, playlist), playlistinfo, ensure_ascii=False)
if answer2 == 'search' or answer2 == 's':
print("args: t(rack), a(lbum), b(and), q(uit)")
answer3 = input()
if answer3 == 'track' or answer3 == 't':
print("which track do you want to search for?")
answer4 = input()
result = sp.search(q='track:' + answer4, type='track')
items = result['tracks']['items']
track = items[0]
trackid = [ track['id'] ]
print('The song', track['name'], 'has the ID of', track['id'])
print("do you want to add this to the: p(laylist), s(earched list) or n(othing)")
answer5 = input()
if answer5 == 'playlist' or answer5 == 'p':
sp.user_playlist_add_tracks(user_id, playlist, trackid)
print("added to the playlist")
main()
if answer5 == 'searched' or answer5 == 's':
searched.append(trackid)
print("added to the recently searched list")
main()
if answer5 == 'nothing' or answer5 == 'n':
main()
if answer3 == 'album' or answer3 == 'a':
print("which album do you want to search for?")
answer4 = input()
result = sp.search(q='album:' + answer4, type='album')
items = result['albums']['items']
album = items[0]
print('The album', album['name'], 'by', album['artist'], 'has the ID of', album['id'])
main()
if answer3 == 'band' or answer3 == 'b':
print("which band/musician/artist do you want to search for?")
answer4 = input()
result = sp.search(q='artist:' + answer4, type='artist')
items = result['artists']['items']
artist = items[0]
print('The artist', artist['name'], 'has the ID of', artist['id'])
main()
if answer3 == 'quit' or answer3 == 'q':
sys.exit()
if answer2 == 'quit' or answer2 == 'q':
sys.exit()
else:
main()
if answer1 == 'set' or answer1 == 's':
print("args: (a)dd, (r)emove, (p)osition, s(earched), q(uit)")
answer2 = input()
if answer2 == 'add' or answer2 == 'a':
print("track id?")
track_id = input()
track_id2 = [ track_id ]
sp.user_playlist_add_tracks(user_id, playlist, track_id2)
with open('data/addhist.info', 'r+') as addhistinfo:
json.dump(sp.user_playlist_add_tracks(user_id, playlist, track_id2), userinfo, ensure_ascii=False)
main()
if answer2 == 'remove' or answer2 == 'r':
print("please note that this will remove all occurences of the track!")
print("track id?")
track_id = input()
track_id2 = [ track_id ]
sp.user_playlist_remove_all_occurrences_of_tracks(user_id, playlist, track_id2)
with open('data/remhist.info', 'r+') as remhistinfo:
json.dump(sp.user_playlist_remove_all_occurrences_of_tracks(user_id, playlist, track_id2), userinfo, ensure_ascii=False)
main()
if answer2 == 'position' or answer2 == 'p':
print("track id?")
track_id = input()
track_id2 = [ track_id ]
print("position?")
pos = input()
sp.user_playlist_add_tracks(user_id, playlist, track_id2, pos)
with open('data/poshist.info', 'r+') as poshistinfo:
json.dump(sp.user_playlist_add_tracks(user_id, playlist, track_id2, pos), userinfo, ensure_ascii=False)
main()
if answer2 == 'searched' or answer2 == 's':
if len(searched) >= 1:
sp.user_playlist_add_tracks(user_id, playlist, searched[0])
print("added", searched[0], "and removing it from the list")
searched.pop(0)
main()
else:
print("the searched list is empty")
main()
main()
if answer2 == 'quit' or answer2 == 'q':
sys.exit()
else:
print("reloading the program")
main()
if answer1 == 'quit' or answer1 == 'q':
sys.exit()
else:
main()
else:
print("cannot find", client_id)
sys.exit()
def main():
#sysult.clear()
req()
main()