From 702ec22094e6707c508073e6788491f5e7fb020c Mon Sep 17 00:00:00 2001 From: Leon Bohmann Date: Tue, 30 Nov 2021 20:20:06 +0100 Subject: [PATCH] updated exception handling --- zspotify/track.py | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/zspotify/track.py b/zspotify/track.py index b58abbe..1deed40 100644 --- a/zspotify/track.py +++ b/zspotify/track.py @@ -1,5 +1,6 @@ import os import re +from threading import Thread import time import uuid from typing import Any, Tuple, List @@ -46,20 +47,24 @@ def get_song_info(song_id) -> Tuple[List[str], List[str], str, str, Any, Any, An genreRetrieved = False for data in info[TRACKS][0][ARTISTS]: artists.append(data[NAME]) - - if not genreRetrieved: - # query artist genres via href, which will be the api url - (raw, artistInfo) = ZSpotify.invoke_url(f'{data["href"]}') - if ZSpotify.CONFIG.get_allGenres() and len(artistInfo[GENRES]) > 0: - genreRetrieved = False - for genre in artistInfo[GENRES]: - genres.append(genre) - elif len(artistInfo[GENRES]) > 0: - genres.append(artistInfo[GENRES][0]) - genreRetrieved = True - else: + try: + if not genreRetrieved: + # query artist genres via href, which will be the api url + (raw, artistInfo) = ZSpotify.invoke_url(f'{data["href"]}') + if ZSpotify.CONFIG.get_allGenres() and len(artistInfo[GENRES]) > 0: + genreRetrieved = False + for genre in artistInfo[GENRES]: + genres.append(genre) + elif len(artistInfo[GENRES]) > 0: + genres.append(artistInfo[GENRES][0]) + genreRetrieved = True + else: + genres.append('') + genreRetrieved = True + except Exception as genreError: + if len(genres) == 0: genres.append('') - genreRetrieved = True + album_name = info[TRACKS][0][ALBUM][NAME] name = info[TRACKS][0][NAME] image_url = info[TRACKS][0][ALBUM][IMAGES][0][URL]