From 50ea9003c7638f0deb8ad3535557282105d82256 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Thu, 3 Mar 2016 19:40:43 +0100 Subject: [PATCH] Reject empty playlists, fixes #42 --- app/js/utils/soundcloud.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/js/utils/soundcloud.js b/app/js/utils/soundcloud.js index 84d5a1e..dab46a3 100644 --- a/app/js/utils/soundcloud.js +++ b/app/js/utils/soundcloud.js @@ -134,6 +134,7 @@ SoundCloud.prototype.fetchFeed = function(options) { else if (item.kind === 'track') return self._mapTrack(item) }) + .then(rejectEmptyPlaylists) .then(function(tracks) { // SoundCloud activities can return multiple of the same track tracks = _.uniq(tracks, 'id') @@ -156,6 +157,7 @@ SoundCloud.prototype.fetchPlaylists = function() { }.bind(this)) return playlist }) + .then(rejectEmptyPlaylists) } SoundCloud.prototype.fetchPlaylistLikes = function() { @@ -172,6 +174,7 @@ SoundCloud.prototype.fetchPlaylistLikes = function() { }.bind(this)) return playlist }) + .then(rejectEmptyPlaylists) } SoundCloud.prototype.expandPlaylist = function(playlist) { @@ -203,4 +206,15 @@ function _artworkFormat(url, size) { return url.replace('-large', '-' + size); } +/** + * reject playlists with 0 tracks, maybe some sort of DRM? + * + * fixes https://github.com/gillesdemey/Cumulus/issues/42 + */ +function rejectEmptyPlaylists(playlists) { + return _.reject(playlists, function(item) { + return item.kind === 'playlist' && item.tracks.length < 1; + }); +} + module.exports = new SoundCloud();