Situation: User want to import Youtube playlist in a JQuery site using Youtube's JSON API.
Problem: Youtube only gives back first 50 entries, but playlists can be 100+ entries long (length is given by 'totalItems' in JSON response). All the entries need to be merged as 1 object and need to be pushed into an output function at the end.
Entry 50-100: http://gdata.youtube.com/feeds/api/playlists/84780DAC99E1A285?v=2&alt=jsonc&max-results=50&start-index=50
Current code:
function fetchPlaylist(pid) {
var the_url = 'http://gdata.youtube.com/feeds/api/playlists/' + encodeURIComponent(pid) + '?v=2&alt=jsonc&max-results=50';
$.ajax({
type: "GET",
url: the_url,
dataType: "jsonp",
success: function (responseData, textStatus, XMLHttpRequest) {
if (responseData.data != null) {
if (responseData.data.items) {
outputFunction(responseData.data.items);
} else {
console.log('No results for playlist: "' + pid + '"');
}
}
}
});
}
Question:
What is the most efficient way to repeat the JSON calls until all the entries are received?
How to combine the different responses into one object?
What I've tried:
Merging with the use of http://api.jquery.com/jQuery.extend/ , got stuck because of the complex/nested situation