[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.
This commit is contained in:
chme 2018-11-25 09:31:29 +01:00
parent a8d3a045f2
commit 89ca5e8ba9

View File

@ -1525,6 +1525,7 @@ 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));
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);
@ -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;
}