Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -411,25 +411,27 @@ def get_song_link_info(url: str):
|
|
411 |
# Make the API call
|
412 |
response = requests.get(api_url)
|
413 |
if response.status_code == 200:
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
|
|
421 |
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
|
|
429 |
else:
|
430 |
-
return
|
431 |
-
|
432 |
-
|
433 |
else:
|
434 |
return None
|
435 |
|
|
|
411 |
# Make the API call
|
412 |
response = requests.get(api_url)
|
413 |
if response.status_code == 200:
|
414 |
+
try:
|
415 |
+
track_info = response.json()
|
416 |
+
if not track_info:
|
417 |
+
raise HTTPException(status_code=404, detail="Could not fetch track info")
|
418 |
+
entityUniqueId = track_info["entityUniqueId"]
|
419 |
+
title = track_info["entitiesByUniqueId"][entityUniqueId]["title"]
|
420 |
+
artist = track_info["entitiesByUniqueId"][entityUniqueId]["artistName"]
|
421 |
+
filename = f"{title} - {artist}"
|
422 |
|
423 |
+
#extract YouTube URL
|
424 |
+
youtube_url = extract_url(track_info["linksByPlatform"], "youtube")
|
425 |
+
if youtube_url:
|
426 |
+
if title and artist:
|
427 |
+
filename = f"{title} - {artist}"
|
428 |
+
return {"url": youtube_url, "filename": filename}
|
429 |
+
else:
|
430 |
+
return {"url": youtube_url, "filename": "Unknown Track - Unknown Artist"}
|
431 |
else:
|
432 |
+
return None
|
433 |
+
except ValueError:
|
434 |
+
raise HTTPException(status_code=500, detail="Error parsing API response as JSON")
|
435 |
else:
|
436 |
return None
|
437 |
|