From 3f953d1cdf50ef7f56c5635bba47cf4947fa455e Mon Sep 17 00:00:00 2001 From: Anthony Brown Date: Mon, 22 Jun 2015 18:57:38 +0100 Subject: [PATCH] fix error where track not playable in country - https://github.com/TooTallNate/node-spotify-web/issues/90 --- lib/spotify.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/spotify.js b/lib/spotify.js index e90eb3a..fe32460 100644 --- a/lib/spotify.js +++ b/lib/spotify.js @@ -989,6 +989,17 @@ Spotify.prototype.isTrackAvailable = function (track, country) { Spotify.prototype.recurseAlternatives = function (track, country, fn) { debug('recurseAlternatives()'); + var enumCatalogue = { + "AD" : 0 , + "SUBSCRIPTION" : 1, + "SHUFFLE" : 2, + "undefined" : 3 + } + track.restriction.forEach(function(r) { + if (r.catalogue) { + r.catalogue = r.catalogue.map(function(x) { return enumCatalogue[x]; }); + } + }); function done () { process.nextTick(function () { fn(null, track); @@ -996,7 +1007,8 @@ Spotify.prototype.recurseAlternatives = function (track, country, fn) { } if (this.isTrackAvailable(track, country)) { return done(); - } else if (Array.isArray(track.alternative)) { + } + if (Array.isArray(track.alternative)) { var tracks = track.alternative; for (var i = 0; i < tracks.length; i++) { debug('checking alternative track %j', track.uri);