Skip to content

Instantly share code, notes, and snippets.

@dested
Created December 22, 2014 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dested/bc70cd912c966ea1e77e to your computer and use it in GitHub Desktop.
Save dested/bc70cd912c966ea1e77e to your computer and use it in GitHub Desktop.
getPlaylistSongs = function(options) {
var deferred = Q.defer();
this._doRequest(YouTubeServiceType.PlaylistItems, {
part: 'contentDetails',
maxResults: 50,
playlistId: options.playlistId,
pageToken: options.pageToken || '',
fields: 'nextPageToken, items/contentDetails/videoId'
})
.then(function(response) {
var songIds = _.map(response.items, function(item) {
return item.contentDetails.videoId;
});
this.getSongs({
songIds: songIds,
})
.then(function(songs) {
deferred.resolve({
songs: songs,
nextPageToken: response.nextPageToken,
})
})
.error(deferred.reject)
.finally(deferred.finally);
}.bind(this))
.error(function(error) {
deferred.reject();
deferred.finally();
});
return deferred.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment