From 880f5b2bf67a06ea95d412629baf868f9a358edf Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Wed, 16 Oct 2024 16:42:24 +0200 Subject: [PATCH] [json_api] Method for setting skip_count and for setting play_count directly --- docs/json-api.md | 5 +++-- src/httpd_jsonapi.c | 19 ++++++++++++++++++- src/library.c | 7 +++++++ src/library.h | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/docs/json-api.md b/docs/json-api.md index 8de4674d29..3a53121233 100644 --- a/docs/json-api.md +++ b/docs/json-api.md @@ -1622,7 +1622,7 @@ curl -X GET "http://localhost:3689/api/library/tracks/27/playlists" ### Update track properties -Change properties of one or more tracks (supported properties are "rating", "play_count" and "usermark") +Change properties of one or more tracks (supported properties are "rating", "play_count", "skip_count" and "usermark") **Endpoint** @@ -1663,7 +1663,8 @@ PUT /api/library/tracks/{id} | Parameter | Value | | --------------- | ----------------------------------------------------------- | | rating | The new rating (0 - 100) | -| play_count | Either `increment` or `reset`. `increment` will increment `play_count` and update `time_played`, `reset` will set `play_count` and `skip_count` to zero and delete `time_played` and `time_skipped` | +| play_count | Either `increment` or `reset` or the new count. `increment` will increment `play_count` and update `time_played`, `reset` will set `play_count` and `skip_count` to zero and delete `time_played` and `time_skipped` | +| skip_count | The new skip count | | usermark | The new usermark (>= 0) | **Response** diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index 09984541d8..edee06d593 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -3305,11 +3305,28 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq) { db_file_reset_playskip_count(track_id); } + else if (safe_atou32(param, &val) == 0) + { + library_item_attrib_save(track_id, LIBRARY_ATTRIB_PLAY_COUNT, val); + } else { - DPRINTF(E_WARN, L_WEB, "Ignoring invalid play_count value '%s' for track '%d'.\n", param, track_id); + DPRINTF(E_WARN, L_WEB, "Invalid play_count value '%s' for track '%d'.\n", param, track_id); + return HTTP_BADREQUEST; + } + } + + param = httpd_query_value_find(hreq->query, "skip_count"); + if (param) + { + ret = safe_atou32(param, &val); + if (ret < 0) + { + DPRINTF(E_WARN, L_WEB, "Invalid skip_count value '%s' for track '%d'.\n", param, track_id); return HTTP_BADREQUEST; } + + library_item_attrib_save(track_id, LIBRARY_ATTRIB_SKIP_COUNT, val); } param = httpd_query_value_find(hreq->query, "rating"); diff --git a/src/library.c b/src/library.c index 4d4f842856..b9d4b32de8 100644 --- a/src/library.c +++ b/src/library.c @@ -692,6 +692,13 @@ item_attrib_save(void *arg, int *retval) mfi->play_count = param->value; break; + case LIBRARY_ATTRIB_SKIP_COUNT: + if (param->value < 0) + goto error; + + mfi->skip_count = param->value; + break; + default: goto error; } diff --git a/src/library.h b/src/library.h index 5201d951c7..82f0b166c6 100644 --- a/src/library.h +++ b/src/library.h @@ -52,6 +52,7 @@ enum library_attrib LIBRARY_ATTRIB_RATING, LIBRARY_ATTRIB_USERMARK, LIBRARY_ATTRIB_PLAY_COUNT, + LIBRARY_ATTRIB_SKIP_COUNT, }; /*