gpt4 book ai didi

php - 确定 YouTube 视频是否为宽屏?

转载 作者:可可西里 更新时间:2023-11-01 12:38:08 26 4
gpt4 key购买 nike

我想确切地知道 YouTube 视频是宽屏的还是不使用 v3 API。有很多旧视频有 4:3 的比例,所以我需要检测这一点。

这可以通过 API v2 实现,不过现在已经正式退役了。这是 API v3 docs .

API 调用看起来像这样:

https://www.googleapis.com/youtube/v3/videos?id=[VIDEOID]&part=snippet&key=[DEVELOPERKEY]

此外,缩略图数据始终返回 4:3 的尺寸,因此这无济于事。这是一个例子:

[thumbnails] => Array
(
[default] => Array
(
[url] => https://i.ytimg.com/vi/nnnnnnnnn/default.jpg
[width] => 120
[height] => 90
)
...
)

有什么想法吗?

(我目前通过分析缩略图中的像素来破解 4:3 视频中明显的黑条。)

这是一个 4:3 比例的示例视频:

https://www.youtube.com/watch?v=zMJ-Dl4eJu8 (老武打视频)

martial arts in 4:3

16:9 中的一个:

https://www.youtube.com/watch?v=7O2Jqi-LhEI (一个新的锻炼视频)

workout video


更新:一个有前途的建议是探索fileDetails.videoStreams[].aspectRatio,但似乎只有视频所有者可以使用。否则请求 fileDetails 会导致

The request cannot access user rating information. This error may occur because the request is not properly authorized

最佳答案

如果您愿意使用 API V3 以外的其他方法,那么我相信可以通过 oEmbed API 实现。

http://www.youtube.com/oembed?url={VIDEO_URL}&format=json

像这样:

http://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=zMJ-Dl4eJu8&format=json

会产生:

{  
"provider_url":"https:\/\/www.youtube.com\/",
"thumbnail_url":"https:\/\/i.ytimg.com\/vi\/zMJ-Dl4eJu8\/hqdefault.jpg",
"thumbnail_height":360,
"height":344,
"type":"video",
"version":"1.0",
"html":"\u003ciframe width=\"459\" height=\"344\" src=\"https:\/\/www.youtube.com\/embed\/zMJ-Dl4eJu8?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e",
"author_name":"hadronica2",
"width":459,
"provider_name":"YouTube",
"author_url":"https:\/\/www.youtube.com\/user\/hadronica2",
"title":"Aikido - Kazuo Chiba sensei - 1\u00ba part",
"thumbnail_width":480
}

在您给出的示例中,输出如下:

http://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=zMJ-Dl4eJu8&format=json

Width: 459
Height: 344
Ratio: w/h = 1.3343 = 4:3 (ish)

http://www.youtube.com/oembed?url=https://www.youtube.com/watch?v=zMJ-Dl4eJu8&format=json

Width: 480
Height: 270
Ratio: w/h = 1.7777 = 16/9

这似乎适用于您提供的示例。

关于php - 确定 YouTube 视频是否为宽屏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31188142/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com