Last active
August 29, 2015 14:02
-
-
Save hedgerh/d95329285bf78bf2a9ab 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
get('/user/12345/stream', params) | |
.then(function(items) { | |
var stream = []; | |
var new_item; | |
_.each(items, function(item) { | |
/* see if track is a repost. item.type can have the values: | |
'track', 'playlist', 'track_repost', or 'playlist_repost' | |
*/ | |
new_item.is_repost = (item.type.slice(-6) === 'repost'); | |
// if it's a repost, item.created_at != item.track.created_at, so i want to add it to the new object | |
new_item.repost_created_at = item.created_at; | |
if (item.type === 'playlist' || item.type === 'playlist_repost') { | |
new_item = item.playlist; | |
stream.push(new_item); | |
} | |
else { | |
new_item = item.track; | |
stream.push(new_item); | |
} | |
}); | |
var final = _.groupBy(stream, function(item) { | |
return (item.slice(8) === 'playlist') | |
}) | |
return final; | |
}); | |
// track object | |
var track = { | |
"kind": "stream_item", | |
"type": "track_repost", | |
"created_at": "2014/06/16 22:29:09 +0000", | |
"track": { | |
"kind": "track", | |
"id": 154591682, | |
"created_at": "2014/06/16 11:33:38 +0000", | |
"user_id": 46059856, | |
"duration": 350308, | |
// ... trimmed off track data that isnt pertinent | |
}, | |
"playlist": null | |
} | |
//playlist object | |
var playlist = { | |
"kind": "stream_item", | |
"type": "playlist_repost", | |
"created_at": "2014/06/22 22:36:02 +0000", | |
"track": null, | |
"playlist": { | |
"kind": "playlist", | |
"id": 40585650, | |
"created_at": "2014/06/20 16:22:58 +0000", | |
"user_id": 315279, | |
"duration": 2677318, | |
"sharing": "public", | |
"tag_list": "Dubstep House Moombahton \"Electro House\"", | |
"permalink": "coders-special", | |
"track_count": 13, | |
"streamable": true, | |
"downloadable": null, | |
"embeddable_by": "all", | |
"purchase_url": null, | |
"label_id": null, | |
"type": null, | |
"playlist_type": null, | |
"ean": null, | |
"description": null, | |
"genre": "Electronic", | |
"release": null, | |
"purchase_title": null, | |
"label_name": null, | |
"title": "Coder's Special", | |
"release_year": null, | |
"release_month": null, | |
"release_day": null, | |
"license": "all-rights-reserved", | |
"uri": "https://api.soundcloud.com/playlists/40585650", | |
"permalink_url": "http://soundcloud.com/rudeluv/sets/coders-special", | |
"artwork_url": null, | |
"user": { | |
"id": 315279, | |
"kind": "user", | |
"permalink": "rudeluv", | |
"username": "RÜDΣLUV", | |
"uri": "https://api.soundcloud.com/users/315279", | |
"permalink_url": "http://soundcloud.com/rudeluv", | |
"avatar_url": "https://i1.sndcdn.com/avatars-000034897715-spf187-large.jpg?30a2558" | |
}, | |
"tracks": [{ | |
// collection of track objects, this is non-pertinent. i want the entire 'playlist' property | |
}] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment