From 3343e9cfc81049be0eac9bda55362ec975ebadfb Mon Sep 17 00:00:00 2001 From: chme Date: Thu, 14 Feb 2019 08:22:50 +0100 Subject: [PATCH] [jsonapi] Rename queue item "albumartist_id" to "album_artist_id" Keeps it in sync with the naming in the track object. Also introduce a helper function to add an int64 as a json string. --- src/httpd_jsonapi.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/src/httpd_jsonapi.c b/src/httpd_jsonapi.c index 551ba011..d6785036 100644 --- a/src/httpd_jsonapi.c +++ b/src/httpd_jsonapi.c @@ -66,6 +66,20 @@ safe_json_add_string(json_object *obj, const char *key, const char *value) json_object_object_add(obj, key, json_object_new_string(value)); } +static inline void +safe_json_add_string_from_int64(json_object *obj, const char *key, int64_t value) +{ + char tmp[100]; + int ret; + + if (value > 0) + { + ret = snprintf(tmp, sizeof(tmp), "%" PRIi64, value); + if (ret < sizeof(tmp)) + json_object_object_add(obj, key, json_object_new_string(tmp)); + } +} + static inline void safe_json_add_int_from_string(json_object *obj, const char *key, const char *value) { @@ -1649,24 +1663,13 @@ queue_item_to_json(struct db_queue_item *queue_item, char shuffle) safe_json_add_string(item, "artist_sort", queue_item->artist_sort); safe_json_add_string(item, "album", queue_item->album); safe_json_add_string(item, "album_sort", queue_item->album_sort); + safe_json_add_string_from_int64(item, "album_id", queue_item->songalbumid); safe_json_add_string(item, "album_artist", queue_item->album_artist); safe_json_add_string(item, "album_artist_sort", queue_item->album_artist_sort); + safe_json_add_string_from_int64(item, "album_artist_id", queue_item->songartistid); safe_json_add_string(item, "composer", queue_item->composer); safe_json_add_string(item, "genre", queue_item->genre); - if (queue_item->songartistid > 0) - { - ret = snprintf(uri, sizeof(uri), "%" PRIi64, queue_item->songartistid); - if (ret < sizeof(uri)) - json_object_object_add(item, "albumartist_id", json_object_new_string(uri)); - } - if (queue_item->songalbumid > 0) - { - ret = snprintf(uri, sizeof(uri), "%" PRIi64, queue_item->songalbumid); - if (ret < sizeof(uri)) - json_object_object_add(item, "album_id", json_object_new_string(uri)); - } - json_object_object_add(item, "year", json_object_new_int(queue_item->year)); json_object_object_add(item, "track_number", json_object_new_int(queue_item->track)); json_object_object_add(item, "disc_number", json_object_new_int(queue_item->disc));