【问题标题】:Get YouTube video height via API通过 API 获取 YouTube 视频高度
【发布时间】:2023-03-30 03:05:01
【问题描述】:

我如何获得视频高度,例如。像Stats for nerds 中显示的高度?视频的宽度可能为 1920 像素,但高度可能小于 1080 像素,我想通过 ajaxAPI 获得该高度

【问题讨论】:

    标签: javascript ajax youtube-api jsonp


    【解决方案1】:

    最简单的方法是使用oembed

    例如http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch%3Fv%3DbDOYN-6gdRE&format=json 然后杰森给你

    {"height": 344, "title": "Auto-Tune the News #8: dragons. geese. Michael Vick. (ft. T-Pain)", "author_url": "http:\/\/www.youtube.com\/user\/schmoyoho", "thumbnail_height": 360, "version": "1.0", "provider_url": "http:\/\/www.youtube.com\/", "type": "video", "width": 459, "provider_name": "YouTube", "thumbnail_url": "http:\/\/i.ytimg.com\/vi\/bDOYN-6gdRE\/hqdefault.jpg", "thumbnail_width": 480, "html": "\u003ciframe width=\"459\" height=\"344\" src=\"http:\/\/www.youtube.com\/embed\/bDOYN-6gdRE?feature=oembed\" frameborder=\"0\" allowfullscreen\u003e\u003c\/iframe\u003e", "author_name": "schmoyoho"}
    

    更多信息http://apiblog.youtube.com/2009/10/oembed-support.html

    http://oembed.com/#section5

    【讨论】:

    • 这不适用于所有视频。例如此视频:youtube.com/watch?v=-NschES-8e0 尺寸为 1920 x 844,因此高度应为 480 * 844 / 1920 = 211px 但显示为 270px @ceasar
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    • 2012-03-19
    • 2017-12-10
    • 2019-09-12
    • 1970-01-01
    • 1970-01-01
    • 2014-11-20
    相关资源
    最近更新 更多