Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,6 +71,7 @@ def obtener_canciones_playlist_spotify(token, playlist_id, playlist_name):
|
|
| 71 |
if track:
|
| 72 |
audio_features = obtener_caracteristicas_audio(token, track['id'])
|
| 73 |
audio_analysis = obtener_analisis_audio(token, track['id'])
|
|
|
|
| 74 |
canciones.append({
|
| 75 |
'playlist_name': playlist_name,
|
| 76 |
'artista': track['artists'][0]['name'] if track['artists'] else 'Desconocido',
|
|
@@ -89,6 +90,7 @@ def obtener_canciones_playlist_spotify(token, playlist_id, playlist_name):
|
|
| 89 |
'timbre': audio_analysis.get('segments', [{}])[0].get('timbre', 'No disponible'),
|
| 90 |
'acousticness': audio_features.get('acousticness', 'No disponible'),
|
| 91 |
'liveness': audio_features.get('liveness', 'No disponible'),
|
|
|
|
| 92 |
'link': track['external_urls']['spotify'],
|
| 93 |
'record_label': obtener_record_label_spotify(track['album']['id'], token),
|
| 94 |
'source': 'Spotify'
|
|
@@ -116,6 +118,25 @@ def obtener_analisis_audio(token, track_id):
|
|
| 116 |
response = requests.get(url, headers={'Authorization': f'Bearer {token}'})
|
| 117 |
return response.json() if response.status_code == 200 else {}
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
def obtener_record_label_spotify(album_id, token):
|
| 120 |
url = f'https://api.spotify.com/v1/albums/{album_id}'
|
| 121 |
headers = {'Authorization': f'Bearer {token}'}
|
|
@@ -159,3 +180,4 @@ iface = gr.Interface(
|
|
| 159 |
description="Enter a search query to fetch playlists and their songs from Spotify. Client credentials are pre-configured."
|
| 160 |
)
|
| 161 |
iface.launch()
|
|
|
|
|
|
| 71 |
if track:
|
| 72 |
audio_features = obtener_caracteristicas_audio(token, track['id'])
|
| 73 |
audio_analysis = obtener_analisis_audio(token, track['id'])
|
| 74 |
+
key = obtener_clave(audio_analysis)
|
| 75 |
canciones.append({
|
| 76 |
'playlist_name': playlist_name,
|
| 77 |
'artista': track['artists'][0]['name'] if track['artists'] else 'Desconocido',
|
|
|
|
| 90 |
'timbre': audio_analysis.get('segments', [{}])[0].get('timbre', 'No disponible'),
|
| 91 |
'acousticness': audio_features.get('acousticness', 'No disponible'),
|
| 92 |
'liveness': audio_features.get('liveness', 'No disponible'),
|
| 93 |
+
'key': key,
|
| 94 |
'link': track['external_urls']['spotify'],
|
| 95 |
'record_label': obtener_record_label_spotify(track['album']['id'], token),
|
| 96 |
'source': 'Spotify'
|
|
|
|
| 118 |
response = requests.get(url, headers={'Authorization': f'Bearer {token}'})
|
| 119 |
return response.json() if response.status_code == 200 else {}
|
| 120 |
|
| 121 |
+
def obtener_clave(audio_analysis):
|
| 122 |
+
key_map = {
|
| 123 |
+
-1: 'No Key',
|
| 124 |
+
0: 'C',
|
| 125 |
+
1: 'C#/Db',
|
| 126 |
+
2: 'D',
|
| 127 |
+
3: 'D#/Eb',
|
| 128 |
+
4: 'E',
|
| 129 |
+
5: 'F',
|
| 130 |
+
6: 'F#/Gb',
|
| 131 |
+
7: 'G',
|
| 132 |
+
8: 'G#/Ab',
|
| 133 |
+
9: 'A',
|
| 134 |
+
10: 'A#/Bb',
|
| 135 |
+
11: 'B'
|
| 136 |
+
}
|
| 137 |
+
key = audio_analysis.get('track', {}).get('key', -1)
|
| 138 |
+
return key_map.get(key, 'Unknown')
|
| 139 |
+
|
| 140 |
def obtener_record_label_spotify(album_id, token):
|
| 141 |
url = f'https://api.spotify.com/v1/albums/{album_id}'
|
| 142 |
headers = {'Authorization': f'Bearer {token}'}
|
|
|
|
| 180 |
description="Enter a search query to fetch playlists and their songs from Spotify. Client credentials are pre-configured."
|
| 181 |
)
|
| 182 |
iface.launch()
|
| 183 |
+
|