mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-26 12:59:19 -05:00
[spotify] Simplify parsing of artist/album-artist name
forked-daapd does not support a 1:n relationship between tracks and artists. Just take the first artist the spotify web api returns (libspotify does also return only one artist, so this should not introduce a regression).
This commit is contained in:
parent
03c5ecd690
commit
2cfb4b6a28
@ -123,38 +123,21 @@ jparse_time_from_obj(json_object *haystack, const char *key)
|
|||||||
return parsed_time;
|
return parsed_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static const char *
|
||||||
jparse_artist_from_obj(json_object *artists)
|
jparse_str_from_array(json_object *array, int index, const char *key)
|
||||||
{
|
{
|
||||||
char artistnames[1024];
|
json_object *item;
|
||||||
json_object *artist;
|
|
||||||
int count;
|
int count;
|
||||||
int i;
|
|
||||||
const char *tmp;
|
|
||||||
|
|
||||||
count = json_object_array_length(artists);
|
if (json_object_get_type(array) != json_type_array)
|
||||||
if (count == 0)
|
|
||||||
{
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
count = json_object_array_length(array);
|
||||||
{
|
if (count <= 0 || count <= index)
|
||||||
artist = json_object_array_get_idx(artists, i);
|
return NULL;
|
||||||
tmp = jparse_str_from_obj(artist, "name");
|
|
||||||
|
|
||||||
if (i == 0)
|
item = json_object_array_get_idx(array, index);
|
||||||
{
|
return jparse_str_from_obj(item, key);
|
||||||
strcpy(artistnames, tmp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strncat(artistnames, ", ", sizeof(artistnames) - 2);
|
|
||||||
strncat(artistnames, tmp, sizeof(artistnames) - strlen(artistnames));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return strdup(artistnames);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -491,14 +474,14 @@ track_metadata(json_object* jsontrack, struct spotify_track* track)
|
|||||||
if (json_object_object_get_ex(jsontrack, "album", &jsonalbum))
|
if (json_object_object_get_ex(jsontrack, "album", &jsonalbum))
|
||||||
{
|
{
|
||||||
track->album = jparse_str_from_obj(jsonalbum, "name");
|
track->album = jparse_str_from_obj(jsonalbum, "name");
|
||||||
if (json_object_object_get_ex(jsonalbum, "artists", &jsonartists) && json_object_get_type(jsonartists) == json_type_array)
|
if (json_object_object_get_ex(jsonalbum, "artists", &jsonartists))
|
||||||
{
|
{
|
||||||
track->album_artist = jparse_artist_from_obj(jsonartists);
|
track->album_artist = jparse_str_from_array(jsonartists, 0, "name");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (json_object_object_get_ex(jsontrack, "artists", &jsonartists) && json_object_get_type(jsonartists) == json_type_array)
|
if (json_object_object_get_ex(jsontrack, "artists", &jsonartists))
|
||||||
{
|
{
|
||||||
track->artist = jparse_artist_from_obj(jsonartists);
|
track->artist = jparse_str_from_array(jsonartists, 0, "name");
|
||||||
}
|
}
|
||||||
track->disc_number = jparse_int_from_obj(jsontrack, "disc_number");
|
track->disc_number = jparse_int_from_obj(jsontrack, "disc_number");
|
||||||
track->album_type = jparse_str_from_obj(jsonalbum, "album_type");
|
track->album_type = jparse_str_from_obj(jsonalbum, "album_type");
|
||||||
@ -531,9 +514,9 @@ album_metadata(json_object *jsonalbum, struct spotify_album *album)
|
|||||||
{
|
{
|
||||||
json_object* jsonartists;
|
json_object* jsonartists;
|
||||||
|
|
||||||
if (json_object_object_get_ex(jsonalbum, "artists", &jsonartists) && json_object_get_type(jsonartists) == json_type_array)
|
if (json_object_object_get_ex(jsonalbum, "artists", &jsonartists))
|
||||||
{
|
{
|
||||||
album->artist = jparse_artist_from_obj(jsonartists);
|
album->artist = jparse_str_from_array(jsonartists, 0, "name");
|
||||||
}
|
}
|
||||||
album->name = jparse_str_from_obj(jsonalbum, "name");
|
album->name = jparse_str_from_obj(jsonalbum, "name");
|
||||||
album->uri = jparse_str_from_obj(jsonalbum, "uri");
|
album->uri = jparse_str_from_obj(jsonalbum, "uri");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user