mirror of
https://github.com/SocialSisterYi/bilibili-API-collect.git
synced 2024-12-29 14:00:09 +08:00
267 lines
15 KiB
Markdown
267 lines
15 KiB
Markdown
# 视频流URL
|
||
|
||
## 获取视频流URL
|
||
|
||
> http://api.bilibili.com/x/player/playurl
|
||
|
||
*方式:GET*
|
||
|
||
获取会员专属视频及720P以上清晰度视频时需要登录(SESSDATA)
|
||
|
||
会员专属及高帧率(码率)视频需要带有大会员的账号token(SESSDATA)
|
||
|
||
获取的url有效时间为120min,超时失效需要重新获取
|
||
|
||
**部分视频**会有**分段**,需要特别注意
|
||
|
||
若视频有分P,仅为单P的视频的url,换P则需更换CID重新获取
|
||
|
||
**参数:**
|
||
|
||
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
|
||
| ------ | ---- | -------------- | ------ | ------------------------------------------------------------ |
|
||
| aid | url | 视频avID | 非必要 | avID与bvID任选一个 |
|
||
| bvid | url | 视频bvID | 非必要 | avID与bvID任选一个 |
|
||
| cid | url | 视频CID | 必要 | |
|
||
| qn | url | 视频清晰度选择 | 非必要 | 未登录默认32(480P)<br />登录默认64(720P)<br />**值含义见下表** |
|
||
|
||
分辨率代码:
|
||
|
||
| 值 | 含义 |
|
||
| ---- | ---------------------- |
|
||
| 16 | 360P 流畅 |
|
||
| 32 | 480P 清晰 |
|
||
| 64 | 720P 高清(登录) |
|
||
| 74 | 720P60 高清(大会员) |
|
||
| 80 | 1080P 高清(登录) |
|
||
| 112 | 1080P+ 高清(大会员) |
|
||
| 116 | 1080P60 高清(大会员) |
|
||
| 120 | 4K 超清(大会员) |
|
||
|
||
**json回复:**
|
||
|
||
根对象:
|
||
|
||
| 字段 | 类型 | 内容 | 备注 |
|
||
| ------- | ----------------------------- | -------- | ---------------------------------------------- |
|
||
| code | num | 返回值 | 0:成功 <br />-400:请求错误<br />-404:无视频 |
|
||
| message | str | 错误信息 | 默认为0 |
|
||
| ttl | num | 1 | 作用尚不明确 |
|
||
| data | 有效时:obj<br />无效时:null | 数据本体 | |
|
||
|
||
`data`对象:
|
||
|
||
| 字段 | 类型 | 内容 | 备注 |
|
||
| ------------------ | ------ | ------------------------ | ---------------------------------------- |
|
||
| from | str | local | 作用尚不明确 |
|
||
| result | str | suee | 作用尚不明确 |
|
||
| message | str | 空 | 作用尚不明确 |
|
||
| quality | num | 视频分辨率代码 | **值含义见上表** |
|
||
| format | str | 视频格式 | |
|
||
| timelength | num | 视频长度 | 单位为毫秒<br />不同分辨率可能有略微差异 |
|
||
| accept_format | str | 视频支持的分辨率的格式 | |
|
||
| accept_description | arrary | 视频支持的分辨率列表 | |
|
||
| accept_quality | arrary | 视频支持的分辨率代码列表 | **值含义见上表** |
|
||
| video_codecid | num | ??? | 作用尚不明确 |
|
||
| seek_param | str | start | 作用尚不明确 |
|
||
| seek_type | str | offset | 作用尚不明确 |
|
||
| durl | arrary | 视频流地址信息 | |
|
||
|
||
`data`中的`accept_description`数组:
|
||
|
||
| 项 | 类型 | 内容 | 备注 |
|
||
| ---- | ---- | ----------- | ---- |
|
||
| 0 | str | 分辨率1 | |
|
||
| n | str | 分辨率(n+1) | |
|
||
| …… | str | …… | …… |
|
||
|
||
`data`中的`accept_quality`数组:
|
||
|
||
| 项 | 类型 | 内容 | 备注 |
|
||
| ---- | ---- | --------------- | ---- |
|
||
| 0 | str | 分辨率代码1 | |
|
||
| n | str | 分辨率代码(n+1) | |
|
||
| …… | str | …… | …… |
|
||
|
||
`data`中的`durl`数组:
|
||
|
||
| 项 | 类型 | 内容 | 备注 |
|
||
| ---- | ---- | ----------------- | ---- |
|
||
| 0 | obj | 视频分段1信息 | |
|
||
| n | obj | 视频分段(n+1)信息 | |
|
||
| …… | obj | …… | |
|
||
|
||
`data`中的`durl`数组中的对象:
|
||
|
||
| 字段 | 类型 | 内容 | 备注 |
|
||
| ---------- | ------ | ------------ | ---------------------------------- |
|
||
| order | num | 视频分段序号 | 某些视频会分为多个片段 |
|
||
| length | num | 视频长度 | 单位为毫秒 |
|
||
| size | num | 视频大小 | 单位为Byte |
|
||
| ahead | str | 空 | 作用尚不明确 |
|
||
| vhead | str | 空 | 作用尚不明确 |
|
||
| url | str | 视频流url | **重要**<br />链接有效时间为120min |
|
||
| backup_url | arrary | 备用视频流 | |
|
||
|
||
`data`中的`durl`数组中的对象中的`backup_url`数组:
|
||
|
||
| 项 | 类型 | 内容 | 备注 |
|
||
| ---- | ---- | ------------- | ---------------- |
|
||
| 0 | str | 备用视频流url | 有效时间为120min |
|
||
|
||
**示例:**
|
||
|
||
**视频无分段时**
|
||
|
||
获取视频`av99999999`/`BV1y7411Q7Eq`中的1P(CID=`171776208`)的视频流url,清晰度为1080P+
|
||
|
||
http://api.bilibili.com/x/player/playurl?avid=99999999&cid=171776208&qn=112
|
||
|
||
同http://api.bilibili.com/x/player/playurl?bvid=BV1y7411Q7Eq&cid=171776208&qn=112
|
||
|
||
```json
|
||
{
|
||
"code": 0,
|
||
"message": "0",
|
||
"ttl": 1,
|
||
"data": {
|
||
"from": "local",
|
||
"result": "suee",
|
||
"message": "",
|
||
"quality": 112,
|
||
"format": "hdflv2",
|
||
"timelength": 283701,
|
||
"accept_format": "hdflv2,flv,flv720,flv480,mp4",
|
||
"accept_description": [
|
||
"高清 1080P+",
|
||
"高清 1080P",
|
||
"高清 720P",
|
||
"清晰 480P",
|
||
"流畅 360P"
|
||
],
|
||
"accept_quality": [
|
||
112,
|
||
80,
|
||
64,
|
||
32,
|
||
16
|
||
],
|
||
"video_codecid": 7,
|
||
"seek_param": "start",
|
||
"seek_type": "offset",
|
||
"durl": [
|
||
{
|
||
"order": 1,
|
||
"length": 283701,
|
||
"size": 219827828,
|
||
"ahead": "",
|
||
"vhead": "",
|
||
"url": "http://upos-sz-mirrorhw.bilivideo.com/upgcxcode/08/62/171776208/171776208-1-112.flv?e=ig8euxZM2rNcNbhMnwhVhwdlhzK3hzdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1589565412&gen=playurl&os=hwbv&oi=606631998&trid=e0fa5f9a7610440a871279a28fae85aau&platform=pc&upsig=5f469cb4c190ed54b89bd40cc37eddff&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=80000000",
|
||
"backup_url": [
|
||
"http://upos-sz-mirrorks3c.bilivideo.com/upgcxcode/08/62/171776208/171776208-1-112.flv?e=ig8euxZM2rNcNbhMnwhVhwdlhzK3hzdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1589565412&gen=playurl&os=ks3cbv&oi=606631998&trid=e0fa5f9a7610440a871279a28fae85aau&platform=pc&upsig=914ef921c5258e067c382601a4b1f81c&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=40000000"
|
||
]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
```
|
||
|
||
**视频有分段时**
|
||
|
||
获取视频`av138284`/`BV1Tx411w7PX`中的2P(CID=`872498`)的视频流url,清晰度为1080P
|
||
|
||
http://api.bilibili.com/x/player/playurl?avid=138284&cid=872498&qn=80
|
||
|
||
同http://api.bilibili.com/x/player/playurl?bvid=BV1Tx411w7PX&cid=872498&qn=80
|
||
|
||
```json
|
||
{
|
||
"code": 0,
|
||
"message": "0",
|
||
"ttl": 1,
|
||
"data": {
|
||
"from": "local",
|
||
"result": "suee",
|
||
"message": "",
|
||
"quality": 16,
|
||
"format": "flv360",
|
||
"timelength": 1437918,
|
||
"accept_format": "flv,flv720,flv480,flv360",
|
||
"accept_description": [
|
||
"高清 1080P",
|
||
"高清 720P",
|
||
"清晰 480P",
|
||
"流畅 360P"
|
||
],
|
||
"accept_quality": [
|
||
80,
|
||
64,
|
||
32,
|
||
16
|
||
],
|
||
"video_codecid": 7,
|
||
"seek_param": "start",
|
||
"seek_type": "offset",
|
||
"durl": [
|
||
{
|
||
"order": 1,
|
||
"length": 364417,
|
||
"size": 23018310,
|
||
"ahead": "",
|
||
"vhead": "",
|
||
"url": "http://upos-sz-mirrorhw.bilivideo.com/upgcxcode/98/24/872498/872498-1-15.flv?e=ig8euxZM2rNcNbRB7zUVhoM17WuBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=hwbv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=f99db2dc9b8c65c245515b29b9ca8b16&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=80000000",
|
||
"backup_url": [
|
||
"http://upos-sz-mirrorks3c.bilivideo.com/upgcxcode/98/24/872498/872498-1-15.flv?e=ig8euxZM2rNcNbRB7zUVhoM17WuBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=ks3cbv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=74d0d62697364346f88d9c39430ce23c&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=40000000"
|
||
]
|
||
},
|
||
{
|
||
"order": 2,
|
||
"length": 364395,
|
||
"size": 23694756,
|
||
"ahead": "",
|
||
"vhead": "",
|
||
"url": "http://upos-sz-mirrorcos.bilivideo.com/upgcxcode/98/24/872498/872498-2-15.flv?e=ig8euxZM2rNcNbRjhbUVhoM17bNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=cosbv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=308c87c55f3325bdaac2a3e8632948ee&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=80000000",
|
||
"backup_url": [
|
||
"http://upos-sz-mirrorks3c.bilivideo.com/upgcxcode/98/24/872498/872498-2-15.flv?e=ig8euxZM2rNcNbRjhbUVhoM17bNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=ks3cbv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=eb8f043e0f36f82ab9c62fd002143438&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=40000000"
|
||
]
|
||
},
|
||
{
|
||
"order": 3,
|
||
"length": 352333,
|
||
"size": 22835734,
|
||
"ahead": "",
|
||
"vhead": "",
|
||
"url": "http://upos-sz-mirrorhw.bilivideo.com/upgcxcode/98/24/872498/872498-3-15.flv?e=ig8euxZM2rNcNbRjhwdVhoM17bdVhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=hwbv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=2685b7649f4bb6eb90f986f125432d78&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=80000000",
|
||
"backup_url": [
|
||
"http://upos-sz-mirrorks3c.bilivideo.com/upgcxcode/98/24/872498/872498-3-15.flv?e=ig8euxZM2rNcNbRjhwdVhoM17bdVhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=ks3cbv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=922543bfb26184f901187bf9c39c69b2&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=40000000"
|
||
]
|
||
},
|
||
{
|
||
"order": 4,
|
||
"length": 356773,
|
||
"size": 23466279,
|
||
"ahead": "",
|
||
"vhead": "",
|
||
"url": "http://upos-sz-mirrorkodo.bilivideo.com/upgcxcode/98/24/872498/872498-4-15.flv?e=ig8euxZM2rNcNbRjhbUVhoM17bNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=kodobv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=9d29707faf012797ef2b6de21523fcf2&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=80000000",
|
||
"backup_url": [
|
||
"http://upos-sz-mirrorks3c.bilivideo.com/upgcxcode/98/24/872498/872498-4-15.flv?e=ig8euxZM2rNcNbRjhbUVhoM17bNBhwdEto8g5X10ugNcXBlqNxHxNEVE5XREto8KqJZHUa6m5J0SqE85tZvEuENvNo8g2ENvNo8i8o859r1qXg8xNEVE5XREto8GuFGv2U7SuxI72X6fTr859r1qXg8gNEVE5XREto8z5JZC2X2gkX5L5F1eTX1jkXlsTXHeux_f2o859IB_&uipk=5&nbs=1&deadline=1589874109&gen=playurl&os=ks3cbv&oi=1965551630&trid=ceac015d41e04a7b90ec972db710524fu&platform=pc&upsig=9ad4524d31c8d9695ae07b400b73ed29&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=40000000"
|
||
]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
```
|
||
|
||
## 视频的获取
|
||
|
||
将`data`.`durl`.`[1-n]`.`url`或`data`.`durl`.`[1-n]`.`backup_url`.`[0]`中的内容作为url进行GET操作, 如果有多个视频, 需要手动合并处理
|
||
|
||
需要验证Header中`referer`在 `http://www.bilibili.com`或`https://www.bilibili.com`域名下
|
||
|
||
**无referer或错误的情况会返回403 Forbidden**故无法获取
|
||
|
||
**以上述视频url为例:**
|
||
|
||
wget --referer "http://www.bilibili.com" "http://upos-sz-mirrorhw.bilivideo.com/upgcxcode/08/62/171776208/171776208-1-112.flv?e=ig8euxZM2rNcNbhMnwhVhwdlhzK3hzdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1589565412&gen=playurl&os=hwbv&oi=606631998&trid=e0fa5f9a7610440a871279a28fae85aau&platform=pc&upsig=5f469cb4c190ed54b89bd40cc37eddff&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,platform&mid=293793435&logo=80000000" -O video.flv
|
||
|
||
回复正文将返回一个flv文件的数据 |