[scan/library] Media rating sync (#1681)

Automatically read/write ratings to files in the library, if options read_rating/
write_rating are enabled. Also adds a max_rating so the user can set the rating
scale.

Doesn't sync automatic rating updates, because that could lead to whole-playlist
file rewriting.

Closes #1678 

---------

Co-authored-by: whatdoineed2do/Ray <whatdoineed2do@nospam.gmail.com>
Co-authored-by: ejurgensen <espenjurgensen@gmail.com>
This commit is contained in:
whatdoineed2do
2024-01-24 22:30:02 +00:00
committed by GitHub
parent 9491a3b980
commit 2dc448fa30
12 changed files with 648 additions and 169 deletions

View File

@@ -3269,7 +3269,8 @@ static int
mpd_sticker_set(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, const char *virtual_path)
{
uint32_t rating;
int ret = 0;
int id;
int ret;
if (strcmp(argv[4], "rating") != 0)
{
@@ -3291,20 +3292,22 @@ mpd_sticker_set(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, co
return ACK_ERROR_ARG;
}
ret = db_file_rating_update_byvirtualpath(virtual_path, rating);
if (ret <= 0)
id = db_file_id_byvirtualpath(virtual_path);
if (id <= 0)
{
*errmsg = safe_asprintf("Invalid path '%s'", virtual_path);
return ACK_ERROR_ARG;
}
library_item_attrib_save(id, LIBRARY_ATTRIB_RATING, rating);
return 0;
}
static int
mpd_sticker_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg, const char *virtual_path)
{
int ret = 0;
int id;
if (strcmp(argv[4], "rating") != 0)
{
@@ -3312,12 +3315,15 @@ mpd_sticker_delete(struct evbuffer *evbuf, int argc, char **argv, char **errmsg,
return ACK_ERROR_NO_EXIST;
}
ret = db_file_rating_update_byvirtualpath(virtual_path, 0);
if (ret <= 0)
id = db_file_id_byvirtualpath(virtual_path);
if (id <= 0)
{
*errmsg = safe_asprintf("Invalid path '%s'", virtual_path);
return ACK_ERROR_ARG;
}
library_item_attrib_save(id, LIBRARY_ATTRIB_RATING, 0);
return 0;
}
@@ -4714,7 +4720,7 @@ artwork_cb(struct evhttp_request *req, void *arg)
DPRINTF(E_DBG, L_MPD, "Artwork request for path: %s\n", decoded_path);
itemid = db_file_id_by_virtualpath_match(decoded_path);
itemid = db_file_id_byvirtualpath_match(decoded_path);
if (!itemid)
{
DPRINTF(E_WARN, L_MPD, "No item found for path '%s' from request uri '%s'\n", decoded_path, uri);