如何使用适用于Android的YouTube API v3获取YouTube视频的cc副标题?
字幕"英语","英语自动生成"之间的区别是什么?和"英语自动"?
答案 0 :(得分:0)
根据此documentation,您需要调用captions.list方法来检索特定视频可用的字幕轨道列表。将videoId参数值设置为唯一标识要检索字幕的视频的YouTube视频ID。
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.captions.list?part=snippet&videoId=PRU2ShMzQRg
以下是example,演示了如何使用API方法创建和管理YouTube视频字幕轨道。
检查此相关的SO问题:How to add Captions to Youtube video using Youtube API v3?
<强>更新强>
选中example。
/**
* Returns a list of caption tracks. (captions.listCaptions)
*
* @param videoId The videoId parameter instructs the API to return the
* caption tracks for the video specified by the video id.
* @throws IOException
*/
private static List<Caption> listCaptions(String videoId) throws IOException {
// Call the YouTube Data API's captions.list method to
// retrieve video caption tracks.
CaptionListResponse captionListResponse = youtube.captions().
list("snippet", videoId).execute();
List<Caption> captions = captionListResponse.getItems();
// Print information from the API response.
System.out.println("\n============ Returned Caption Tracks ============\n");
CaptionSnippet snippet;
for (Caption caption : captions) {
snippet = caption.getSnippet();
System.out.println(" - ID: " + caption.getId());
System.out.println(" - Name: " + snippet.getName());
System.out.println(" - Language: " + snippet.getLanguage());
System.out.println("\n----------------------------------------------\n");
}
return captions;
}