Skip to content

Commit

Permalink
feat(api): handle missing song name in tidal results
Browse files Browse the repository at this point in the history
  • Loading branch information
felipetodev committed Sep 16, 2024
1 parent 3b717a4 commit 5cc4b41
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,15 @@ def get_from_tidal(query, song_name):
result = response.json()

track_url = None
for track in result['included']:
if track['attributes']['title'] == song_name:
track_url = track['attributes']['externalLinks'][0]['href']
track_url = f"https://listen.tidal.com/track/{track_url.split('/')[-1]}"
break
return track_url
try:
for track in result['included']:
if track['attributes']['title'] == song_name:
track_url = track['attributes']['externalLinks'][0]['href']
track_url = f"https://listen.tidal.com/track/{track_url.split('/')[-1]}"
break
return track_url
except KeyError:
return None

@app.route('/')
def home():
Expand Down

0 comments on commit 5cc4b41

Please sign in to comment.