YouTube API v3中的隐藏字幕 [英] Closed Captions in YouTube API v3

查看:200
本文介绍了YouTube API v3中的隐藏字幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从我的java webapp中的第三方公开的YouTube视频阅读隐藏字幕文本,即我没有上传内容。



第二版YouTube数据API 限制访问权限向上传视频的人提供的字幕信息看起来像是一个非常奇怪的限制,只允许访问除这一部分数据之外的所有内容。我预计会在第三版API中删除此限制,但现在只有对隐藏字幕的引用是确认CC是否附加到视频的布尔方法。即使是业主现在也无法下载。 (Google是否至少将它添加回来?)

 布尔hasCaptions = video.getContentDetails()。getCaption()

使用YouTube数据API v3(使用)我已经能够查找,验证和检索YouTube资源(视频,播放列表,频道,视频,音乐,视频,等等。)。我几乎可以完成API提供的所有内容,但我无法阅读实际的标题文本。



我也尝试了未发布的定时文本链接解决方法,但这是不一致的,不适用于较新的内容,并且在它包含的内容中存在许多编码错误。



我想知道是否有人知道从Java视频中获取标题文本的方法(不是.js插件)?

[最糟糕的情况是任何人都知道图书馆允许我以浏览器的方式与YouTube进行程序化交互,并且允许我点击屏幕上的抄本按钮,并且可以从那里提取抄本。 Prowser 不允许点击互动和 JxBrowser 是$ 1,300 +]



下面的代码可以正常工作,让我可以看到所有的视频数据,因此它是最后一步我需要帮助。我将它包含在这里以防止任何需要这么做的人。

  //构建YouTube资源
YouTube youtube = new YouTube.Builder(新的NetHttpTransport(),
新的JacksonFactory(),
新的HttpRequestInitializer())
.setApplicationName(caption-retrieval)
.build();

//创建视频列表请求,它应该只返回一个
//结果
YouTube.Videos.List listVideosRequest = youtube.videos()。list(id, snippet,contentDetails);
listVideosRequest.setKey(API_KEY));
listVideosRequest.setId(VIDEO_ID);

//执行请求并返回视频列表响应
VideoListResponse listVideosResponse = listVideosRequest.execute();

列表< Video> videos = listVideosResponse.getItems();

//由于给出了唯一的视频ID,它只会返回
//一个视频。将检查视频是否已在
//生产代码中删除。
Video video = videos.get(0);

//读取其余的元信息
title = video.getSnippet()。getTitle()。trim();
author = video.getSnippet()。getChannelTitle();

captionText = ???????

感谢您的任何帮助。

谢谢,

格雷格。

解决方案

即将支持Data API v3。您不需要刮网站。



更新:现已实施。 可在此处找到文档。


I need to read closed caption text from 3rd party, publicly available YouTube videos in my java webapp i.e. I have NOT uploaded the content.

Whilst v2 of the YouTube Data API restricted access to the caption information to the person who uploaded the video it seems like a very odd restriction to give access to everything except this one piece of data. I expected to see this restriction removed in v3 of the API but now the only reference to closed caption is a boolean method to confirm if CC is attached to the video. Even the owner can't seem to download it now. (Are Google going to add it back at least?)

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

Using YouTube Data API v3 (using the Google Java API client) I have been able to find, authenticate and retrieve YouTube resources (videos, playlists, channels, etc.). I can do pretty much everything the API has made available I just can't read the actual caption text.

I've also tried the unpublished timed text link workaround but this is inconsistent, doesn't work for newer content and has many encoding errors in the content it does cover.

I'm wondering if anyone knows of a method for retrieving caption text from a YouTube video from java (not a .js plugin)?

[ Worst case, does anyone know of a library that allows me to programmatically interact with YouTube like a browser and allows me to click the transcript button on the screen and I can pull the transcript from there? Prowser doesn't allow click interaction and JxBrowser is $1,300+ ]

The code below works fine and gets me to all the video data so it's the last step I need help on. I've included it here in case it's helpful to anyone who needs to get this far.

// 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 = ???????

Any help is gratefully received.

Thanks,

Greg.

解决方案

We are hoping to have Captions support on Data API v3 soon. You won't need to scrape the website.

Update: This has been implemented now. The docs can be found here.

这篇关于YouTube API v3中的隐藏字幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆