2016-08-22 19 views
1

私は特定のプレイリストのすべてのトラックを、python用にSpotipy libraryを使って取得しようとしています。Spotipy:プレイリストから100以上のトラックを読むには

user_playlist_tracks関数は、パラメータの制限にかかわらず、100トラックに制限されています。 Spotipyのドキュメントのようにそれを説明します

username = xxxx 
playlist = #fromspotipy 
sp_playlist = sp.user_playlist_tracks(username, playlist_id=playlist) 
tracks = sp_playlist['items'] 
print tracks 

100台の以上のトラックを返す方法があります:Spotifyはして認証後

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.

、私は現在、このようなものを使用していますか?私は、関数パラメータでlimit = Noneを設定しようとしましたが、エラーを返します。

答えて

5

に上限を設定してみてください、あなただけの最高限度を超えるを表示するためにそれらをスクロールする必要がありますので、spotipy方法の多くは、ページ番号付きの結果を返します。 Iこれは、ほとんどの場合、リストのプレイリストのフルトラックを収集し、その結果、これを処理するためのカスタムメソッドを作成したときに遭遇した: `spotipy.client.SpotifyException::HTTPステータス:このエラーで

def get_playlist_tracks(username,playlist_id): 
    results = sp.user_playlist_tracks(username,playlist_id) 
    tracks = results['items'] 
    while results['next']: 
     results = sp.next(results) 
     tracks.extend(results['items']) 
    return tracks 
0

以下は、spotipyで使用されるuser_playlist_tracksモジュールです。 (デフォルトで100に制限されていることに注意してください)。

は200

def user_playlist_tracks(self, user, playlist_id = None, fields=None, 
    limit=100, offset=0): 
    ''' 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 
    ''' 
    plid = self._get_id('playlist', playlist_id) 
    return self._get("users/%s/playlists/%s/tracks" % (user, plid), 
       limit=limit, offset=offset, fields=fields) 
+0

何でも100以上の結果400を、コード:-1 - https://api.spotify.com/v1/users/im.nick.hello/playlists/7lArr0TzHvKoEsj6cotHqZ/tracks?limit=200&offset=0: 無効な制限 ' – npbecker

+0

@NickBeckerはこのリンクをWeb APIを見分ける。 https://developer.spotify.com/web-api/get-playlist/ ページングオブジェクト内で「offset」キーを使用する必要があります。上の私の記事では、コードが 'offset'パラメータを許すことがわかります。 APIへの複数の呼び出しを行い、呼び出しごとにオフセットを調整する必要があります。 – rvisio

関連する問題