Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,41 +1,45 @@
|
|
| 1 |
-
import os
|
| 2 |
-
import gradio as gr
|
| 3 |
-
import requests
|
| 4 |
|
| 5 |
-
#
|
| 6 |
CID = os.getenv("SPOTIFY_CLIENT_IDS", "").split(',')[0]
|
| 7 |
CSEC = os.getenv("SPOTIFY_CLIENT_SECRETS", "").split(',')[0]
|
| 8 |
|
| 9 |
-
def
|
|
|
|
| 10 |
if not (CID and CSEC):
|
| 11 |
return "❌ Faltan credenciales"
|
| 12 |
-
|
| 13 |
-
tok_resp = requests.post(
|
| 14 |
"https://accounts.spotify.com/api/token",
|
| 15 |
headers={"Content-Type":"application/x-www-form-urlencoded"},
|
| 16 |
data={"grant_type":"client_credentials"},
|
| 17 |
auth=(CID, CSEC)
|
| 18 |
)
|
| 19 |
-
if
|
| 20 |
-
return f"❌
|
| 21 |
-
token =
|
| 22 |
-
|
| 23 |
-
#
|
| 24 |
-
pid =
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
if resp.status_code == 200:
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
else:
|
| 31 |
-
return f"❌
|
| 32 |
|
| 33 |
iface = gr.Interface(
|
| 34 |
-
fn=
|
| 35 |
inputs=gr.Textbox(label="URL de Playlist"),
|
| 36 |
outputs="text",
|
| 37 |
-
title="🔍 Test
|
| 38 |
-
description="
|
| 39 |
)
|
| 40 |
|
| 41 |
if __name__=="__main__":
|
|
|
|
| 1 |
+
import os, gradio as gr, requests
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
# Toma las creds
|
| 4 |
CID = os.getenv("SPOTIFY_CLIENT_IDS", "").split(',')[0]
|
| 5 |
CSEC = os.getenv("SPOTIFY_CLIENT_SECRETS", "").split(',')[0]
|
| 6 |
|
| 7 |
+
def test_playlist_info(url_playlist):
|
| 8 |
+
# 1) Auth
|
| 9 |
if not (CID and CSEC):
|
| 10 |
return "❌ Faltan credenciales"
|
| 11 |
+
r = requests.post(
|
|
|
|
| 12 |
"https://accounts.spotify.com/api/token",
|
| 13 |
headers={"Content-Type":"application/x-www-form-urlencoded"},
|
| 14 |
data={"grant_type":"client_credentials"},
|
| 15 |
auth=(CID, CSEC)
|
| 16 |
)
|
| 17 |
+
if r.status_code != 200:
|
| 18 |
+
return f"❌ Error token {r.status_code}"
|
| 19 |
+
token = r.json().get("access_token")
|
| 20 |
+
|
| 21 |
+
# 2) ID limpio
|
| 22 |
+
pid = url_playlist.rstrip('/').split('/')[-1].split('?')[0]
|
| 23 |
+
|
| 24 |
+
# 3) Metadata endpoint
|
| 25 |
+
resp = requests.get(
|
| 26 |
+
f"https://api.spotify.com/v1/playlists/{pid}",
|
| 27 |
+
headers={"Authorization":f"Bearer {token}"}
|
| 28 |
+
)
|
| 29 |
if resp.status_code == 200:
|
| 30 |
+
d = resp.json()
|
| 31 |
+
name = d.get("name","?")
|
| 32 |
+
total = d.get("tracks",{}).get("total","?")
|
| 33 |
+
return f"✅ Playlist “{name}”: {total} tracks"
|
| 34 |
else:
|
| 35 |
+
return f"❌ Error {resp.status_code}: {resp.json()}"
|
| 36 |
|
| 37 |
iface = gr.Interface(
|
| 38 |
+
fn=test_playlist_info,
|
| 39 |
inputs=gr.Textbox(label="URL de Playlist"),
|
| 40 |
outputs="text",
|
| 41 |
+
title="🔍 Test Info Playlist",
|
| 42 |
+
description="Chequea nombre y total de tracks de una playlist pública"
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__=="__main__":
|