Skip to content

Commit

Permalink
[json_api] Method for setting skip_count and for setting play_count d…
Browse files Browse the repository at this point in the history
…irectly
  • Loading branch information
ejurgensen committed Oct 16, 2024
1 parent 8ae25aa commit 880f5b2
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
5 changes: 3 additions & 2 deletions docs/json-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**

Expand Down Expand Up @@ -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**
Expand Down
19 changes: 18 additions & 1 deletion src/httpd_jsonapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 7 additions & 0 deletions src/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ enum library_attrib
LIBRARY_ATTRIB_RATING,
LIBRARY_ATTRIB_USERMARK,
LIBRARY_ATTRIB_PLAY_COUNT,
LIBRARY_ATTRIB_SKIP_COUNT,
};

/*
Expand Down

0 comments on commit 880f5b2

Please sign in to comment.