I am trying to create a small JavaScript program to request a YouTube API for a specific playlist, sorted by duration. Everything works fine, but the order does not take into account the entire playlist, only 25 new videos! Here is a minimal complete working example like JSFiddle and here is part of JavaScript:
var playlistId = "UUAuUUnT6oDeKwE6v1NGQxug"; jQuery.getJSON( "https://gdata.youtube.com/feeds/api/playlists/"+playlistId+"?v=2&orderby=duration&alt=json", function(data) { $.each(data.feed.entry, function(key, val) { var title = val.title.$t; var url = val.content.src; var duration = val.media$group.yt$duration.seconds; var minutes = Math.floor(duration / 60); var seconds = (duration % 60); if( seconds < 10 ) seconds = "0"+seconds; var newRow = $("<tr></tr>"); newRow.append("<td><a href='"+url+"'>"+title+"</a></td>"); newRow.append("<td class='dur'>"+minutes+":"+seconds+"</td>"); $("#videos").append(newRow); }); } );
I tried this in both XML and JSON, and I also tried other kinds of searches besides playlist searches. With the API sorting, only the newest result videos seem completely pointless. How can I get the longest or shortest videos from a playlist or those uploaded by a given user?
Zeroone
source share