Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order by playbacks when fetching tracks from SoundCloud

Tags:

soundcloud

I am fetching a list of tracks from soundcloud's API using the following query to retrieve the 5 most popular tracks:

https://api.soundcloud.com/tracks?client_id=XXX&order=hotness&limit=5

But recently SoundCloud removed the hotness order. In the blog post they say tracks can instead be sorted by playback_count. But can this be done in the query or do they suggest I pull down the whole SoundCloud library and order them in the client? The following doesn't seem to work:

https://api.soundcloud.com/tracks?client_id=XXX&order=playback_count&limit=5

So how would one retrieve the top tracks on SoundCloud?

like image 467
Christoffer Reijer Avatar asked May 06 '13 07:05

Christoffer Reijer


2 Answers

The solution was to use the undocumented calls for the explorer feature that SoundCloud itself uses (I used the dev tools in Chrome to check the AJAX calls).

https://api.soundcloud.com/explore/sounds/category?limit=L&client_id=XXX

This appears to use some sort of sorting on the popularity of the songs. The songs can then be filtered on only music by checking the "grouping" attribute. I then have to resolve the list of IDs to actual songs which can be done with the (documented, official) API call:

https://api.soundcloud.com/tracks?ids=1,2,3&client_id=XXX

This seems to work perfectly and I also get the added benefit of an even distribution among genres. But of course, this can stop working at any moment since the API calls are undocumented and perhaps not meant for public use.

like image 121
Christoffer Reijer Avatar answered Oct 14 '22 05:10

Christoffer Reijer


Just wanted to provide an update. It seems soundcloud has moved to v2 of the explore API call.

Use this to get a list of categories:
https://api.soundcloud.com/explore/v2

And this to get tracks from a category:
https://api-v2.soundcloud.com/explore/metal?limit=10&offset=0

So far it seems to without a key, although I have no idea how long that will last.

EDIT: So the 2nd url doesn't seem to allow cross-origin, but so far this does work, though it only returns the trackID not the full information

https://api.soundcloud.com/explore/v2/metal?limit=50&consumer_key=XXX

like image 33
Justin Avatar answered Oct 14 '22 06:10

Justin