【问题标题】:Pull metadata from a soundcloud account with over 1500 tracks从具有 1500 多个音轨的 soundcloud 帐户中提取元数据
【发布时间】:2018-02-24 00:43:31
【问题描述】:

我正在帮助需要从他们的 soundcloud 帐户中提取元数据(曲目标题、描述、发布日期、大小、持续时间、媒体 URL 等)的人。不幸的是,它们有超过 1500 多个曲目,因此仅使用 rss 提要是不够的,它仅限于 200 或 250 个曲目。

soundcloud 不再为其 API 提供客户端 ID。我找到了一个 github 项目中使用的客户端 ID。然后使用在这里找到的 soundcloud python 包装器https://github.com/soundcloud/soundcloud-python,我试图用这个来获取跟踪元数据

 import soundcloud

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

唉,它最多只能返回 200 首曲目,所以这无济于事。

如果我在帐户中注册了实际的客户 ID,是否存在 200 条跟踪限制?有没有希望得到这些数据?

提前致谢

【问题讨论】:

  • 200 首曲目后,是否出现错误?还是脚本继续运行,但没有返回任何新内容?
  • 它只返回 200 个结果。该请求返回一个包含 200 个项目的数组。没有错误。

标签: python api soundcloud


【解决方案1】:

将 ?linked_pa​​rtitioning=1 添加到初始请求,响应将包含一个名为 next_href 的属性,该属性为您提供下一页结果的 URL。

【讨论】:

    【解决方案2】:

    linked_pa​​rtitioning 是关键。感谢@nickf

    顺便说一句,soundcloud API 文档要么错误,要么引用了旧 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 2016-03-23
      • 1970-01-01
      • 2020-08-10
      • 2015-12-12
      • 2018-09-27
      • 2012-02-06
      相关资源
      最近更新 更多