reduce cognitive complexity

This commit is contained in:
Torma Kristóf 2020-11-26 23:50:44 +01:00
parent ecaec93819
commit 19ea61e339

View File

@ -25,30 +25,24 @@ class APIInteractionResource(UserStoreResource):
spotify_uri = "spotify:" spotify_uri = "spotify:"
if mb_type == "artist": if mb_type == "artist":
spot_data = self.spotify.search(q=querystring, type="artist", limit=1)['artists']['items'] spot_data = self.spotify.search(q=querystring, type="artist", limit=1)['artists']['items']
spotify_uri += "artist:" if not spot_data:
if spot_data:
imagedata = spot_data[0]['images']
else:
return None, None, None return None, None, None
spotify_uri += "artist:"
imagedata = spot_data[0]['images']
elif mb_type == "release": elif mb_type == "release":
spot_data = self.spotify.search(q=querystring, type="artist", limit=1).get( spot_data = self.spotify.search(q=querystring, type="artist", limit=1).get(
'albums') 'albums')
if spot_data: if not spot_data:
return None, None, None
spot_data = spot_data['items'] spot_data = spot_data['items']
else:
return None, None, None
spotify_uri += "album:" spotify_uri += "album:"
if spot_data:
imagedata = spot_data[0]['images'] imagedata = spot_data[0]['images']
else:
return None, None, None
elif mb_type == "work" or mb_type == "recording": elif mb_type == "work" or mb_type == "recording":
spot_data = self.spotify.search(q=querystring, type="track", limit=1)['tracks']['items'] spot_data = self.spotify.search(q=querystring, type="track", limit=1)['tracks']['items']
spotify_uri += "track:" if not spot_data:
if spot_data:
imagedata = spot_data[0]['album']['images']
else:
return None, None, None return None, None, None
spotify_uri += "track:"
imagedata = spot_data[0]['album']['images']
else: else:
return None, None, None return None, None, None