Created
June 23, 2014 10:26
-
-
Save hedgerh/f8e4ff494d3546e253c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stream = { | |
tracks: [], | |
playlists: [] | |
}; | |
function buildStream(group, callback) { | |
var artists = group.artists; | |
var params = { | |
limit: 5 | |
}; | |
async.each(artists, getStreamItems, function done(err) { | |
if (err) { | |
console.log(err); | |
} | |
callback(stream); | |
}); | |
function getStreamItems(artist, done) { | |
Soundcloud.get('/e1/users/' + artist + '/stream', params, processStreamItems); | |
function processStreamItems(items) { | |
async.each(items, processItem, error); | |
function processItem(item, cb) { | |
if ((item.type === 'track') || (item.type === 'track_repost')) { | |
stream.tracks = stream.tracks.concat(item.track); | |
} else if ((item.type === 'playlist') || (item.type === 'playlist_repost')) { | |
stream.playlists = stream.playlists.concat(item.playlist); | |
} | |
cb(); | |
} | |
function error(err) { | |
if (err) { | |
console.log(err); | |
} | |
} | |
done(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment