A random query like
https://api.soundcloud.com/tracks.json?genre=Rnbhiphop
gives something like
[
{
"kind":"track",
"id":161532719,
(...)
"artwork_url":null,
(...)
},
{
"kind":"track",
"id":161532718,
(...)
"artwork_url":null,
(...)
},
(..)
]
In many, many cases, artwork_url is null, although this is not consistent.
However, when looking at the single track id 161532719 (first in list above) with
http://api.soundcloud.com/tracks/161532719.json
we get
{
"kind":"track",
"id":161532719,
(...)
"artwork_url":"http://i1.sndcdn.com/artworks-000087026689-ogd56p-large.jpg?e76cf77",
(...)
}
... which strangely enough reveals that track 161532719 HAS a valid artwork_url. The same is the case with many other tracks.
Is this a bug, or am I doing something wrong here?
It looks like the collection endpoint (in this case genre), has a backend bug where the artwork is not fetched.
null
is not the same as undefined, rather it is intentionally set. If you encounter a null value, you can use data gathered from the single track endpoint, aggregate it to the tracks data from there.
If you choose to do this, I recommend firing the request for tracks endpoint the second you have the id you need, and updating using the id.
If the uploader of the track didn't attach an image to it, Soundcloud will show the uploader avatar instead. But, when you will try to get the "artwork_url" from a JSONObject of that kind of a track, you will get "null".
To fix this issue, and to use the same logic Soundcloud use just add:
String artUrl = trackJson.getString("artwork_url");
if (artUrl == "null") {
JSONObject user = trackJson.getJSONObject("user");
artUrl = user.getString("avatar_url");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With