【问题标题】:How to get a Spotify playlist without the username?如何获得没有用户名的 Spotify 播放列表?
【发布时间】:2018-12-06 20:57:16
【问题描述】:

主要的 python api "spotipy"(https://spotipy.readthedocs.io/en/latest/) 只允许您在提供用户名和播放列表 ID 时获取播放列表。

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

我认为可以查看 Get A Playlist 参考页面,但我无法解读 - https://developer.spotify.com/documentation/web-api/reference/playlists/get-playlist/

请你至少把我引向正确的方向吗?

【问题讨论】:

    标签: python-3.x spotify spotipy


    【解决方案1】:

    我对 python 语法不是 100% 确定的(很抱歉,如果它不是很正确),但你能在你的本地 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)
    

    【讨论】:

      猜你喜欢
      • 2015-08-31
      • 1970-01-01
      • 2011-09-23
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 2019-07-27
      • 2017-03-26
      • 2017-03-08
      相关资源
      最近更新 更多