YouTube API v3中的隐藏式字幕

时间:2013-08-12 16:37:14

标签: java youtube-api google-api closed-captions

我需要在我的java网络应用中阅读来自第三方,公开提供的YouTube视频的隐藏式字幕文字,即我尚未上传内容。

虽然v2 of the YouTube Data API 限制了对上传视频的用户的字幕信息的访问,但除了这一段数据外,访问除了这一项之外的所有内容似乎是一个非常奇怪的限制。我希望在v3 of the API中看到此限制被删除,但现在对隐藏式字幕的唯一引用是一种布尔方法,用于确认CC是否附加到视频。即便是所有者现在也无法下载它。 (谷歌至少会把它添加回来吗?)

Boolean hasCaptions = video.getContentDetails().getCaption()

使用YouTube Data API v3(使用Google Java API client),我能够查找,验证和检索YouTube资源(视频,播放列表,频道等)。我可以做几乎所有API提供的东西我只是无法读取实际的标题文本。

我也尝试了unpublished timed text link workaround,但这不一致,不适用于较新的内容,并且在其涵盖的内容中有很多编码错误。

我想知道是否有人知道从java(不是.js插件)中检索YouTube视频中的字幕文本的方法?

[最坏的情况是,有没有人知道一个图书馆,它允许我像浏览器一样以编程方式与YouTube互动,而允许我点击屏幕上的成绩单按钮,我可以从那里提取成绩单? Prowser不允许点击互动,JxBrowser为$ 1,300 +]

下面的代码运行正常,让我收看所有视频数据,这是我需要帮助的最后一步。我把它包含在这里,以防它对任何需要这么做的人都有帮助。

// Build a YouTube resource
YouTube youtube = new YouTube.Builder(new NetHttpTransport(),
                            new JacksonFactory(), 
                            new HttpRequestInitializer())
                    .setApplicationName("caption-retrieval")
                    .build();

// Create the video list request, it should only return one
// result
YouTube.Videos.List listVideosRequest = youtube.videos().list("id, snippet, contentDetails");
listVideosRequest.setKey(API_KEY));
listVideosRequest.setId(VIDEO_ID);

// Request is executed and video list response is returned
VideoListResponse listVideosResponse = listVideosRequest.execute();

List<Video> videos = listVideosResponse.getItems();

// Since a unique video id is given, it will only return
// one video. Would check if video has been removed in 
// production code.
Video video = videos.get(0);

// Read the remaining meta information
title = video.getSnippet().getTitle().trim();
author = video.getSnippet().getChannelTitle();

captionText = ???????

感谢任何帮助。

谢谢,

格雷格。

2 个答案:

答案 0 :(得分:14)

我们希望尽快为Data API v3提供Captions支持。你不需要抓住网站。

更新:现已实施。 The docs can be found here.

答案 1 :(得分:0)

他们最终介绍了这个功能:

https://developers.google.com/youtube/v3/docs/captions
相关问题