even more generic
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Torma Kristóf 2020-11-26 23:46:34 +01:00
parent d6780481d3
commit ecaec93819
2 changed files with 10 additions and 9 deletions

View File

@ -4,7 +4,7 @@ Base resource with user handling and Spotify integration
__author__ = '@tormakris'
__copyright__ = "Copyright 2020, onSpot Team"
__module_name__ = "spotifyuserstoreresource"
__module_name__ = "apiinteractionresource"
__version__text__ = "1"
from flask import current_app
@ -22,9 +22,10 @@ class APIInteractionResource(UserStoreResource):
def queryspotifyinfo(self, mb_type: str, title: str = "", artist: str = "", album: str = "") -> tuple:
querystring = f"{artist} {album} {title}"
spotify_uri = "spotify:"
if mb_type == "artist":
spot_data = self.spotify.search(q=querystring, type="artist", limit=1)['artists']['items']
spotify_uri = "spotify:artist:"
spotify_uri += "artist:"
if spot_data:
imagedata = spot_data[0]['images']
else:
@ -36,14 +37,14 @@ class APIInteractionResource(UserStoreResource):
spot_data = spot_data['items']
else:
return None, None, None
spotify_uri = "spotify:album:"
spotify_uri += "album:"
if spot_data:
imagedata = spot_data[0]['images']
else:
return None, None, None
elif mb_type == "work" or mb_type == "recording":
spot_data = self.spotify.search(q=querystring, type="track", limit=1)['tracks']['items']
spotify_uri = "spotify:track:"
spotify_uri += "track:"
if spot_data:
imagedata = spot_data[0]['album']['images']
else:

View File

@ -25,18 +25,18 @@ class ItemApi(APIInteractionResource):
current_app.logger.info(e)
abort(401, "unauthorized")
try:
item_type = flaskred.get(itemid).decode('UTF-8')
itemtype = flaskred.get(itemid).decode('UTF-8')
except Exception as e:
current_app.logger.warning(e)
abort(404, "unknown item")
if item_type == 'release':
if itemtype == 'release':
return self.getreleaseinfo(itemid), 200
elif item_type == 'artist':
elif itemtype == 'artist':
return self.getartistinfo(itemid), 200
elif item_type == 'work':
elif itemtype == 'work':
return self.getworkinfo(itemid), 200
elif item_type == 'recording':
elif itemtype == 'recording':
return self.getrecordinginfo(itemid), 200
else:
abort(417, "wrong type of item")