7

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?

Zumteufel
  • 165
  • 1
  • 3
  • 10
  • I have this problem. Have you found a sollution?! – maxisme Nov 07 '14 at 21:50
  • `if(tracks.artwork_url == null){ console.log(tracks.avatar_url); $('.imageTrack').css('content', 'url(' + tracks.avatar_url.replace('large', 't500x500') + ')').fadeIn( "slow" ); }else{ console.log(tracks.artwork_url); $('.imageTrack').css('content', 'url(' + tracks.artwork_url.replace('large', 't500x500') + ')').fadeIn( "slow" ); }` – maxisme Nov 07 '14 at 23:19
  • I tried this but `avatar_url` returns `'undefined'` – maxisme Nov 07 '14 at 23:20
  • 1
    I haven't found a solution yet. To be honest, I thought that SoundCloud were handling their technical support here on SO, but... – Zumteufel Nov 08 '14 at 05:18
  • This is quite a major issue for anyone trying to build there own soundcloud application... I think the problem lies when the owner of the track hasn't given a specific song artwork? But that is why I tried avatar_url but that returns undefined! – maxisme Nov 08 '14 at 11:16
  • As I wrote in my original question, the artwork is there when you look at the track URL, just not in the query result. And yes, I'd say it's a major issue. – Zumteufel Nov 08 '14 at 16:45
  • Bounty hasn't worked... – maxisme Nov 10 '14 at 21:33

2 Answers2

1

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.

Tarik
  • 118
  • 1
  • 10
1

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");
}
Alon Levanon
  • 691
  • 5
  • 18