不能使用Youtube的'get_video_info'来获得高质量的视频

时间:2018-02-12 23:22:05

标签: jquery html5 video youtube

由于https://jsfiddle.net/350D/uq1vvavf/

,我终于找到了在HTML5视频代码中使用Youtube视频的方法
var vid = "9PDcJeymhWM",
    streams,
    video_focused = true,
    video_tag = $("#video"),
    video_obj = video_tag.get(0);
$.getJSON("https://query.yahooapis.com/v1/public/yql", {
    q: "select * from csv where url='https://www.youtube.com/get_video_info?video_id=" + vid + "'",
    format: "json"
}, function(data) {
    if (data.query.results && !data.query.results.row.length) {
        streams = parse_youtube_meta(data.query.results.row.col0);
        video_tag.attr({
            src: streams['1080p'] || streams['720p']
        });

        document.addEventListener("visibilitychange", function() {
            video_focused = !video_focused ? video_obj.play() : video_obj.pause();
        });
    } else {
            $('pre').text('YQL request error...');
    }
});

function parse_youtube_meta(rawdata) {
    var data = parse_str(rawdata),
        streams = (data.url_encoded_fmt_stream_map + ',' + data.adaptive_fmts).split(','),
        result = {};
    $.each(streams, function(n, s) {
        var stream = parse_str(s),
            itag = stream.itag * 1,
            quality = false,
            itag_map = {
                18: '360p',
                22: '720p',
                37: '1080p',
                38: '3072p',
                82: '360p3d',
                83: '480p3d',
                84: '720p3d',
                85: '1080p3d',
                133: '240pna',
                134: '360pna',
                135: '480pna',
                136: '720pna',
                137: '1080pna',
                160: '144pna',
                264: '1440pna',
                139: "48kbps",
                140: "128kbps",
                141: "256kbps"
            };
        if (itag_map[itag]) result[itag_map[itag]] = stream.url;
    });
    return result;
};

function parse_str(str) {
    return str.split('&').reduce(function(params, param) {
        var paramSplit = param.split('=').map(function(value) {
            return decodeURIComponent(value.replace('+', ' '));
        });
        params[paramSplit[0]] = paramSplit[1];
        return params;
    }, {});
}

我现在唯一挣扎的就是提高质量。使用前面的代码片段,我只能在720p中获取我的视频。我想在1080p50的Youtube上播放它。

如何获得更高质量的视频版本? (我正在尝试使用的视频是https://www.youtube.com/watch?v=aVussY7jIdo

0 个答案:

没有答案