From 49171dac1aedca00f9abb7493e1b2ee42f565327 Mon Sep 17 00:00:00 2001 From: ejurgensen Date: Sat, 25 Oct 2025 23:32:09 +0200 Subject: [PATCH] [artwork] Rename to artwork_get_by_file_id and artwork_get_by_group_id For consistency with new artwork_get_by_queue_item_id --- src/artwork.c | 12 ++++++------ src/artwork.h | 6 +++--- src/httpd_artworkapi.c | 12 ++++++------ src/httpd_daap.c | 4 ++-- src/mpd.c | 20 ++++++-------------- 5 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/artwork.c b/src/artwork.c index 92827dcf..eec229f0 100644 --- a/src/artwork.c +++ b/src/artwork.c @@ -1897,7 +1897,7 @@ source_queue_item_artwork_url_get(struct artwork_ctx *ctx) /* --------------------------- SOURCE PROCESSING --------------------------- */ static int -process_items(struct artwork_ctx *ctx, int item_mode) +process_file_items(struct artwork_ctx *ctx, int item_mode) { struct db_media_file_info dbmfi; int i; @@ -2041,7 +2041,7 @@ process_group(struct artwork_ctx *ctx) } invalid_group: - return process_items(ctx, 0); + return process_file_items(ctx, 0); } static int @@ -2087,7 +2087,7 @@ process_queue_item(struct artwork_ctx *ctx) /* ------------------------------ ARTWORK API ------------------------------ */ int -artwork_get_item(struct evbuffer *evbuf, int id, int max_w, int max_h, int format) +artwork_get_by_file_id(struct evbuffer *evbuf, int id, int max_w, int max_h, int format) { struct artwork_ctx ctx = { 0 }; char filter[32]; @@ -2116,7 +2116,7 @@ artwork_get_item(struct evbuffer *evbuf, int id, int max_w, int max_h, int forma // Note: process_items will set ctx.persistentid for the following process_group() // - and do nothing else if artwork_individual is not configured by user - ret = process_items(&ctx, 1); + ret = process_file_items(&ctx, 1); if (ret > 0) { if (ctx.cache & ON_SUCCESS) @@ -2146,7 +2146,7 @@ artwork_get_item(struct evbuffer *evbuf, int id, int max_w, int max_h, int forma } int -artwork_get_group(struct evbuffer *evbuf, int id, int max_w, int max_h, int format) +artwork_get_by_group_id(struct evbuffer *evbuf, int id, int max_w, int max_h, int format) { struct artwork_ctx ctx = { 0 }; int ret; @@ -2202,7 +2202,7 @@ artwork_get_by_queue_item_id(struct evbuffer *evbuf, int item_id, int max_w, int if (queue_item->file_id != DB_MEDIA_FILE_NON_PERSISTENT_ID) { - ret = artwork_get_item(evbuf, queue_item->file_id, max_w, max_h, format); + ret = artwork_get_by_file_id(evbuf, queue_item->file_id, max_w, max_h, format); free_queue_item(queue_item, 0); return ret; } diff --git a/src/artwork.h b/src/artwork.h index 0dfc6efd..5c7b8b00 100644 --- a/src/artwork.h +++ b/src/artwork.h @@ -13,7 +13,7 @@ #include /* - * Get the artwork image for an individual item (track) + * Get the artwork image for an individual library item (track) * * @out evbuf Event buffer that will contain the (scaled) image * @in id The mfi item id @@ -23,7 +23,7 @@ * @return ART_FMT_* on success, -1 on error or no artwork found */ int -artwork_get_item(struct evbuffer *evbuf, int id, int max_w, int max_h, int format); +artwork_get_by_file_id(struct evbuffer *evbuf, int id, int max_w, int max_h, int format); /* * Get the artwork image for a group (an album or an artist) @@ -36,7 +36,7 @@ artwork_get_item(struct evbuffer *evbuf, int id, int max_w, int max_h, int forma * @return ART_FMT_* on success, -1 on error or no artwork found */ int -artwork_get_group(struct evbuffer *evbuf, int id, int max_w, int max_h, int format); +artwork_get_by_group_id(struct evbuffer *evbuf, int id, int max_w, int max_h, int format); /* * Get the artwork image for a queue item. If the queue item is in the library, diff --git a/src/httpd_artworkapi.c b/src/httpd_artworkapi.c index 5858336d..f7b0f5de 100644 --- a/src/httpd_artworkapi.c +++ b/src/httpd_artworkapi.c @@ -74,20 +74,20 @@ response_process(struct httpd_request *hreq, int format) static int artworkapi_reply_nowplaying(struct httpd_request *hreq) { + struct player_status status; uint32_t max_w; uint32_t max_h; - uint32_t id; int ret; ret = request_process(hreq, &max_w, &max_h); if (ret != 0) return ret; - ret = player_playing_now(&id); - if (ret != 0) + player_get_status(&status); + if (status.status == PLAY_STOPPED) return HTTP_NOTFOUND; - ret = artwork_get_item(hreq->out_body, id, max_w, max_h, 0); + ret = artwork_get_by_queue_item_id(hreq->out_body, status.item_id, max_w, max_h, 0); return response_process(hreq, ret); } @@ -108,7 +108,7 @@ artworkapi_reply_item(struct httpd_request *hreq) if (ret != 0) return HTTP_BADREQUEST; - ret = artwork_get_item(hreq->out_body, id, max_w, max_h, 0); + ret = artwork_get_by_file_id(hreq->out_body, id, max_w, max_h, 0); return response_process(hreq, ret); } @@ -129,7 +129,7 @@ artworkapi_reply_group(struct httpd_request *hreq) if (ret != 0) return HTTP_BADREQUEST; - ret = artwork_get_group(hreq->out_body, id, max_w, max_h, 0); + ret = artwork_get_by_group_id(hreq->out_body, id, max_w, max_h, 0); return response_process(hreq, ret); } diff --git a/src/httpd_daap.c b/src/httpd_daap.c index 7a141f2a..4510a61f 100644 --- a/src/httpd_daap.c +++ b/src/httpd_daap.c @@ -1986,9 +1986,9 @@ daap_reply_extra_data(struct httpd_request *hreq) } if (strcmp(hreq->path_parts[2], "groups") == 0) - ret = artwork_get_group(hreq->out_body, id, max_w, max_h, 0); + ret = artwork_get_by_group_id(hreq->out_body, id, max_w, max_h, 0); else if (strcmp(hreq->path_parts[2], "items") == 0) - ret = artwork_get_item(hreq->out_body, id, max_w, max_h, 0); + ret = artwork_get_by_file_id(hreq->out_body, id, max_w, max_h, 0); len = evbuffer_get_length(hreq->out_body); diff --git a/src/mpd.c b/src/mpd.c index 57de138d..bd0f6a92 100644 --- a/src/mpd.c +++ b/src/mpd.c @@ -2391,7 +2391,7 @@ mpd_command_albumart(struct mpd_command_output *out, struct mpd_command_input *i // Ref. docs: "If the song file was recognized, but there is no picture, the // response is successful, but is otherwise empty" - format = artwork_get_item(artwork, id, ART_DEFAULT_WIDTH, ART_DEFAULT_HEIGHT, 0); + format = artwork_get_by_file_id(artwork, id, ART_DEFAULT_WIDTH, ART_DEFAULT_HEIGHT, 0); if (format == ART_FMT_PNG) evbuffer_add_printf(out->evbuf, "type: image/png\n"); else if (format == ART_FMT_JPEG) @@ -4150,7 +4150,7 @@ artwork_cb(struct evhttp_request *req, void *arg) const char *path; char *decoded_path; char *last_slash; - int itemid; + int file_id; int format; if (evhttp_request_get_command(req) != EVHTTP_REQ_GET) @@ -4195,8 +4195,8 @@ 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_byvirtualpath_match(decoded_path); - if (!itemid) + file_id = db_file_id_byvirtualpath_match(decoded_path); + if (!file_id) { DPRINTF(E_WARN, L_MPD, "No item found for path '%s' from request uri '%s'\n", decoded_path, uri); evhttp_send_error(req, HTTP_NOTFOUND, "Document was not found"); @@ -4205,17 +4205,9 @@ artwork_cb(struct evhttp_request *req, void *arg) return; } - evbuffer = evbuffer_new(); - if (!evbuffer) - { - DPRINTF(E_LOG, L_MPD, "Could not allocate an evbuffer for artwork request\n"); - evhttp_send_error(req, HTTP_INTERNAL, "Document was not found"); - evhttp_uri_free(decoded); - free(decoded_path); - return; - } + CHECK_NULL(L_MPD, evbuffer = evbuffer_new()); - format = artwork_get_item(evbuffer, itemid, ART_DEFAULT_WIDTH, ART_DEFAULT_HEIGHT, 0); + format = artwork_get_by_file_id(evbuffer, file_id, ART_DEFAULT_WIDTH, ART_DEFAULT_HEIGHT, 0); if (format < 0) { evhttp_send_error(req, HTTP_NOTFOUND, "Document was not found");