Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -93,12 +93,20 @@ def buscar_playlists_spotify(token, query, limit=50):
|
|
| 93 |
if limit <= 50:
|
| 94 |
params = {'q': query, 'type': 'playlist', 'limit': limit}
|
| 95 |
response = realizar_solicitud(url, headers, params)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
playlists.extend(response.json().get('playlists', {}).get('items', []))
|
| 97 |
else:
|
| 98 |
offset = 0
|
| 99 |
while limit > 0:
|
| 100 |
params = {'q': query, 'type': 'playlist', 'limit': min(50, limit), 'offset': offset}
|
| 101 |
response = realizar_solicitud(url, headers, params)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
playlists.extend(response.json().get('playlists', {}).get('items', []))
|
| 103 |
limit -= min(50, limit)
|
| 104 |
offset += 50
|
|
@@ -115,6 +123,10 @@ def obtener_canciones_playlist_spotify(token, playlist_id, playlist_name):
|
|
| 115 |
|
| 116 |
try:
|
| 117 |
response = realizar_solicitud(url, headers, {})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
if response.status_code == 200:
|
| 119 |
tracks = response.json().get('items')
|
| 120 |
for item in tracks:
|
|
@@ -146,12 +158,20 @@ def obtener_caracteristicas_audio(token, track_id):
|
|
| 146 |
url = f'https://api.spotify.com/v1/audio-features/{track_id}'
|
| 147 |
headers = {'Authorization': f'Bearer {token}'}
|
| 148 |
response = realizar_solicitud(url, headers, {})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
return response.json() if response.status_code == 200 else {}
|
| 150 |
|
| 151 |
def obtener_record_label_spotify(album_id, token):
|
| 152 |
url = f'https://api.spotify.com/v1/albums/{album_id}'
|
| 153 |
headers = {'Authorization': f'Bearer {token}'}
|
| 154 |
response = realizar_solicitud(url, headers, {})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
album_info = response.json() if response.status_code == 200 else {}
|
| 156 |
return album_info.get('label', 'No disponible')
|
| 157 |
|
|
|
|
| 93 |
if limit <= 50:
|
| 94 |
params = {'q': query, 'type': 'playlist', 'limit': limit}
|
| 95 |
response = realizar_solicitud(url, headers, params)
|
| 96 |
+
if response.status_code == 429:
|
| 97 |
+
token = obtener_nuevo_token()
|
| 98 |
+
headers = {'Authorization': f'Bearer {token}'}
|
| 99 |
+
response = realizar_solicitud(url, headers, params)
|
| 100 |
playlists.extend(response.json().get('playlists', {}).get('items', []))
|
| 101 |
else:
|
| 102 |
offset = 0
|
| 103 |
while limit > 0:
|
| 104 |
params = {'q': query, 'type': 'playlist', 'limit': min(50, limit), 'offset': offset}
|
| 105 |
response = realizar_solicitud(url, headers, params)
|
| 106 |
+
if response.status_code == 429:
|
| 107 |
+
token = obtener_nuevo_token()
|
| 108 |
+
headers = {'Authorization': f'Bearer {token}'}
|
| 109 |
+
response = realizar_solicitud(url, headers, params)
|
| 110 |
playlists.extend(response.json().get('playlists', {}).get('items', []))
|
| 111 |
limit -= min(50, limit)
|
| 112 |
offset += 50
|
|
|
|
| 123 |
|
| 124 |
try:
|
| 125 |
response = realizar_solicitud(url, headers, {})
|
| 126 |
+
if response.status_code == 429:
|
| 127 |
+
token = obtener_nuevo_token()
|
| 128 |
+
headers = {'Authorization': f'Bearer {token}'}
|
| 129 |
+
response = realizar_solicitud(url, headers, {})
|
| 130 |
if response.status_code == 200:
|
| 131 |
tracks = response.json().get('items')
|
| 132 |
for item in tracks:
|
|
|
|
| 158 |
url = f'https://api.spotify.com/v1/audio-features/{track_id}'
|
| 159 |
headers = {'Authorization': f'Bearer {token}'}
|
| 160 |
response = realizar_solicitud(url, headers, {})
|
| 161 |
+
if response.status_code == 429:
|
| 162 |
+
token = obtener_nuevo_token()
|
| 163 |
+
headers = {'Authorization': f'Bearer {token}'}
|
| 164 |
+
response = realizar_solicitud(url, headers, {})
|
| 165 |
return response.json() if response.status_code == 200 else {}
|
| 166 |
|
| 167 |
def obtener_record_label_spotify(album_id, token):
|
| 168 |
url = f'https://api.spotify.com/v1/albums/{album_id}'
|
| 169 |
headers = {'Authorization': f'Bearer {token}'}
|
| 170 |
response = realizar_solicitud(url, headers, {})
|
| 171 |
+
if response.status_code == 429:
|
| 172 |
+
token = obtener_nuevo_token()
|
| 173 |
+
headers = {'Authorization': f'Bearer {token}'}
|
| 174 |
+
response = realizar_solicitud(url, headers, {})
|
| 175 |
album_info = response.json() if response.status_code == 200 else {}
|
| 176 |
return album_info.get('label', 'No disponible')
|
| 177 |
|