From 0d553243d2b4ec5a8c52f9ae591d9ca0d834ebed Mon Sep 17 00:00:00 2001 From: Leon Bohmann Date: Tue, 30 Nov 2021 17:01:34 +0100 Subject: [PATCH] added switch to not send too much requests --- zspotify/track.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/zspotify/track.py b/zspotify/track.py index faa630b7..b58abbe9 100644 --- a/zspotify/track.py +++ b/zspotify/track.py @@ -43,17 +43,23 @@ def get_song_info(song_id) -> Tuple[List[str], List[str], str, str, Any, Any, An try: artists = [] genres = [] + genreRetrieved = False for data in info[TRACKS][0][ARTISTS]: artists.append(data[NAME]) - # 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: - for genre in artistInfo[GENRES]: - genres.append(genre) - elif len(artistInfo[GENRES]) > 0: - genres.append(artistInfo[GENRES][0]) - else: - genres.append('') + + 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 album_name = info[TRACKS][0][ALBUM][NAME] name = info[TRACKS][0][NAME] image_url = info[TRACKS][0][ALBUM][IMAGES][0][URL]