[jsonapi] Make updating of currently playing track metadata easier

Update to commit #aaffa4a that makes it easier to update currently playing
track, user can use "now_playing" instead of getting the queue item id.
This commit is contained in:
ejurgensen 2021-01-21 22:46:19 +01:00
parent aaffa4a83f
commit 728d253e1f
3 changed files with 39 additions and 13 deletions

View File

@ -529,8 +529,8 @@ curl -X PUT "http://localhost:3689/api/outputs/0/toggle"
| GET | [/api/queue](#list-queue-items) | Get a list of queue items | | GET | [/api/queue](#list-queue-items) | Get a list of queue items |
| PUT | [/api/queue/clear](#clearing-the-queue) | Remove all items from the queue | | PUT | [/api/queue/clear](#clearing-the-queue) | Remove all items from the queue |
| POST | [/api/queue/items/add](#adding-items-to-the-queue) | Add items to the queue | | POST | [/api/queue/items/add](#adding-items-to-the-queue) | Add items to the queue |
| PUT | [/api/queue/items/{id}](#updating-a-queue-item) | Updating a queue item in the queue | | PUT | [/api/queue/items/{id}|now_playing](#updating-a-queue-item) | Updating a queue item in the queue |
| DELETE | [/api/queue/items/{id}](#removing-a-queue-item) | Remove a queue item form the queue | | DELETE | [/api/queue/items/{id}](#removing-a-queue-item) | Remove a queue item from the queue |
@ -699,6 +699,10 @@ Update or move a queue item in the current queue
```http ```http
PUT /api/queue/items/{id} PUT /api/queue/items/{id}
``` ```
or
```http
PUT /api/queue/items/now_playing
```
**Path parameters** **Path parameters**
@ -706,6 +710,8 @@ PUT /api/queue/items/{id}
| --------------- | -------------------- | | --------------- | -------------------- |
| id | Queue item id | | id | Queue item id |
(or use now_playing to update the currenly playing track)
**Query parameters** **Query parameters**
| Parameter | Value | | Parameter | Value |
@ -733,6 +739,10 @@ curl -X PUT "http://localhost:3689/api/queue/items/3?new_position=0"
curl -X PUT "http://localhost:3689/api/queue/items/3?title=Awesome%20title&artwork_url=http%3A%2F%2Fgyfgafguf.dk%2Fimages%2Fpige3.jpg" curl -X PUT "http://localhost:3689/api/queue/items/3?title=Awesome%20title&artwork_url=http%3A%2F%2Fgyfgafguf.dk%2Fimages%2Fpige3.jpg"
``` ```
```shell
curl -X PUT "http://localhost:3689/api/queue/items/now_playing?title=Awesome%20title&artwork_url=http%3A%2F%2Fgyfgafguf.dk%2Fimages%2Fpige3.jpg"
```
### Removing a queue item ### Removing a queue item
Remove a queue item from the current queue Remove a queue item from the current queue

View File

@ -43,7 +43,8 @@ Metadata:
``` ```
In the above, first fix is the blank name, second is the image artwork. In the above, first fix is the blank name, second is the image artwork.
### 1) Stream Name/Title
### 1) Set stream name/title via the M3U file
Set the name with an EXTINF tag in the m3u playlist file: Set the name with an EXTINF tag in the m3u playlist file:
``` ```
@ -57,7 +58,7 @@ Length is -1 since it's a stream, `<Artist Name>` was left blank since
`StreamTitle` is accurate in the Metadata but `<Artist Title>` was set to `StreamTitle` is accurate in the Metadata but `<Artist Title>` was set to
`My Radio Stream Name` since `icy-name` was blank. `My Radio Stream Name` since `icy-name` was blank.
### 2) Artwork (and track duration) ### 2) StreamUrl is a JSON file with metadata
If `StreamUrl` does not point directly to an artwork file then the link may be If `StreamUrl` does not point directly to an artwork file then the link may be
to a json file that contains an artwork link. If so, you can make forked-daapd to a json file that contains an artwork link. If so, you can make forked-daapd
download the file automatically and search for an artwork link, and also track download the file automatically and search for an artwork link, and also track
@ -91,6 +92,15 @@ curl -X PUT "http://localhost:3689/api/settings/misc/streamurl_keywords_artwork_
If you want multiple search phrases then comma separate, e.g. "duration,length". If you want multiple search phrases then comma separate, e.g. "duration,length".
### 3) Set metadata with a custom script
If your radio station publishes metadata via another method than the above, e.g.
just on their web site, then you will have to write a script that pulls the
metadata and then pushes it to forked-daapd. To update metadata for the
currently playing radio station use something like this JSON API request:
```shell
curl -X PUT "http://localhost:3689/api/queue/items/now_playing?title=Awesome%20title&artwork_url=http%3A%2F%2Fgyfgafguf.dk%2Fimages%2Fpige3.jpg"
```
If your radio station is not returning any artwork links, you can also just make If your radio station is not returning any artwork links, you can also just make
a static artwork by placing a png/jpg in the same directory as the m3u, and with a static artwork by placing a png/jpg in the same directory as the m3u, and with

View File

@ -2533,10 +2533,9 @@ jsonapi_reply_queue_tracks_add(struct httpd_request *hreq)
} }
static int static int
update_pos(uint32_t item_id, const char *new) update_pos(uint32_t item_id, const char *new, char shuffle)
{ {
uint32_t new_position; uint32_t new_position;
struct player_status status;
int ret; int ret;
if (safe_atou32(new, &new_position) < 0) if (safe_atou32(new, &new_position) < 0)
@ -2545,8 +2544,7 @@ update_pos(uint32_t item_id, const char *new)
return HTTP_BADREQUEST; return HTTP_BADREQUEST;
} }
player_get_status(&status); ret = db_queue_move_byitemid(item_id, new_position, shuffle);
ret = db_queue_move_byitemid(item_id, new_position, status.shuffle);
if (ret < 0) if (ret < 0)
{ {
DPRINTF(E_LOG, L_WEB, "Moving item '%d' to new position %d failed\n", item_id, new_position); DPRINTF(E_LOG, L_WEB, "Moving item '%d' to new position %d failed\n", item_id, new_position);
@ -2567,22 +2565,29 @@ static int
jsonapi_reply_queue_tracks_update(struct httpd_request *hreq) jsonapi_reply_queue_tracks_update(struct httpd_request *hreq)
{ {
struct db_queue_item *queue_item; struct db_queue_item *queue_item;
uint32_t item_id; struct player_status status;
uint32_t item_id = 0;
const char *param; const char *param;
bool is_changed; bool is_changed;
int ret; int ret;
ret = safe_atou32(hreq->uri_parsed->path_parts[3], &item_id); player_get_status(&status);
if (ret < 0 || !(queue_item = db_queue_fetch_byitemid(item_id)))
if (strcmp(hreq->uri_parsed->path_parts[3], "now_playing") != 0)
safe_atou32(hreq->uri_parsed->path_parts[3], &item_id);
else
item_id = status.item_id;
if (!item_id || !(queue_item = db_queue_fetch_byitemid(item_id)))
{ {
DPRINTF(E_LOG, L_WEB, "No valid item id given '%s'\n", hreq->uri_parsed->path); DPRINTF(E_LOG, L_WEB, "No valid item id given, or now_playing given but not playing: '%s'\n", hreq->uri_parsed->path);
return HTTP_BADREQUEST; return HTTP_BADREQUEST;
} }
ret = HTTP_OK; ret = HTTP_OK;
is_changed = false; is_changed = false;
if ((param = evhttp_find_header(hreq->query, "new_position"))) if ((param = evhttp_find_header(hreq->query, "new_position")))
ret = update_pos(item_id, param); ret = update_pos(item_id, param, status.shuffle);
if ((param = evhttp_find_header(hreq->query, "title")) && (is_changed = true)) if ((param = evhttp_find_header(hreq->query, "title")) && (is_changed = true))
update_str(&queue_item->title, param); update_str(&queue_item->title, param);
if ((param = evhttp_find_header(hreq->query, "album")) && (is_changed = true)) if ((param = evhttp_find_header(hreq->query, "album")) && (is_changed = true))
@ -4378,6 +4383,7 @@ static struct httpd_uri_map adm_handlers[] =
{ EVHTTP_REQ_PUT, "^/api/queue/clear$", jsonapi_reply_queue_clear }, { EVHTTP_REQ_PUT, "^/api/queue/clear$", jsonapi_reply_queue_clear },
{ EVHTTP_REQ_POST, "^/api/queue/items/add$", jsonapi_reply_queue_tracks_add }, { EVHTTP_REQ_POST, "^/api/queue/items/add$", jsonapi_reply_queue_tracks_add },
{ EVHTTP_REQ_PUT, "^/api/queue/items/[[:digit:]]+$", jsonapi_reply_queue_tracks_update }, { EVHTTP_REQ_PUT, "^/api/queue/items/[[:digit:]]+$", jsonapi_reply_queue_tracks_update },
{ EVHTTP_REQ_PUT, "^/api/queue/items/now_playing$", jsonapi_reply_queue_tracks_update },
{ EVHTTP_REQ_DELETE, "^/api/queue/items/[[:digit:]]+$", jsonapi_reply_queue_tracks_delete }, { EVHTTP_REQ_DELETE, "^/api/queue/items/[[:digit:]]+$", jsonapi_reply_queue_tracks_delete },
{ EVHTTP_REQ_POST, "^/api/queue/save$", jsonapi_reply_queue_save}, { EVHTTP_REQ_POST, "^/api/queue/save$", jsonapi_reply_queue_save},