From 097e25eecc22e77be12f97d00ff5bb98e6595c77 Mon Sep 17 00:00:00 2001 From: krishsharma0413 Date: Sat, 30 Dec 2023 19:09:52 +0530 Subject: [PATCH] check for analysis error for local files --- spotify_dl/spotify.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/spotify_dl/spotify.py b/spotify_dl/spotify.py index 04a15c8..448d5e4 100644 --- a/spotify_dl/spotify.py +++ b/spotify_dl/spotify.py @@ -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")] ) @@ -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, @@ -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: