Skip to content

Instantly share code, notes, and snippets.

@hedgerh
Created June 23, 2014 10:26
Show Gist options
  • Save hedgerh/f8e4ff494d3546e253c4 to your computer and use it in GitHub Desktop.
Save hedgerh/f8e4ff494d3546e253c4 to your computer and use it in GitHub Desktop.
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