Youtube Api v3多个视频时长

时间:2015-05-21 17:15:14

标签: c# youtube youtube-api

我正在使用Youtube Api v3搜索视频。我希望收到的视频持续时间在0-20分钟之间。

SearchResource.ListRequest listRequest = SearchResource.List("snippet");
 listRequest.Q = query;
 listRequest.Type = "video";
 listRequest.VideoDuration =    SearchResource.ListRequest.VideoDurationEnum.Medium;

Youtube有枚举,它定义了像;

这样的长度
SearchResource.ListRequest.VideoDurationEnum.Short; (0-4 minutes)
SearchResource.ListRequest.VideoDurationEnum.Medium; (4-20 minutes)

我想将这两个过滤器合并为一个。因为中等过滤器不会在0-4分钟之间返回视频。

有可能吗?

1 个答案:

答案 0 :(得分:2)

就我阅读文档而言,我没有看到一种优雅的方式来做到这一点。因此,创建2个请求,合并列表并迭代它们。像这样:

// define 2 separate requests
SearchResource.ListRequest listRequestMedium = SearchResource.List("snippet");
listRequestMedium.Q = query;
listRequestMedium.Type = "video";
listRequestMedium.VideoDuration = SearchResource.ListRequest.VideoDurationEnum.Medium;
SearchResource.ListRequest listRequestShort = SearchResource.List("snippet");
listRequestShort.Q = query;
listRequestShort.Type = "video";
listRequestShort.VideoDuration = SearchResource.ListRequest.VideoDurationEnum.Short;

SearchListResponse shortVideos = listRequestShort.Fetch();
SearchListResponse mediumVideos = listRequestMedium.Fetch();

// merge the 2 result lists and iterate over them
foreach (SearchResult searchResult in shortVideos.Items.Union(mediumVideos.Items).ToList()) {
    // do something with the videos

}