javascript – YouTube API’orderby = duration’不处理整个播放列表,只处理最新的视频

前端之家收集整理的这篇文章主要介绍了javascript – YouTube API’orderby = duration’不处理整个播放列表,只处理最新的视频前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试构建一个 JavaScript程序,以查询给定播放列表的 YouTube API,按持续时间排序.一切都运作良好,但订单不占整个播放列表,只有25个最新的视频!这是最小的完整工作 example as a JSFiddle,这是它的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);
        });
    }
);

我在XML和JSON中尝试了这个,除了播放列表搜索之外,我还尝试了其他类型的搜索.让API排序只是结果的最新视频似乎毫无意义.我究竟如何检索播放列表的最长或最短视频,或者由给定用户上传的那些视频?

解决方法

编辑

我不认为你想要的功能是可用的. YouTube本身甚至无法按照持续时间排序.我想你需要使用max-results和start-index来获取视频块.然后,您可以按持续时间对编译列表进行排序

以下是一个可能解决方案的工作示例:http://jsfiddle.net/PKcnb/8

我发现谷歌说这种说法不可能.

YouTube API v2.0 – Video Feed Types: Videos uploaded by a specific user

This section explains how to retrieve a Feed containing all of the
videos uploaded by a specific user. You should not include 07002 in requests to retrieve an uploaded videos Feed. The
parameters will generate a Feed from YouTube’s search index,
effectively restricting the result set to indexed,public videos,
rather than returning a complete list of the user’s uploaded videos.

它继续说:

To request a Feed of all videos uploaded by the currently logged-in
user,send a GET request to the following URL. This request requires
an authentication token,which enables YouTube to identify the user.

因此,它可能是可能的,但您必须使用身份验证令牌对其进行测试.

原帖

> API docs for orderby让它听起来只有响应被排序.

The orderby parameter,which is supported for video Feeds and playlist Feeds,specifies the method that will be used to order entries in the API response.

>此外,the max-results tag将允许您指定要返回的项目数.
> Here’s an example of how you could pull more (50 in this example)结果已经排序.看起来您可能需要尽可能多的请求然后排序.绝对不理想.
> Retrieving a user’s playlists

猜你在找的JavaScript相关文章