From f77161b5c238981ba1dcf4ed963a5be6fdb9f7a4 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Thu, 1 Apr 2021 23:23:18 +0200 Subject: [PATCH] [jsonapi] Get currently playing queue item details (closes #1206) Add now_playing shorthand, so that /api/queue?id=now_playing returns the currently playing queue item info. --- README_JSON_API.md | 2 +- src/httpd_jsonapi.c | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README_JSON_API.md b/README_JSON_API.md index cf4119cf..bc07dadd 100644 --- a/README_JSON_API.md +++ b/README_JSON_API.md @@ -548,7 +548,7 @@ GET /api/queue | Parameter | Value | | --------------- | ----------------------------------------------------------- | -| id | *(Optional)* If a queue item id is given, only the item with the id will be returend. | +| id | *(Optional)* If a queue item id is given, only the item with the id will be returend. Use id=now_playing to get the currently playing item. | | start | *(Optional)* If a `start`and an `end` position is given, only the items from `start` (included) to `end` (excluded) will be returned. If only a `start` position is given, only the item at this position will be returned. | | end | *(Optional)* See `start` parameter | diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index a5232c26..dcd6d088 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -2682,7 +2682,11 @@ jsonapi_reply_queue(struct httpd_request *hreq) query_params.sort = S_SHUFFLE_POS; param = evhttp_find_header(hreq->query, "id"); - if (param && safe_atou32(param, &item_id) == 0) + if (param && strcmp(param, "now_playing") == 0) + { + query_params.filter = db_mprintf("id = %d", status.item_id); + } + else if (param && safe_atou32(param, &item_id) == 0) { query_params.filter = db_mprintf("id = %d", item_id); }