From 5bd78c6b84b95211e74452a2ab8d8984e9aaca9c Mon Sep 17 00:00:00 2001 From: minus Date: Sun, 27 Oct 2019 16:04:44 +0100 Subject: [PATCH] Allow multiple requests for random requests /api/request/random?q=&num= --- stewdio/app.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stewdio/app.py b/stewdio/app.py index b684be1..0109c22 100644 --- a/stewdio/app.py +++ b/stewdio/app.py @@ -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(): -- 2.45.2