SoundCloud API忽略持续时间过滤器(SoundCloud API ignoring duration filter)

编程入门 行业动态 更新时间:2024-10-25 08:15:44
SoundCloud API忽略持续时间过滤器(SoundCloud API ignoring duration filter)

在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']) > 30000

api是否忽略了“持续时间”参数,或者在我的代码中的过滤器中是否有错误?

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']) > 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.

最满意答案

在尝试通过对代码进行一些更改来解决此问题后,我终于找到了问题:

不是一个错误。 随着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)

更多推荐

本文发布于:2023-08-06 16:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1451575.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   持续时间   API   SoundCloud   duration

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!