rinukkusu / spotify-dart

A dart library for interfacing with the Spotify API.
BSD 3-Clause "New" or "Revised" License
205 stars 92 forks source link

Error fetching playlists #69

Open stefanoromanello opened 4 years ago

stefanoromanello commented 4 years ago

I'm testing my code with 70+ playlists and in some of them when I try to get the tracks by using getTracksByPlaylistId I get a broken list (Iterable) see https://i.imgur.com/T3Tyt38.png. It seems that it starts to put some tracks but can't finish the list.

I've done some debug in the sdk code and when the code is parsing each song of the playlist in the method "Track _$TrackFromJson(Map<String, dynamic> json)" present in _models.g.dart at some point for one song of the playlist the parameter json is null.

And when I try to read the length of the Iterable returned by getTracksByPlaylistId I get:

Exception has occurred. NoSuchMethodError (NoSuchMethodError: The method '[]' was called on null. Receiver: null Tried calling: []("album"))

but the song that get a null json object has an album and it is not a podcast in the playlist.

Ps: this occurs with 4/5 playlists over the 70+

Update: the getPage method works correctly for every page and the problem seems to be in this pages.expand:

  Future<Iterable<T>> all([int limit = defaultLimit]) {

    return stream(limit)
        .map((page) => page.items)
        .toList()
        .then((pages) {
          Iterable<T> all = pages.expand((page) => page);
          return all;
        } );
  }

which returns a broken iterable

Also, for avoiding the api rate limit is there a quicker way to get all the songs of all playlist or the only way is to fetch each playlist and use getTracksByPlaylistId?

stefanoromanello commented 4 years ago

The problem is in the spotify's api. Some playlists returns the "count" field with more songs than in the actual response.