~minus/stewdio-api

5bd78c6b84b95211e74452a2ab8d8984e9aaca9c — minus 4 years ago cf33f90
Allow multiple requests for random requests

/api/request/random?q=<terms>&num=<number of songs>
1 files changed, 4 insertions(+), 2 deletions(-)

M stewdio/app.py
M stewdio/app.py => stewdio/app.py +4 -2
@@ 88,14 88,16 @@ def request(hash, session):
@with_pg_cursor
@json_api
def request_random(cur):
	num = int(flask.request.args.get("num", "1"))
	terms = flask.request.args["q"]
	with db_session() as session:
		context = get_np_context(session)
	songs = search_internal(cur, context, terms)
	if not songs:
		return flask.Response(status=404)
	song = random.choice(songs)
	return queue_song(song)
	num = min(num, len(songs))
	songs = random.sample(songs, num)
	return [queue_song(song) for song in songs]

@app.route("/api/skip")
def skip():