0
votes

Following the SoundCloud API Documentation at https://developers.soundcloud.com/docs/api/reference#tracks, I started to write an implementation of the SoundCloud API in one of my projects. I tried to get 50 tracks of a specific genre with a minimum length of 120000ms using this code:

def get_starttracks(genres="Rock"):
    return client.get("/tracks", genres=genres, duration={
        'from': 120000
    }, limit='50')

SoundCloud responds with a valid list of tracks, but their durations don't match the given Filter.

Example:

print(get_starttracks(genres="Pop")[0].fields()['duration'])
> 30000

Is the api ignoring the 'duration'-parameter or is there an error in the filter inside of my code?

Ps.: Could be related to soundcloud search api ignoring duration filter?, if error isn't inside of the python code.

1

1 Answers

0
votes

After trying to fix this problem with several changes to my code, I finally found the issue:

It's NOT a bug. As Soundcloud released their "Go+"-Services, some official tracks got limited to a preview of 30 seconds. The API filter seems to compare the duration of the full track, while just sending the preview-version back to the client (if you don't have subscribed to "Go+" and/or your application is not logged-in).

So, the only way to filter by duration is to iterate through all received tracks:

for track in tracks:
    if track.duration <= 30000:
        tracks.remove(track)