sjw commited on
Commit
b2eaf79
·
1 Parent(s): fd79f32

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -151,26 +151,20 @@ scope= ['user-library-read',
151
  'user-top-read']
152
 
153
 
154
- def spotify_auth(client_id, client_secret, code=None):
155
  auth_manager = SpotifyOAuth(client_id=client_id,
156
  client_secret=client_secret,
157
  redirect_uri=redirect_uri,
158
  scope=scope)
159
  if code:
160
- parsed_url = urlparse(code)
161
- code = parse_qs(parsed_url.query)['code'][0]
162
- auth_manager.get_access_token(code=code, as_dict=False)
163
- #auth_manager.get_cached_token() # if .cache exists
164
-
165
  sp = spotipy.Spotify(auth_manager=auth_manager)
166
  devices = sp.devices()
167
  device_id = devices['devices'][0]['id']
168
-
169
  results = sp.search(q="No Pole", type='track')
170
  track_uri = results['tracks']['items'][0]['uri']
171
  sp.start_playback(device_id=device_id, uris=[track_uri])
172
-
173
- return "Login Successful"
174
  else:
175
  auth_url = auth_manager.get_authorize_url()
176
  return f"Please authorize the app by clicking [here]({auth_url}) and then paste the code below."
@@ -185,7 +179,7 @@ def gradio_interface():
185
  ],
186
  outputs=["markdown"],
187
  description="Authorize and paste the code here:",
188
- live=False,
189
  theme="finlaymacklon/boxy_violet"
190
  )
191
  interface.launch()
 
151
  'user-top-read']
152
 
153
 
154
+ def spotify_auth(code=None):
155
  auth_manager = SpotifyOAuth(client_id=client_id,
156
  client_secret=client_secret,
157
  redirect_uri=redirect_uri,
158
  scope=scope)
159
  if code:
160
+ token_info = auth_manager.get_access_token(code=code)
 
 
 
 
161
  sp = spotipy.Spotify(auth_manager=auth_manager)
162
  devices = sp.devices()
163
  device_id = devices['devices'][0]['id']
 
164
  results = sp.search(q="No Pole", type='track')
165
  track_uri = results['tracks']['items'][0]['uri']
166
  sp.start_playback(device_id=device_id, uris=[track_uri])
167
+ return f"Account switched successfully.\n{devices}"
 
168
  else:
169
  auth_url = auth_manager.get_authorize_url()
170
  return f"Please authorize the app by clicking [here]({auth_url}) and then paste the code below."
 
179
  ],
180
  outputs=["markdown"],
181
  description="Authorize and paste the code here:",
182
+ allow_flagging="never",
183
  theme="finlaymacklon/boxy_violet"
184
  )
185
  interface.launch()