如何识别无法嵌入文件的 YouTube 视频

How to identify the YouTube videos that can't embed on file

我有一个移动应用程序,可以在网络视图中嵌入一些 youtube 视频。

问题是,使用 YouTube 数据 API v3,我得到了一个要显示的“可嵌入”项目列表。但是他们中的一些人说“视频不可用”。当我在 jsfiddle 或域或某种 网络服务器 上粘贴相同的代码时,它 可以工作 但是当从 读取时文件 或通过 webview 导航到 html 字符串,它 不起作用

我的问题是,如果我尝试 嵌入 的视频实际上是 可嵌入 来自 file 还是没有?

我检查了每个视频的 YouTube 数据 API v3 输出,但我找不到任何有意义的信息。

是否有其他类型的网络 api 或 http 端点,我可以检查视频是否正确?

如果没有,我如何以编程方式从 youtube 播放器获取数据以查看它是否成功嵌入?

无法嵌入文件的youtube视频示例列表如下:

https://www.youtube.com/watch?v=TjI3bzvbCU4
https://www.youtube.com/watch?v=QWveXdj6oZU
https://www.youtube.com/watch?v=KEEnap_h8cs

注意:我的问题是识别 unimbeddable 项目,因为我想从 file(在移动应用程序中)。因此,尝试从 网络服务器 加载 它不是 我的选择。

注 2:这些块不是区域性的,它们是基于域的。

我发现这个entry on Google Support可能解释了为什么视频不可用。

引用:

Actually found the issue here. The videos that were displaying this on embed had "Copyrighted" music playing in the background. YouTube apparently does not play videos like this while embedded. We had our user remove the audio and re-uploaded the video and everything is working fine now.

Hope this helps somebody.

可能,YouTube 数据 API 未更新以匹配视频 uploader/owner 和 YouTube 允许嵌入视频的准则设置的值。

对于这种情况,我建议您 post 在 Issue Tracker 上买票。

如果您进入视频的源代码 - 如:view-source:https://www.youtube.com/embed/TjI3bzvbCU4,您可以找到一个名为 previewPlayabilityStatus 的 属性如下:

"previewPlayabilityStatus": {
    "status": "UNPLAYABLE",
    "reason": "Video no disponible",
    "errorScreen": {
        "playerErrorMessageRenderer": {
            "reason": {
                "runs": [{
                    "text": "Video no disponible"
                }]
            },
            "proceedButton": {
                "buttonRenderer": {
                    "style": "STYLE_DEFAULT",
                    "size": "SIZE_DEFAULT",
                    "isDisabled": false,
                    "text": {
                        "simpleText": "Mirar en YouTube"
                    },
                    "navigationEndpoint": {
                        "clickTrackingParams": "CAEQ8FsiEwiT6sGfg6j3AhVG25QJHY96Amgu003d"

此信息可通过此端点获得:https://www.youtube.com/get_video_info?video_id=TjI3bzvbCU4,但是,现在 HTTP ERROR 410返回。

遗憾的是,此信息未提供有关视频不可用原因的任何有用数据 - 尽管 response of the YouTube Data API says is is embeddable:

"status": {
    "uploadStatus": "processed",
    "privacyStatus": "public",
    "license": "youtube",
    "embeddable": true,
    "publicStatsViewable": true,
    "madeForKids": false
  },

您还可以使用 嵌入 YouTube 视频 - 我在这里分享它是因为我觉得它很有趣。

YouTube 数据 API v3 provides a not working embed page while it says that it is.

而像这个这样的其他视频 (ZqYezph-hgg) it works.

所以我的想法是检索 https://www.youtube.com/embed/VIDEO_ID 并查看视频是否无法播放,例如:

curl -s https://www.youtube.com/embed/TjI3bzvbCU4 | grep "UNPLAYABLE" | wc -l

Returns1,因此该视频无法播放。

curl -s https://www.youtube.com/embed/ZqYezph-hgg | grep "UNPLAYABLE" | wc -l

Returns0,所以这个视频可以播放。