Jason Pitts
Jason Pitts

Reputation: 43

Filtering tracks by streamable = true in Soundcloud

I am trying to use the javascript SDK for Soundcloud to return a list of tracks that are streamable.

My question is: How do I filter search results for only streamable songs using the javascript SDK?

Here is an example that will return songs that are not streamable:

SC.get('/tracks', {q: 'mat zo', filter: 'streamable'}).then(function (tracks) { 
    console.log(tracks); 
});

Here is what the request comes out to be:

api.soundcloud.com/tracks?q=mat+zo&filter=streamable&format=json&client_id=[XXX]

I noticed that the first track in this response has streamable=false.
snippet of the response:

...
streamable: false
tag_list: "Remix Mat Zo Burn Ellie Goulding"
title: "Burn (Mat Zo Remix)"
track_type: ""
...

Looking at the Soundcloud SDK documentation I don't see a way to do this as the 'filter' query parameter only accepts '(all, public, private)'.

https://developers.soundcloud.com/docs/api/reference#tracks (I am looking at the Filters)

same unanswered question: stackoverflow.com/questions/23791711/filtering-tracks-by-streamable-in-soundcloud

Thanks in advance, this is my first question. I can provide more of my code upon request.

Upvotes: 4

Views: 278

Answers (2)

Hartger
Hartger

Reputation: 319

There is no (documented) filter for the streamable property on the API. You can however easily filter out the unstreamable tracks yourself:

SC.get('/tracks', {q: 'mat zo'}).then(function (tracks) { 
    for(var i = 0; i < tracks.length; i++) {
        if(!(tracks[i].streamable)) {           
        tracks.splice(i,1);
      } 
    }
    console.log(tracks); 
});

Upvotes: 1

Miles Grimes
Miles Grimes

Reputation: 442

It's hard to tell without having a token to test. However, the documentation around "Search" appears to imply that sounds can be filtered by property directly:

Some resource types, such as sounds, can be filtered by fields like license, duration or tag_list.

  // find all sounds of buskers licensed under 'creative commons share alike'
SC.get('/tracks', {
  q: 'buskers', license: 'cc-by-sa'
}).then(function(tracks) {
  console.log(tracks);
});

In your case, you should replace license with streamable and 'cc-by-sa' with 'true'.

Upvotes: -1

Related Questions