B站直播源获取

这个变量保存了一些直播间初始信息

window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.playurl_info.playurl.stream

进入直播间,F12在控制台执行:

function getUrl(params) {
    // let stream = window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.playurl_info.playurl.stream
    let stream = params
    for (let i = 0; i < stream.length; i++){
        now_proc = stream[i]
        console.log(now_proc.protocol_name)
        for (let j = 0; j < now_proc.format.length; j++) {
            now_format = now_proc.format[j]
            console.log(now_format.format_name)
            for (let k = 0; k < now_format.codec.length; k++) {
                now_codec = now_format.codec[k]
                console.log(now_codec.codec_name)
                console.log(now_codec.current_qn, now_codec.accept_qn)
                for(let l = 0; l < now_codec.url_info.length; l++) {
                    now_url_info = now_codec.url_info[l]
                    url = now_url_info.host + now_codec.base_url + now_url_info.extra
                    console.log(url)
                }
            }
        }
    }
}

function get_max_qn(params) {
    all_qn = new Set()
    let stream = params
    for (let i = 0; i < stream.length; i++){
        now_proc = stream[i]
        for (let j = 0; j < now_proc.format.length; j++) {
            now_format = now_proc.format[j]
            for (let k = 0; k < now_format.codec.length; k++) {
                now_codec = now_format.codec[k]
                for(let l = 0; l < now_codec.accept_qn.length; l++) {
                    now_accept_qn = now_codec.accept_qn[l]
                    all_qn.add(now_accept_qn)
                }
            }
        }
    }
    return Math.max(...all_qn)    
}

fetch(`https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?room_id=${window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.room_id}&protocol=0,1&format=0,1,2&codec=0,1&qn=${get_max_qn(window.__NEPTUNE_IS_MY_WAIFU__.roomInitRes.data.playurl_info.playurl.stream)}&platform=web&ptype=8&dolby=5&panorama=1`, {
  "referrerPolicy": "no-referrer-when-downgrade",
  "body": null,
  "method": "GET",
  "mode": "cors",
  "credentials": "include"
}).then(response => response.json()).then(data => getUrl(data.data.playurl_info.playurl.stream));
posted @ 2022-12-11 12:26  王冰冰  阅读(1510)  评论(0编辑  收藏  举报