[json_api] Method for setting skip_count and for setting play_count directly

This commit is contained in:
ejurgensen 2024-10-16 16:42:24 +02:00
parent 8ae25aaf3e
commit 880f5b2bf6
4 changed files with 29 additions and 3 deletions

View File

@ -1622,7 +1622,7 @@ curl -X GET "http://localhost:3689/api/library/tracks/27/playlists"
### Update track properties ### 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** **Endpoint**
@ -1663,7 +1663,8 @@ PUT /api/library/tracks/{id}
| Parameter | Value | | Parameter | Value |
| --------------- | ----------------------------------------------------------- | | --------------- | ----------------------------------------------------------- |
| rating | The new rating (0 - 100) | | 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) | | usermark | The new usermark (>= 0) |
**Response** **Response**

View File

@ -3305,13 +3305,30 @@ jsonapi_reply_library_tracks_put_byid(struct httpd_request *hreq)
{ {
db_file_reset_playskip_count(track_id); 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 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; 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"); param = httpd_query_value_find(hreq->query, "rating");
if (param) if (param)
{ {

View File

@ -692,6 +692,13 @@ item_attrib_save(void *arg, int *retval)
mfi->play_count = param->value; mfi->play_count = param->value;
break; break;
case LIBRARY_ATTRIB_SKIP_COUNT:
if (param->value < 0)
goto error;
mfi->skip_count = param->value;
break;
default: default:
goto error; goto error;
} }

View File

@ -52,6 +52,7 @@ enum library_attrib
LIBRARY_ATTRIB_RATING, LIBRARY_ATTRIB_RATING,
LIBRARY_ATTRIB_USERMARK, LIBRARY_ATTRIB_USERMARK,
LIBRARY_ATTRIB_PLAY_COUNT, LIBRARY_ATTRIB_PLAY_COUNT,
LIBRARY_ATTRIB_SKIP_COUNT,
}; };
/* /*