This commit is contained in:
parent
95be4734a8
commit
3233741ab1
@ -109,12 +109,11 @@ class ListsApi(Resource):
|
|||||||
count = collection['work-count']
|
count = collection['work-count']
|
||||||
elif collection['entity-type'] == 'recording':
|
elif collection['entity-type'] == 'recording':
|
||||||
count = collection['recording-count']
|
count = collection['recording-count']
|
||||||
elif collection['entity-type'] == 'release_group':
|
|
||||||
elementlist.append({"id": collection['id'], "name": collection['name']})
|
|
||||||
continue
|
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
elementlist.append({"id": collection['id'], "name": collection['name'], "element_count": count})
|
flaskred.set(collection['id'], collection['entity-type'].encode('UTF-8'))
|
||||||
|
elementlist.append({"id": collection['id'], "name": collection['name'], "element_count": count,
|
||||||
|
"type": collection['entity-type']})
|
||||||
returndict = {"count": collections['collection-count'],
|
returndict = {"count": collections['collection-count'],
|
||||||
"ids": elementlist}
|
"ids": elementlist}
|
||||||
|
|
||||||
@ -125,9 +124,69 @@ class SingleListApi(Resource):
|
|||||||
"""
|
"""
|
||||||
See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getList
|
See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getList
|
||||||
"""
|
"""
|
||||||
|
encryptor = EncryptedUserRedis(ENCODED_SECRET_KEY)
|
||||||
|
|
||||||
def get(self, listid: str):
|
def get(self, listid: str):
|
||||||
pass
|
try:
|
||||||
|
currcreds = self.encryptor.load(flaskred.get(request.headers.get('Authorization')).decode('UTF-8'))
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.warning(e)
|
||||||
|
abort(401, "unauthorized")
|
||||||
|
try:
|
||||||
|
list_type = flaskred.get(listid).decode('UTF-8')
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.warning(e)
|
||||||
|
abort(404, "unknown list")
|
||||||
|
musicbrainzngs.auth(currcreds['name'], currcreds['password'])
|
||||||
|
limit = int(request.args.get('limit', 10))
|
||||||
|
offset = int(request.args.get('offset', 0))
|
||||||
|
if list_type == 'release':
|
||||||
|
currdata = musicbrainzngs.get_releases_in_collection(listid, limit, offset)['collection']
|
||||||
|
releaselist = []
|
||||||
|
for release in currdata['release-list']:
|
||||||
|
releasedata = {"id": release['id'], "album": release['title']}
|
||||||
|
currlease = musicbrainzngs.get_release_by_id(release['id'], includes=['artists'])
|
||||||
|
if 'artist-credit' in currlease['release'] and currlease['release']['artist-credit']:
|
||||||
|
currartist = currlease['release']['artist-credit'][0]['artist']
|
||||||
|
releasedata['artist'] = currartist['name']
|
||||||
|
releaselist.append(releasedata)
|
||||||
|
flaskred.set(release['id'], 'release'.encode('UTF-8'))
|
||||||
|
retdata = {"id": currdata['id'], "element_count": currdata['release-count'], "itemlist": releaselist}
|
||||||
|
elif list_type == 'artist':
|
||||||
|
currdata = musicbrainzngs.get_artists_in_collection(listid, limit, offset)['collection']
|
||||||
|
artistlist = []
|
||||||
|
for artist in currdata['artist-list']:
|
||||||
|
artistlist.append({"id": artist['id'], "name": artist['name']})
|
||||||
|
flaskred.set(artist['id'], 'artist'.encode('UTF-8'))
|
||||||
|
retdata = {"id": currdata['id'], "element_count": currdata['artist-count'], "itemlist": artistlist}
|
||||||
|
elif list_type == 'work':
|
||||||
|
currdata = musicbrainzngs.get_works_in_collection(listid, limit, offset)['collection']
|
||||||
|
worklist = []
|
||||||
|
for work in currdata['work-list']:
|
||||||
|
worklist.append({"id": work['id'], "title": work['title']})
|
||||||
|
flaskred.set(work['id'], 'recording'.encode('UTF-8'))
|
||||||
|
retdata = {"id": currdata['id'], "element_count": currdata['work-count'], "itemlist": worklist}
|
||||||
|
elif list_type == 'recording':
|
||||||
|
currdata = musicbrainzngs.get_recordings_in_collection(listid, limit, offset)['collection']
|
||||||
|
recordinglist = []
|
||||||
|
for recording in currdata['recording-list']:
|
||||||
|
currrec = {"id": recording['id'], "title": recording['title']}
|
||||||
|
currrecording = musicbrainzngs.get_recording_by_id(recording['id'], includes=['artists', 'releases'])
|
||||||
|
if 'artist-credit' in currrecording['recording'] and currrecording['recording']['artist-credit']:
|
||||||
|
currartist = currrecording['recording']['artist-credit'][0]['artist']
|
||||||
|
currrec['artist'] = currartist['name']
|
||||||
|
if 'release-list' in currrecording['recording'] and currrecording['recording']['release-list']:
|
||||||
|
currrlease = currrecording['recording']['release-list'][0]
|
||||||
|
currrec['album'] = currrlease['title']
|
||||||
|
recordinglist.append(currrec)
|
||||||
|
flaskred.set(recording['id'], 'recording'.encode('UTF-8'))
|
||||||
|
retdata = {"id": currdata['id'], "element_count": currdata['recording-count'], "itemlist": recordinglist}
|
||||||
|
else:
|
||||||
|
abort(417, "wrong type of collection")
|
||||||
|
musicbrainzngs.auth(None, None)
|
||||||
|
retdata['type'] = list_type
|
||||||
|
|
||||||
|
return retdata, 200
|
||||||
|
|
||||||
|
|
||||||
class TrackApi(Resource):
|
class TrackApi(Resource):
|
||||||
|
@ -22,28 +22,3 @@ class UserSchema(ma.Schema):
|
|||||||
|
|
||||||
name = fields.String(required=True)
|
name = fields.String(required=True)
|
||||||
password = fields.String(required=True)
|
password = fields.String(required=True)
|
||||||
|
|
||||||
|
|
||||||
class TrackSchema(ma.Schema):
|
|
||||||
"""
|
|
||||||
Parameters:
|
|
||||||
- id (integer)
|
|
||||||
- title (string)
|
|
||||||
- artist (string)
|
|
||||||
- album (string)
|
|
||||||
- spotify_id (string)
|
|
||||||
- cover_url (string)
|
|
||||||
"""
|
|
||||||
|
|
||||||
id = fields.Integer(required=True)
|
|
||||||
title = fields.String(required=True)
|
|
||||||
artist = fields.String(required=True)
|
|
||||||
album = fields.String(required=True)
|
|
||||||
spotify_id = fields.String(required=True)
|
|
||||||
cover_url = fields.String(required=True)
|
|
||||||
|
|
||||||
|
|
||||||
class ListSchema(ma.Schema):
|
|
||||||
|
|
||||||
id = fields.Integer(required=True)
|
|
||||||
tracklist = fields.Nested(TrackSchema, many=True)
|
|
||||||
|
Loading…
Reference in New Issue
Block a user