Skip to content

Commit

Permalink
check for analysis error for local files
Browse files Browse the repository at this point in the history
  • Loading branch information
krishsharma0413 committed Dec 30, 2023
1 parent 35429d4 commit 097e25e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions spotify_dl/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ def fetch_tracks(sp, item_type, item_id):
continue
track_album_info = track_info.get("album")
track_num = track_info.get("track_number")
spotify_id = track_info.get("id")
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
track_name = track_info.get("name")
spotify_id = track_info.get("id")
try:
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
except:
log.error("Couldn't fetch audio analysis for %s", track_name)
tempo = None
track_artist = ", ".join(
[artist["name"] for artist in track_info.get("artists")]
)
Expand Down Expand Up @@ -144,8 +148,12 @@ def fetch_tracks(sp, item_type, item_id):
)
track_num = item["track_number"]
spotify_id = item.get("id")
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
try:
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
except:
log.error("Couldn't fetch audio analysis for %s", track_name)
tempo = None
songs_list.append(
{
"name": track_name,
Expand Down Expand Up @@ -188,8 +196,12 @@ def fetch_tracks(sp, item_type, item_id):
album_total = album_info.get("total_tracks")
track_num = items["track_number"]
spotify_id = items["id"]
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
try:
track_audio_data = sp.audio_analysis(spotify_id)
tempo = track_audio_data.get("track").get("tempo")
except:
log.error("Couldn't fetch audio analysis for %s", track_name)
tempo = None
if len(items["album"]["images"]) > 0:
cover = items["album"]["images"][0]["url"]
else:
Expand Down

0 comments on commit 097e25e

Please sign in to comment.