Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -42,18 +42,7 @@ def extract_track_id_from_url(url):
|
|
| 42 |
|
| 43 |
def app():
|
| 44 |
|
| 45 |
-
|
| 46 |
-
auth_code = st.session_state['code']
|
| 47 |
-
token_data = {
|
| 48 |
-
'grant_type': 'authorization_code',
|
| 49 |
-
'code': auth_code,
|
| 50 |
-
'redirect_uri': REDIRECT_URI,
|
| 51 |
-
'client_id': CLIENT_ID,
|
| 52 |
-
'client_secret': CLIENT_SECRET,
|
| 53 |
-
}
|
| 54 |
-
token_r = requests.post(TOKEN_URL, data=token_data)
|
| 55 |
-
token_response = token_r.json()
|
| 56 |
-
st.session_state['access_token'] = token_response.get('access_token')
|
| 57 |
# Step 1: User Authorization
|
| 58 |
if st.session_state.get('code') is None or ('access_token' not in st.session_state or st.session_state['access_token'] is None):
|
| 59 |
auth_params = {
|
|
@@ -65,6 +54,21 @@ def app():
|
|
| 65 |
st.write('Please log in to Spotify')
|
| 66 |
st.markdown(f"[Log In]({AUTH_URL}?{urlencode(auth_params)})", unsafe_allow_html=True)
|
| 67 |
else:#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
if 'access_token' in st.session_state:
|
| 69 |
st.write("Enter a Spotify Track URL or URI to get its audio features.")
|
| 70 |
track_input = st.text_input("Spotify Track URL/URI", "")
|
|
|
|
| 42 |
|
| 43 |
def app():
|
| 44 |
|
| 45 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
# Step 1: User Authorization
|
| 47 |
if st.session_state.get('code') is None or ('access_token' not in st.session_state or st.session_state['access_token'] is None):
|
| 48 |
auth_params = {
|
|
|
|
| 54 |
st.write('Please log in to Spotify')
|
| 55 |
st.markdown(f"[Log In]({AUTH_URL}?{urlencode(auth_params)})", unsafe_allow_html=True)
|
| 56 |
else:#
|
| 57 |
+
# Step 2: Request Access Token
|
| 58 |
+
if 'access_token' not in st.session_state or (st.session_state['access_token'] is None):
|
| 59 |
+
auth_code = st.session_state['code']
|
| 60 |
+
|
| 61 |
+
token_data = {
|
| 62 |
+
'grant_type': 'authorization_code',
|
| 63 |
+
'code': auth_code,
|
| 64 |
+
'redirect_uri': REDIRECT_URI,
|
| 65 |
+
'client_id': CLIENT_ID,
|
| 66 |
+
'client_secret': CLIENT_SECRET,
|
| 67 |
+
}
|
| 68 |
+
token_r = requests.post(TOKEN_URL, data=token_data)
|
| 69 |
+
token_response = token_r.json()
|
| 70 |
+
st.session_state['access_token'] = token_response.get('access_token')
|
| 71 |
+
|
| 72 |
if 'access_token' in st.session_state:
|
| 73 |
st.write("Enter a Spotify Track URL or URI to get its audio features.")
|
| 74 |
track_input = st.text_input("Spotify Track URL/URI", "")
|