Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

artwork_url is null in track lists, has value for single track. Bug?

Tags:

soundcloud

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?

like image 251
Zumteufel Avatar asked Aug 04 '14 06:08

Zumteufel


2 Answers

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.

like image 131
Tarik Avatar answered Oct 06 '22 08:10

Tarik


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");
}
like image 33
Alon Levanon Avatar answered Oct 06 '22 08:10

Alon Levanon