Soundcloud API not returning all tracks from playlist through Python

纵然是瞬间 提交于 2019-12-10 15:27:05

问题


I recently started to use the Soundcloud API to develop a simple app which saves data on playlists. However, it seems to me that not all tracks from playlists are being returned.

I'm using the following code:

import soundcloud, shelve, time

client = soundcloud.Client(client_id=CLIENT_ID,
                           client_secret=CLIENT_SECRET,
                           username=E-MAIL,
                           password=PASSWORD)

playlists = client.get('/users/24196709/playlists', limit=1)

tracknames = []
trackids= []

for pl in playlists:
    for track in pl.tracks:
        print(track['title'])
        tracknames.append(track['title'])
        trackids.append(track['id'])

print(tracknames)

Using it on this playlist: https://soundcloud.com/michiel-tammeling/sets/icecubes which contains 13 tracks, however the code only returns 11.

Any help would be much appreciated.


回答1:


This can't be solved unfortunately. Lots of topics on this issue already. The thing is that the playlist API returns all tracks in the playlist, but the tracks API returns only tracks that are not protected. Since you already figured out which 2 tracks where missing I verified this and they both return a 403 when you try to use the track API. So those 2 tracks are somehow not accessible using the track API.

Some more background:

SoundCloud Playlist tracks is empty

SoundCloud emailed back saying they have introduced an option for right holders to disable all API access to tracks by default, returning this 403 error when requested. They also said it's understandable that this is a confusing feature, and that they hope to make it more clear.

And @nickf the tech lead of soundcloud says:

Yep -- there's many reasons that a track might not show up to you. It could be taken down by the rightsholder of the track, made private or deleted by the uploader, or (and this is the tricky one) blocked in certain territories. Calculating the policies of all of the tracks of a user every time it is fetched isn't quite feasible, so sometimes this number will be inaccurate (depending on who is asking and where they are). – nickf Apr 14 at 22:37



来源:https://stackoverflow.com/questions/36755039/soundcloud-api-not-returning-all-tracks-from-playlist-through-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!