From 19ea61e3395d1b76100c91210f8b82784abcf990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torma=20Krist=C3=B3f?= Date: Thu, 26 Nov 2020 23:50:44 +0100 Subject: [PATCH] reduce cognitive complexity --- src/resources/apiinteractionresource.py | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/resources/apiinteractionresource.py b/src/resources/apiinteractionresource.py index d95c3cb..9bb0e9d 100644 --- a/src/resources/apiinteractionresource.py +++ b/src/resources/apiinteractionresource.py @@ -25,30 +25,24 @@ class APIInteractionResource(UserStoreResource): spotify_uri = "spotify:" if mb_type == "artist": spot_data = self.spotify.search(q=querystring, type="artist", limit=1)['artists']['items'] - spotify_uri += "artist:" - if spot_data: - imagedata = spot_data[0]['images'] - else: + if not spot_data: return None, None, None + spotify_uri += "artist:" + imagedata = spot_data[0]['images'] elif mb_type == "release": spot_data = self.spotify.search(q=querystring, type="artist", limit=1).get( 'albums') - if spot_data: - spot_data = spot_data['items'] - else: + if not spot_data: return None, None, None + spot_data = spot_data['items'] spotify_uri += "album:" - if spot_data: - imagedata = spot_data[0]['images'] - else: - return None, None, None + imagedata = spot_data[0]['images'] elif mb_type == "work" or mb_type == "recording": spot_data = self.spotify.search(q=querystring, type="track", limit=1)['tracks']['items'] - spotify_uri += "track:" - if spot_data: - imagedata = spot_data[0]['album']['images'] - else: + if not spot_data: return None, None, None + spotify_uri += "track:" + imagedata = spot_data[0]['album']['images'] else: return None, None, None