哔哩哔哩~bilibili API
前几天想从B站上下载一个MV放到博客上
然而下载下来的是*.blv格式...恩,video不支持这种格式
然后网上的小伙伴们告诉我可以转格式为MP4
于是我用格式工厂转换了,然而并没有什么软用
然后又有小伙伴告诉我B站支持分享到html
然而居然是Flash,手机浏览器还要下载Flash插件才能看
但是Flash可以转成MP4,然而我已经自己找到API了
通过av号
请求地址:http://api.bilibili.com/playurl?aid=
后面加上av号
但是还有带上cookie才行:buvid3=2652DF89-E27E-4837-BF1F-FD313B37F64E15572infoc
例子:
请求地址:http://api.bilibili.com/playurl?aid=6735252
请求返回:
{
"from":"local",
"result":"suee",
"format":"mp4",
"timelength":366597,
"accept_format":"flv,hdmp4,mp4",
"accept_quality":[3,2,1],
"seek_param":"start",
"seek_type":"second",
"durl":[
{
"order":1,
"length":366597,
"size":23646668,
"url":"http:\/\/cn-fjxm-dx-v-02.acgvideo.com\/vg0\/d\/02\/10975955-1.mp4?expires=1498888800&platform=pc&ssig=LyyCru-K5PSGzxvn4k-GnA&oi=2043616783&nfa=fkYkF\/LEe5xFyJPq\/bZ9eQ==&dynamic=1&hfa=2070152627"
}
],
"img":"https:\/\/i1.hdslb.com\/bfs\/archive\/d7bec4f0ccd05ab2e85da8e1389add959e68ffa8.jpg",
"cid":"http:\/\/comment.bilibili.com\/10975955.xml",
"fromview":"vupload"
}
得到视频地址了,然而这个视频地址用不了
因为里面有一个坑
把platform=pc
替换成platform=html5
就行了
这个用在番剧也是可以的
但是要先知道番剧的av号
然后我又找到了两个请求地址,可以取到番剧的av号
下面是B站一个番剧的链接
电脑:https://bangumi.bilibili.com/anime/5747/play#98574
移动设备:https://bangumi.bilibili.com/mobile/anime/5747/play/98574
我把5747
称为番剧全集号
把98574
称为番剧单集号
通过番剧全集号
请求地址:http://bangumi.bilibili.com/jsonp/seasoninfo/
+ 番剧全集号 + .ver
例子:
请求地址:http://bangumi.bilibili.com/jsonp/seasoninfo/5747.ver
请求返回:
{
"code":0,
"message":"success",
"result":{
"actor":[
{
"actor":"島﨑信長",
"actor_id":0,
"role":"藤丸立香"
},
{
"actor":"高橋李依",
"actor_id":0,"role":"玛修·基列莱特"
},
{
"actor":"杉田智和",
"actor_id":0,
"role":"列夫·莱诺尔·佛劳洛斯"
},
{
"actor":"鈴村健一",
"actor_id":0,
"role":"罗玛尼·阿其曼"
},
{
"actor":"米澤円",
"actor_id":0,
"role":"奥尔加玛丽·阿尼姆斯菲亚"
},
{
"actor":"川澄綾子",
"actor_id":0,
"role":"芙芙"
},
{
"actor":"川澄綾子",
"actor_id":0,
"role":"阿尔托莉雅·潘德拉贡"
},
{
"actor":"浅川悠",
"actor_id":0,
"role":"美杜莎"
},
{
"actor":"諏訪部順一",
"actor_id":0,
"role":"卫宫"
}
],
"alias":"Fate/Grand Order -First Order-,fate,Fate/Grand Order ‐First Order‐,FGO,Fate Grand Order,",
"allow_bp":"1",
"allow_download":"1",
"area":"日本",
"arealimit":0,
"ban_area_show":1,
"bangumi_id":"3454",
"bangumi_title":"Fate/Grand Order ‐First Order‐",
"brief":"【2016年12月31日bilibili独播】2015年。示巴所观测到的未来领域毫无前兆地消失。根据...",
"coins":"46426",
"copyright":"dujia",
"cover":"http://i0.hdslb.com/bfs/bangumi/b75c55d209d156c8631f5ceb21e5c52c834dbb60.jpg",
"danmaku_count":"218533",
"ed_jump":5,
"episodes":[
{
"av_id":"7772646",
"coins":"42994",
"cover":"http://i2.hdslb.com/bfs/archive/34b46557045ce4729bdb4536d3e27b34e562852f.jpg",
"episode_id":"98574",
"episode_status":2,
"index":"1",
"index_title":"特别篇",
"is_webplay":"0",
"mid":"928123",
"page":"1",
"up":{},
"update_time":"2016-12-31 23:00:09.0",
"webplay_url":"http://bangumi.bilibili.com/anime/5747/play#98574"
},
{
"av_id":"7408100",
"coins":"3432",
"cover":"http://i2.hdslb.com/bfs/archive/a252b0fa31fd5fd1647f6eb4784052f374995ab4.jpg",
"episode_id":"97457",
"episode_status":2,
"index":"PV",
"index_title":"",
"is_webplay":"0",
"mid":"928123",
"page":"1",
"up":{},
"update_time":"2016-12-06 21:35:16.0",
"webplay_url":"http://bangumi.bilibili.com/anime/5747/play#97457"
}
],
"evaluate":"【2016年12月31日bilibili独播】2015年。示巴所观测到的未来领域毫无前兆地消失。根据计算,发现——不,是证明了人类将于2017年灭绝。人理延续保障机构·迦勒底将“无法观测的领域”假定为人类灭绝的原因,决定执行尚处于试验阶段的第六实验。那就是回到过去的时间旅行。将术者灵子化送往过去,通过介入事象,寻找出时空奇点,究明真相或予以破坏的禁断的仪式。其名为圣杯探索——冠位指定(Grand Order)。",
"favorites":"1374580",
"is_finish":"1",
"is_started":1,
"jp_title":"Fate/Grand Order -First Order-",
"limitGroupId":340,
"newest_ep_id":"98574",
"newest_ep_index":"1",
"origin_name":"Fate/Grand Order -First Order-",
"payment":{"price":"0"},
"play_count":"9325405",
"pub_time":"2016-12-31 23:00:00",
"related_seasons":[],
"season_id":"5747",
"season_status":2,
"season_title":"特别篇",
"seasons":[],
"share_url":"http://bangumi.bilibili.com/anime/5747/",
"squareCover":"http://i0.hdslb.com/bfs/bangumi/46bc9607b64d8aa4d40d5ff9873e49b1817684b1.jpg",
"staff":"脚本:関根アユミ\n导演:難波日登志\n原作:TYPE-MOON\n人物原案:武内崇\n演出:安部元宏、塚田拓郎\n分镜:難波日登志、塚田拓郎\n音乐:川崎龍\n",
"tag2s":[],
"tags":[
{
"cover":"http://i0.hdslb.com/bfs/bangumi/2182a63b87a3078dcfc78c6a3ea4ab9042db1403.jpg",
"tag_id":"95",
"tag_name":"战斗"
},
{
"cover":"http://i0.hdslb.com/bfs/bangumi/d364c430edf2c8bbe2514237cb48ff8db7579741.jpg",
"tag_id":"136",
"tag_name":"游戏改"
}
],
"title":"Fate/Grand Order ‐First Order‐",
"total_count":"1",
"user_season":{
"attention":"0",
"bp":0,
"last_ep_index":"",
"last_time":"0",
"report_ts":0
},
"version":"other",
"viewRank":0,
"vip_quality":1,
"watchingCount":"0",
"weekday":"-1"
}
}
这样可以取到整个番剧的av号
但是经常返回失败
通过番剧单集号
请求地址:http://bangumi.bilibili.com/web_api/episode/
+ 番剧单机号 + .json
例子:
请求地址:http://bangumi.bilibili.com/web_api/episode/98574.json
请求返回:
{
"code":0,
"message":"success",
"result":{
"upInfo":{
"face":"http://i2.hdslb.com/bfs/face/60a9153609998b04301dc5b8ed44c41b537a2268.jpg",
"mid":928123,
"sign":"",
"uname":"哔哩哔哩番剧",
"vip":{
"vipStatus":0,
"vipType":0
}
},
"upVipInfo":{
"vipStatus":0,
"vipType":0
},
"currentEpisode":{
"avId":"7772646",
"bangumiTitle":"",
"cover":"http://i2.hdslb.com/bfs/archive/34b46557045ce4729bdb4536d3e27b34e562852f.jpg",
"danmaku":"12744209",
"episodeId":98574,
"index":"1",
"indexTitle":"1",
"isDelete":"0",
"longTitle":"特别篇",
"mid":"928123",
"page":"1",
"pubDate":"2016-12-31",
"pubTime":"23:00",
"published":"1",
"push":"1",
"seasonId":5747,
"status":2,
"weekday":-1
}
}
}
用这些方法,我自己再整理了一个
请求地址:
请求参数:
/* 请求参数
* @id
* @type
* a av号
* b 番剧全集号
* c 番剧单集号
* @callback 回调函数名,可空
* @var 变量名,可空
*
* callback 与 var 最多填写一个
*/
下载地址:bilibili.zip
代码:
<?php
/* 请求参数
* @id
* @type
* a av号
* b 番剧全集号
* c 番剧单集号
* @callback 回调函数名,可空
* @var 变量名,可空
*
* callback 与 var 最多填写一个
*/
function bilibili_get_data($url){
$cookie = 'fts=1498895556; buvid3=2652DF89-E27E-4837-BF1F-FD313B37F64E15572infoc; finger=81df3ec0; sid=j5akrgf8; biliMzIsnew=1; biliMzTs=null;';
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_COOKIE,$cookie);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
function bilibili_get_by_av($id){
$url = 'http://api.bilibili.com/playurl?aid=' . $id;
$json = bilibili_get_data($url);
$data = json_decode($json);
$result = new stdClass();
$result -> av_id = $id;
$result -> url = str_replace('platform=pc','platform=html5',$data -> durl[0] -> url);
$result -> format = $data -> format;
$result -> length = $data -> timelength;
$result -> size = $data -> durl[0] -> size;
$result -> img = $data -> img;
$result -> barrage = $data -> cid;
return $result;
}
if(empty($_GET['id']) || empty($_GET['type'])){
die('{"error":"参数错误!"}');
}
$id = $_GET['id'];
$type = $_GET['type'];
/*$id = '6735252';
$type = 'a';*/
/*$id = '5747';
$type = 'b';*/
/*$id = '98574';
$type = 'c';*/
switch($type){
case 'a':
$return = bilibili_get_by_av($id);
break;
case 'b':
$url = 'http://bangumi.bilibili.com/jsonp/seasoninfo/' . $id . '.ver?jsonp:jsonp&_=' . time();
$json = bilibili_get_data($url);
$json = str_replace('seasonListCallback(','',$json);
$json = str_replace(');','',$json);
$data = json_decode($json);
if(!$data){
die('{"error":"服务器抽风啦!"}');
}
$result = new stdClass();
$result -> bangumi_id = $id;
$result -> title = $data -> result -> title;
$result -> total_count = $data -> result -> total_count;
$result -> episodes = new stdClass();
foreach ($data -> result -> episodes as $value){
$index = $value -> index;
$result -> episodes -> $index = bilibili_get_by_av($value -> av_id);
$result -> episodes -> $index -> title = $value -> index_title;
}
$return = $result;
break;
case 'c':
$url = 'http://bangumi.bilibili.com/web_api/episode/' . $id . '.json';
$json = bilibili_get_data($url);
$data = json_decode($json);
$result = new stdClass();
$result = bilibili_get_by_av($data -> result -> currentEpisode -> avId);
$result -> index = $data -> result -> currentEpisode -> index;
$return = $result;
break;
default:
die('{"error":"参数错误!"}');
}
//$_return = stripslashes(json_encode($return,JSON_UNESCAPED_UNICODE));
if (!empty($_GET['callback'])){
header("Content-type: text/javascript; charset=utf-8");
echo $_GET['callback'] . '(' . stripslashes(json_encode($return,JSON_UNESCAPED_UNICODE)) . ');';
}else if(!empty($_GET['var'])){
header("Content-type: text/javascript; charset=utf-8");
echo $_GET['var'] . '=' . stripslashes(json_encode($return,JSON_UNESCAPED_UNICODE)) . ';';
}else{
header("Content-type: text/json; charset=utf-8");
echo stripslashes(json_encode($return,JSON_UNESCAPED_UNICODE));
}
?>
更新
本方法已废,推荐:哔哩哔哩API