【问题标题】:SoundCloud API ignoring duration filterSoundCloud API 忽略持续时间过滤器
【发布时间】:2017-03-06 08:31:39
【问题描述】:

根据https://developers.soundcloud.com/docs/api/reference#tracks 的 SoundCloud API 文档,我开始在我的一个项目中编写 SoundCloud API 的实现。我尝试使用以下代码获取 50 首特定类型的曲目,最小长度为 120000 毫秒:

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.:如果错误不在 python 代码中,可能与soundcloud search api ignoring duration filter? 有关。

【问题讨论】:

    标签: python api dictionary soundcloud


    【解决方案1】:

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

    不是错误。随着 Soundcloud 发布他们的“Go+”服务,一些官方曲目被限制为 30 秒的预览。 API 过滤器似乎比较了完整曲目的持续时间,而只是将预览版本发送回客户端(如果您没有订阅“Go+”和/或您的应用程序未登录)。

    因此,按时长过滤的唯一方法是遍历所有接收到的曲目:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-23
      相关资源
      最近更新 更多