列出带有给定单词的视频

时间:2019-02-16 16:47:01

标签: youtube youtube-api youtube-data-api

如您所知,youtube具有一个属性,其中包含带有软编码视频的字幕。通过单击cc可以看到它。还有一个网站可以帮助一个人学习英语单词www.youglish.com

的发音

网站会在字幕视频中搜索给定的单词,并将其中的一部分与“ say”一词一起显示。也就是说,它可以按字幕搜索视频。这样做的方式/方法/步骤是什么?此外,ibm的工作类似于that

1 个答案:

答案 0 :(得分:0)

您可以使用search.list来请求以下视频:

  • closed caption
  • 与搜索词匹配。

在此示例中,这是对search.list启用且与搜索字词 (迷人) 匹配的搜索视频的closecaption请求:

https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=4&q=charming&type=video&videoCaption=closedCaption&fields=items(id(channelId%2Ckind%2CvideoId)%2Ckind%2Csnippet(channelTitle%2Cdescription%2Ctitle))&key={YOUR_API_KEY}

Demo available in Google API Explorer

这些是结果:

{
 "items": [
  {
   "kind": "youtube#searchResult",
   "id": {
    "kind": "youtube#video",
    "videoId": "ztsbgEUzVpc"
   },
   "snippet": {
    "title": "CHARMING Official Trailer (2018) Demi Lovato, Sia, Animation Movie HD",
    "description": "CHARMING Official Trailer © 2018 - Smith Global Media Comedy, Kids, Family and Animated Film, Blockbuster, Action Cinema, Blockbuster, Scifi Movie or ...",
    "channelTitle": "ONE Media"
   }
  },
  {
   "kind": "youtube#searchResult",
   "id": {
    "kind": "youtube#video",
    "videoId": "sO5F8DulPPk"
   },
   "snippet": {
    "title": "How to be more Charismatic - 6 Charisma Tips to be more Charming and Attractive",
    "description": "Use my FREE 27 Confidence-Boosting Hacks: https://practicalpie.com/confidence/ Want my TOP 10 book list?: https://practicalpie.com/book-list/ Get a girl to like ...",
    "channelTitle": "Practical Psychology"
   }
  },
  {
   "kind": "youtube#searchResult",
   "id": {
    "kind": "youtube#video",
    "videoId": "gesBAZo2_l4"
   },
   "snippet": {
    "title": "9 Tricks to Be the Most Charming Person in the Room",
    "description": "How to be a bit more charming? Some people could easily gain the trust of everyone and create a positive image of themselves? Jeff Haden, one of the most ...",
    "channelTitle": "BRIGHT SIDE"
   }
  },
  {
   "kind": "youtube#searchResult",
   "id": {
    "kind": "youtube#video",
    "videoId": "wMVPU3uUc5g"
   },
   "snippet": {
    "title": "10 Signs You Are An Exceptionally Charming Person",
    "description": "If you have these signs you are an exceptionally charming person – even if you don't think you are! Charm is the power or quality of delighting, attracting or ...",
    "channelTitle": "BRAINY DOSE"
   }
  }
 ]
}

不幸的是,并非所有返回的视频都有给定的单词(带字幕)-在这种情况下,单词是 charming

因此,您必须循环播放search.list响应中返回的视频,并选择确实具有给定单词的视频。

接下来,您可以通过传递videoId来获得字幕:

您可以使用此URL获取标题:

https://video.google.com/timedtext?type=track&v=<VIDEO_ID>&id=0&lang=en

通过修改URl并添加videoId来检索标题的有效jsfiddle是here