spotipy-dev / spotipy

A light weight Python library for the Spotify Web API
http://spotipy.readthedocs.org
MIT License
5k stars 954 forks source link

Stop at 50 tracks #299

Closed ghost closed 4 years ago

ghost commented 6 years ago

I have tried to see information with Unleashed album by Two Steps From Well and I don't know why the items are only 50 if the songs are 56. (Sorry for my english)

ritiek commented 6 years ago

Spotify API returns the first page and each page contains maximum 50 songs. To fetch rest of the songs, you need fetch more pages.

I do something like this to workaround this problem: https://github.com/ritiek/spotify-downloader/blob/0a3b7bd7d84fd0622fdca01413d8a82f57d44fe3/core/spotify_tools.py#L162-L181

So, you might have to structure your code something like this:

while True:
    for track in tracks['items']:
        # do stuff with track
        print(track)
    # 1 page = 50 results
    # check if there are more pages
    if track['next']:
        tracks = spotify.next(tracks)
    # if no more pages, exit while loop
    else:
        break

If you're still facing problems, share your code here and we'll try to figure out. Remember to remove your credentials.

(P.S. Your english is pretty good :)

ghost commented 6 years ago

Thanks very much for the answer, maybe you will be happy know that I have used your spotify-dowloader some time ago.