JBart
JBart

Reputation: 143

Pull metadata from a soundcloud account with over 1500 tracks

I'm helping out someone who needs to pull metadata from their soundcloud account (track title, description, date published, size, duration, media URL, etc). Unfortunately, they have over 1500+ tracks, so it is not sufficient to use the rss feed, which is limited to 200 or 250 tracks.

soundcloud no longer gives out client ID for their API. I found a client ID used in a github project. Then using soundcloud python wrapper found here https://github.com/soundcloud/soundcloud-python, I tried to get track meta data with this

 import soundcloud

 client = soundcloud.Client(client_id=CLIENT_ID_REDACTED)
 tracks = client.get('/users/9999999/tracks/', limit=5000)
 print(len(tracks))

Alas, it will only return max 200 tracks, so that doesn't help.

Does this 200 track limit exist if I have an actual client ID registered to the account? Is there any hope of getting this data?

thanks in advance

Upvotes: 0

Views: 566

Answers (2)

JBart
JBart

Reputation: 143

linked_partitioning is the key. Thanks to @nickf

Btw, the soundcloud API doc is either wrong or refers to an old API

import soundcloud

client = soundcloud.Client(client_id='clientidhere')

page_size = 200

# get first page of tracks
tracks = client.get('/users/999999/tracks', limit=page_size,
    linked_partitioning=1)

c = 1

for track in tracks.collection:
    print(c,track.title)
    c += 1

# .next_href exists means there are more pages
while hasattr(tracks, 'next_href'):
    # pass .next_href to get next page
    tracks = client.get(tracks.next_href, limit=page_size,
        linked_partitioning=1)
    for track in tracks.collection:
        print(c,track.title)
        c += 1

Upvotes: 0

nickf
nickf

Reputation: 546085

Add ?linked_partitioning=1 to the initial request and the response will contain a property called next_href which gives you the URL of the next page of results.

Upvotes: 1

Related Questions