Chrunos commited on
Commit
610a040
·
verified ·
1 Parent(s): e6f6974

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
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
- track_info = response
415
- if not track_info:
416
- raise HTTPException(status_code=404, detail="Could not fetch track info")
417
- entityUniqueId = track_info["entityUniqueId"]
418
- title = track_info["entitiesByUniqueId"][entityUniqueId]["title"]
419
- artist = track_info["entitiesByUniqueId"][entityUniqueId]["artistName"]
420
- filename = f"{title} - {artist}"
 
421
 
422
- #extract YouTube URL
423
- youtube_url = extract_url(track_info["linksByPlatform"], "youtube")
424
- if youtube_url:
425
-
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
  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