The browser analyzes the live broadcast source address of station B
0. Preface
Previously, I only knew that station B was on-demand. Many up hosts can upload their own videos and have never watched the live broadcast of station B. Now let’s grab its live source. We still analyze from the browser 授人以鱼不如授人以渔
and teach you how to crawl the live source, even if it fails.
1. Search live source
Open a live among which, F12
first check whether the requested page address into the search found no ( m3u8/flv
), then it is ajax come: the
next to check ajax
and found that the first ajax
return address:
Tested, simply host
and base_url
The first half of the file can be spliced together without the following parameters. Use the online m3u8 test website to test the playback successfully:
https://d1--cn-gotcha204.bilivideo.com/live-bvc/711838/live_222103174_4331333_1500/index.m3u8
2. Browser request process analysis and ideas
Now that the request is found, the simulation is convenient. Let's first look at the request address and parameters:
Request Method: GET
(very strange, it is a GET request here)
Request URL: https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo
Query String:
- room_id: 8178490
- no_playurl: 0
- mask: 1
- qn: 0
- platform: web
- protocol: 0,1
- format: 0,2
- codec: 0,1
At a glance room_id
, everything else is fixed. This is too simple.
First test it with Postman, it is completely OK:
3. Simulation implementation
Server source code (PHP):
<?php
header('Content-Type:application/json; charset=utf-8');
header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin');
$params = [
"room_id" => $_POST["room_id"],
"no_playurl" => 0,
"mask" => 0,
"qn" => 0,
"platform" => "web",
"protocol" => "0,1",
"format" => "0,2",
"codec" => "0,1",
];
$res = file_get_contents('https://api.live.bilibili.com/xlive/web-room/v2/index/getRoomPlayInfo?' . http_build_query($params));
echo $res;
exit;
Front end H5:
$.ajax({
type: 'post',
url: 'http://xxx/player/bilibli/url.php',
data: {
room_id: 8178490,
},
success: function(res){
var data = res.data.playurl_info.playurl.stream[1].format[0].codec[1];
var url = data.url_info[0].host + data.base_url.split("?")[0];
console.log(url);
}
});
The console will print out the live source address:https://d1--cn-gotcha204.bilivideo.com/live-bvc/481520/live_222103174_4331333_1500/index.m3u8
4. Integrated player
Please refer to the previous articles to deal with this by yourself, you can use it ckplayer
, videojs
etc. The player I tested is slow to load, or it is the VLC media player
fastest to use it directly
5. Summary
The live source of station B is not difficult, and the parameters are not encrypted. It is simpler than other websites. The key is to find the location of the live source, and everything else is easy.