我正在尝试使用python的Spotipy library来提取某个播放列表中的所有曲目
无论参数限制如何,用户播放列表曲目功能限制为100首曲目。Spotipy文档将其描述为:
user_playlist_tracks(user, playlist_id=None, fields=None, limit=100, offset=0, market=None)
Get full details of the tracks of a playlist owned by a user.
Parameters:
- user
- the id of the user playlist_id
- the id of the playlist fields
- which fields to return limit
- the maximum number of tracks to return offset
- the index of the first track to return market
- an ISO 3166-1 alpha-2 country code.
在使用Spotify进行身份验证后,我目前正在使用类似以下内容:
username = xxxx
playlist = #fromspotipy
sp_playlist = sp.user_playlist_tracks(username, playlist_id=playlist)
tracks = sp_playlist['items']
print tracks
有没有办法返回100多首曲目?我尝试在函数参数中设置limit=None,但它返回了一个错误
我写了一个函数,它可以输出熊猫的数据帧,在那里它可以为超过100首歌曲的播放列表提取所有的元数据(不是所有的,因为我不想这样做,但你可以为此腾出一些空间)。我通过迭代每首歌曲,找到每首歌曲的元数据,将元数据保存到字典中,然后将字典连接到数据帧来实现。它以您的用户名和播放列表ID作为输入
另一种解决方法是编写for循环并执行以下操作:
然后,您可以在末尾连接轨迹,或者将它们放在数据帧中。 功能参考:
参考:https://spotipy.readthedocs.io/en/2.7.0/#spotipy.client.Spotify.playlist_tracks
许多spotipy方法返回分页结果,因此您必须滚动浏览它们才能查看的不仅仅是max limit。我在收集播放列表的完整曲目列表时经常遇到这种情况,因此创建了一个自定义方法来处理这种情况:
相关问题 更多 >
编程相关推荐