Skip to content

Commit

Permalink
Reject empty playlists, fixes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
gillesdemey committed Mar 3, 2016
1 parent 83be377 commit 50ea900
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/js/utils/soundcloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -156,6 +157,7 @@ SoundCloud.prototype.fetchPlaylists = function() {
}.bind(this))
return playlist
})
.then(rejectEmptyPlaylists)
}

SoundCloud.prototype.fetchPlaylistLikes = function() {
Expand All @@ -172,6 +174,7 @@ SoundCloud.prototype.fetchPlaylistLikes = function() {
}.bind(this))
return playlist
})
.then(rejectEmptyPlaylists)
}

SoundCloud.prototype.expandPlaylist = function(playlist) {
Expand Down Expand Up @@ -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();

0 comments on commit 50ea900

Please sign in to comment.