【问题标题】:Get Video Duration of a YouTube Video with youtube v3 API c#使用 youtube v3 API c# 获取 YouTube 视频的视频时长
【发布时间】:2018-06-28 13:23:21
【问题描述】:

我尝试使用 youtube v3 API 获取我之前搜索过的视频的长度,您可以在 nuget.org 下载。

我知道有很多解决方案,但它们总是用 php 编写的。

这就是我现在使用的代码:

var searchListRequest = youtubeService.Search.List("snippet");
earchListRequest.Q = Find;
searchListRequest.MaxResults = 5;



var searchListResponse = await searchListRequest.ExecuteAsync();
foreach (var searchResult in searchListResponse.Items)
        {
            switch (searchResult.Id.Kind)
            {
                case "youtube#video":
                break;
            }
        }

感谢您的任何帮助:)

【问题讨论】:

标签: c# youtube-data-api


【解决方案1】:

您可以下载Json版本的视频:

    WebClient myDownloader = new WebClient();
    myDownloader.Encoding = System.Text.Encoding.UTF8;

   string jsonResponse=myDownloader.DownloadString(
   "https://www.googleapis.com/youtube/v3/videos?id=" + yourvideoID+ "&key=" 
   + youtubekey + "&part=contentDetails");
   dynamic dynamicObject = Json.Decode(jsonResponse);
   string tmp = dynamicObject.items[0].contentDetails.duration;
   var Duration = Convert.ToInt32
   (System.Xml.XmlConvert.ToTimeSpan(tmp).TotalSeconds);

【讨论】:

猜你喜欢
  • 2015-12-07
  • 1970-01-01
  • 2016-01-17
  • 2014-01-26
  • 2014-06-05
  • 2015-07-18
  • 2015-08-29
  • 2015-12-01
  • 2015-03-11
相关资源
最近更新 更多