From 89ca5e8ba9cc9db04aa45396970f5ec0facc1688 Mon Sep 17 00:00:00 2001 From: chme Date: Sun, 25 Nov 2018 09:31:29 +0100 Subject: [PATCH] [jsonapi] Fix wrong artwork url for non library queue items and streams Add check against the special file_id DB_MEDIA_FILE_NON_PERSISTENT_ID to identify if a queue item is not in the library. And always prefer the artwork url in the queue item before the artwork for the library file. --- src/httpd_jsonapi.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index ca3eb84b..4a74d439 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -1525,7 +1525,8 @@ queue_item_to_json(struct db_queue_item *queue_item, char shuffle) else json_object_object_add(item, "position", json_object_new_int(queue_item->pos)); - json_object_object_add(item, "track_id", json_object_new_int(queue_item->file_id)); + if (queue_item->file_id > 0 && queue_item->file_id != DB_MEDIA_FILE_NON_PERSISTENT_ID) + json_object_object_add(item, "track_id", json_object_new_int(queue_item->file_id)); safe_json_add_string(item, "title", queue_item->title); safe_json_add_string(item, "artist", queue_item->artist); @@ -1546,21 +1547,27 @@ queue_item_to_json(struct db_queue_item *queue_item, char shuffle) safe_json_add_string(item, "path", queue_item->path); - if (queue_item->file_id > 0) + if (queue_item->file_id > 0 && queue_item->file_id != DB_MEDIA_FILE_NON_PERSISTENT_ID) { ret = snprintf(uri, sizeof(uri), "%s:%s:%d", "library", "track", queue_item->file_id); if (ret < sizeof(uri)) json_object_object_add(item, "uri", json_object_new_string(uri)); - - ret = snprintf(artwork_url, sizeof(artwork_url), "/artwork/item/%d", queue_item->file_id); - if (ret < sizeof(artwork_url)) - json_object_object_add(item, "artwork_url", json_object_new_string(artwork_url)); } else { safe_json_add_string(item, "uri", queue_item->path); + } + + if (queue_item->artwork_url) + { safe_json_add_string(item, "artwork_url", queue_item->artwork_url); } + else if (queue_item->file_id > 0 && queue_item->file_id != DB_MEDIA_FILE_NON_PERSISTENT_ID) + { + ret = snprintf(artwork_url, sizeof(artwork_url), "/artwork/item/%d", queue_item->file_id); + if (ret < sizeof(artwork_url)) + json_object_object_add(item, "artwork_url", json_object_new_string(artwork_url)); + } return item; }