Incorrect snapshot length returned for a specific playlist

117 views Asked by At

I have a problem when using this spotify playlist spotify:user:juan20150:playlist:5rl5QaWjWtEPv9a057w3qc

This is the first playlist I've seen which has this problem. The snapshot length returned is 290, but when I do snapshot.loadAll, it returns only 289 tracks.

Any idea why it would happen?

    var playlist = models.Playlist.fromURI("spotify:user:juan20150:playlist:5rl5QaWjWtEPv9a057w3qc");
playlist.load('tracks').done(function() {

      playlist.tracks.snapshot().done(function(snapshot) {
        console.log("snapshot length " , snapshot.length);
        $i=0;
        snapshot.loadAll('name').each(function(track) {


            console.log("i=" , i++);


        });
    });

});

Results:

snapshot length 290 i = 289 (at the end)

Thanks

1

There are 1 answers

2
Thomas On BEST ANSWER

Because you started at zero, and post-incremented. If the playlist was length 3, it would print

0
1
2

for the 3 tracks.


Update trying it myself To start with, it helps to put actual code not pseudo code. I threw your code in my app and it didn't work. Once I fixed it, it printed from 0 to 288. So, I removed .each and put in .done and it didn't print anything. However, .fail did return something. Unfortunately, the error is undefined. The below:

require(['$api/models'], function(models) {
    var playlist = models.Playlist.fromURI("spotify:user:juan20150:playlist:5rl5QaWjWtEPv9a057w3qc");
    playlist.load('tracks').done(function() {

    playlist.tracks.snapshot().done(function(snapshot) {
        console.log("snapshot length " + snapshot.length);
        var i=0;
        snapshot.loadAll('name')
            //.each(function(t) { console.log(i++); })
           .done(function(snap_tracks) { console.log("loaded tracks length " + snap_tracks.length); })
           .fail(function(track, error) { console.log(error + ". " + track.length); });
        });

    });
});

outputs:

14:39:15.898 I [sp://67456db3aaa5a1c25a619472cdb2cbc3f52da3ed.album-radio/js/alb
umradio.js:507] snapshot length 290
14:39:16.236 I [sp://67456db3aaa5a1c25a619472cdb2cbc3f52da3ed.album-radio/js/alb
umradio.js:512] undefined. 290

My best guess is that you have a song in there that is no longer accessible (licensing dispute or something).