在https://developers.soundcloud.com/docs/api/reference#tracks上的SoundCloud API文档之后,我开始在我的一个项目中编写SoundCloud API的实现。 我尝试使用此代码获得最短长度为120000ms的特定流派的50首曲目:
def get_starttracks(genres="Rock"): return client.get("/tracks", genres=genres, duration={ 'from': 120000 }, limit='50')SoundCloud响应一个有效的曲目列表,但它们的持续时间与给定的过滤器不匹配。
例:
print(get_starttracks(genres="Pop")[0].fields()['duration']) > 30000api是否忽略了“持续时间”参数,或者在我的代码中的过滤器中是否有错误?
Ps .:可能与soundcloud search api有关, 忽略持续时间过滤器? ,如果错误不在Python代码中。
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']) > 30000Is 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.
最满意答案
在尝试通过对代码进行一些更改来解决此问题后,我终于找到了问题:
这不是一个错误。 随着Soundcloud发布了他们的“Go +” - 服务,一些官方音乐受限于30秒的预览。 API过滤器似乎比较完整曲目的持续时间,而只是将预览版本发送回客户端(如果您没有订阅“Go +”和/或您的应用程序未登录)。
因此,按时间过滤的唯一方法是遍历所有收到的曲目:
for track in tracks: if track.duration <= 30000: tracks.remove(track)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)更多推荐
发布评论