51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
"""
|
|
Endpoinds manipulating all lists
|
|
"""
|
|
|
|
__author__ = '@tormakris'
|
|
__copyright__ = "Copyright 2020, onSpot Team"
|
|
__module_name__ = "listsapi"
|
|
__version__text__ = "1"
|
|
|
|
import musicbrainzngs
|
|
from flask import current_app, abort, request
|
|
|
|
from flaskaddons.fred import flaskred
|
|
from resources.userstoreresource import UserStoreResource
|
|
|
|
|
|
class ListsApi(UserStoreResource):
|
|
"""
|
|
See: https://swagger.kmlabz.com/?urls.primaryName=onSpot%20Backend#/backend/getAllLists
|
|
"""
|
|
|
|
def get(self):
|
|
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")
|
|
|
|
musicbrainzngs.auth(currcreds['name'], currcreds['password'])
|
|
collections = musicbrainzngs.get_collections()
|
|
musicbrainzngs.auth(None, None)
|
|
elementlist = []
|
|
for collection in collections['collection-list']:
|
|
if collection['entity-type'] == 'release':
|
|
count = collection['release-count']
|
|
elif collection['entity-type'] == 'artist':
|
|
count = collection['artist-count']
|
|
elif collection['entity-type'] == 'work':
|
|
count = collection['work-count']
|
|
elif collection['entity-type'] == 'recording':
|
|
count = collection['recording-count']
|
|
else:
|
|
continue
|
|
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'],
|
|
"ids": elementlist}
|
|
|
|
return returndict, 200
|