Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import time
|
|
@@ -121,6 +121,55 @@ def get_track_info(token, track_url):
|
|
| 121 |
return [response.json()]
|
| 122 |
return []
|
| 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 124 |
def get_artist_details(token, artist_id):
|
| 125 |
"""Get artist information including genres."""
|
| 126 |
headers = {'Authorization': f'Bearer {token}'}
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import pandas as pd
|
| 4 |
import time
|
|
|
|
| 121 |
return [response.json()]
|
| 122 |
return []
|
| 123 |
|
| 124 |
+
def get_album_tracks(token, album_url):
|
| 125 |
+
"""Get all tracks from an album URL."""
|
| 126 |
+
album_id = extract_id_from_url(album_url, "album")
|
| 127 |
+
print(f"Extracted album ID: {album_id}")
|
| 128 |
+
|
| 129 |
+
headers = {'Authorization': f'Bearer {token}'}
|
| 130 |
+
tracks_url = f'https://api.spotify.com/v1/albums/{album_id}/tracks'
|
| 131 |
+
|
| 132 |
+
all_tracks = []
|
| 133 |
+
next_url = tracks_url
|
| 134 |
+
|
| 135 |
+
while next_url:
|
| 136 |
+
print(f"Fetching tracks from: {next_url}")
|
| 137 |
+
response = make_request_with_retry(next_url, headers)
|
| 138 |
+
if not response:
|
| 139 |
+
break
|
| 140 |
+
|
| 141 |
+
data = response.json()
|
| 142 |
+
items = data.get('items', [])
|
| 143 |
+
|
| 144 |
+
# Get album details for additional info
|
| 145 |
+
album_info = None
|
| 146 |
+
if len(all_tracks) == 0: # Only need to get album info once
|
| 147 |
+
album_response = make_request_with_retry(f'https://api.spotify.com/v1/albums/{album_id}', headers)
|
| 148 |
+
if album_response:
|
| 149 |
+
album_info = album_response.json()
|
| 150 |
+
|
| 151 |
+
for item in items:
|
| 152 |
+
if item:
|
| 153 |
+
# For album tracks, we need to add some missing information that's in the album
|
| 154 |
+
if album_info:
|
| 155 |
+
item['album'] = {
|
| 156 |
+
'name': album_info.get('name', 'Unknown'),
|
| 157 |
+
'release_date': album_info.get('release_date', 'Not available'),
|
| 158 |
+
'id': album_id
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
all_tracks.append(item)
|
| 162 |
+
|
| 163 |
+
next_url = data.get('next')
|
| 164 |
+
|
| 165 |
+
print(f"Found {len(all_tracks)} tracks in album")
|
| 166 |
+
|
| 167 |
+
# Mark the source
|
| 168 |
+
for track in all_tracks:
|
| 169 |
+
track['playlist_source'] = album_url
|
| 170 |
+
|
| 171 |
+
return all_tracks
|
| 172 |
+
|
| 173 |
def get_artist_details(token, artist_id):
|
| 174 |
"""Get artist information including genres."""
|
| 175 |
headers = {'Authorization': f'Bearer {token}'}
|