2019-10-10 11:58:17 +01:00
|
|
|
from flask import Blueprint, request, jsonify
|
|
|
|
import logging
|
|
|
|
|
2022-08-16 18:00:38 +01:00
|
|
|
from music.api.decorators import login_or_jwt, spotify_link_required, no_locked_users
|
2019-10-19 17:14:11 +01:00
|
|
|
import music.db.database as database
|
2019-10-10 11:58:17 +01:00
|
|
|
|
|
|
|
from spotframework.engine.playlistengine import PlaylistEngine
|
|
|
|
from spotframework.model.uri import Uri
|
|
|
|
|
|
|
|
blueprint = Blueprint('spotify_api', __name__)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@blueprint.route('/sort', methods=['POST'])
|
2022-08-08 22:02:14 +01:00
|
|
|
@login_or_jwt
|
2019-10-10 11:58:17 +01:00
|
|
|
@spotify_link_required
|
2022-08-16 18:00:38 +01:00
|
|
|
@no_locked_users
|
2022-08-08 22:02:14 +01:00
|
|
|
def sort(auth=None, user=None):
|
2019-10-10 11:58:17 +01:00
|
|
|
request_json = request.get_json()
|
|
|
|
|
2020-04-30 14:54:05 +01:00
|
|
|
net = database.get_authed_spotify_network(user)
|
2019-10-10 11:58:17 +01:00
|
|
|
engine = PlaylistEngine(net)
|
|
|
|
|
|
|
|
reverse = request_json.get('reverse', False)
|
|
|
|
|
|
|
|
if 'uri' in request_json:
|
|
|
|
try:
|
|
|
|
uri = Uri(request_json['uri'])
|
|
|
|
engine.reorder_playlist_by_added_date(uri=uri, reverse=reverse)
|
|
|
|
except ValueError:
|
|
|
|
return jsonify({'error': "malformed uri provided"}), 400
|
|
|
|
elif 'playlist_name' in request_json:
|
|
|
|
engine.reorder_playlist_by_added_date(name=request_json.get('playlist_name'), reverse=reverse)
|
|
|
|
else:
|
|
|
|
return jsonify({'error': "no uris provided"}), 400
|
|
|
|
|
|
|
|
return jsonify({'message': 'sorted', 'status': 'success'}), 200
|