如何在没有用户名的情况下获得Spotify播放列表?

时间:2018-12-06 20:57:16

标签: python-3.x spotify spotipy

当提供用户名和播放列表ID时,主要的python API“ spotipy”(https://spotipy.readthedocs.io/en/latest/)仅允许您获取播放列表。

我只想提取播放列表ID,URI或URL的曲目列表。不需要用户名。

我认为有可能查看“获取播放列表”参考页面,但无法对其进行解密 -https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/

至少可以请我指引正确的方向吗?

1 个答案:

答案 0 :(得分:0)

我不确定100%知道python语法(对不起,如果不太正确),但是您可以在本地spotipy/client.py文件中添加其他方法吗?它将与user_playlist/user_playlist_tracks非常相似,但会绕过对用户ID的需求。

所以,像这样:

    def user_playlist_custom(self, playlist_id=None, fields=None):
        """ Gets playlist of a user
            Parameters:
                - playlist_id - the id of the playlist
                - fields - which fields to return
        """
        plid = self._get_id('playlist', playlist_id)
        return self._get("playlists/%s" % (plid), fields=fields)

或只是曲目:

    def user_playlist_tracks_custom(self, 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:
                - 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.
        """
        plid = self._get_id('playlist', playlist_id)
        return self._get("playlists/%s/tracks" % (plid),
                         limit=limit, offset=offset, fields=fields,
                         market=market)