Do it yourself
导入库
os
- 与操作系统交互re
- 正则表达式操作json
- 处理 JSON 格式requests
- 网络操作biliapis
- 调用 B 站 APIbilicodes
- B 站 API 使用的枚举值
按照 PEP 8,推荐的导入库的顺序应该是
标准库 - 三方库 - 本地库
,且每组间有一个空行
import os
import re
import json
import requests
import biliapis
import bilicodes
2
3
4
5
6
7
8
就先暂时使用字符串代替一下用户输入吧。因为这里只是梳理一下流程。
使用正则表达式提取用户输入中的 avID
或 bvID
。(代码中所示的表达式可能不是最优解,请自行判断)
其实现在复杂的正则表达式更多让 AI 帮忙写
bvID 优先,因为 bvID 中有时候会碰巧出现
avXXX
这样的字符组合。
将用于匹配 avID
、 bvID
的正则表达式字符串预编译。
REGEX_BVID = re.compile(r"(BV[a-zA-Z0-9]{10})", re.I)
REGEX_AVID = re.compile(r"av([0-9]+)", re.I)
2
user_input = "https://www.bilibili.com/video/BV1q3411E7P7/"
bvids = REGEX_BVID.findall(user_input)
avids = REGEX_AVID.findall(user_input)
ids = {}
if bvids:
ids["bvid"] = bvids[0]
elif avids:
ids["avid"] = int(avids[0])
else:
# 这里直接raise,写在函数里时记得用return代替
raise RuntimeError("No valid id detected")
2
3
4
5
6
7
8
9
10
11
调用 API 请求数据
看不懂这里的 **ids
?去看补注!
video_data = biliapis.get_video_detail(**ids)
print(json.dumps(video_data, ensure_ascii=False, indent=4))
2
Output
{
"code": 0,
"message": "0",
"ttl": 1,
"data": {
"bvid": "BV1q3411E7P7",
"aid": 423736658,
"videos": 2,
"tid": 201,
"tname": "科学科普",
"copyright": 1,
"pic": "http://i1.hdslb.com/bfs/archive/e4cae24d721b65e59176b701f9e338bc9be536d8.jpg",
"title": "一位学生在10分钟内读完了31页线性代数,这是他大脑发生的变化",
"pubdate": 1643557557,
"ctime": 1643557557,
"desc": "A Student Finished 31 Pages Of Linear Algebra In 10 Minutes.\r\nThis Is What Happens To His Brain.\r\n模仿chubbyemu的整活视频()",
"desc_v2": [
{
"raw_text": "A Student Finished 31 Pages Of Linear Algebra In 10 Minutes.\r\nThis Is What Happens To His Brain.\r\n模仿chubbyemu的整活视频()",
"type": 1,
"biz_id": 0
}
],
"state": 0,
"duration": 398,
"mission_id": 351469,
"rights": {
"bp": 0,
"elec": 0,
"download": 1,
"movie": 0,
"pay": 0,
"hd5": 1,
"no_reprint": 1,
"autoplay": 1,
"ugc_pay": 0,
"is_cooperation": 0,
"ugc_pay_preview": 0,
"no_background": 0,
"clean_mode": 0,
"is_stein_gate": 0,
"is_360": 0,
"no_share": 0,
"arc_pay": 0,
"free_watch": 0
},
"owner": {
"mid": 82513053,
"name": "F1非法字符",
"face": "https://i0.hdslb.com/bfs/face/783c40298424a85eec3d63ae4aeebca278bd0f0b.jpg"
},
"stat": {
"aid": 423736658,
"view": 1094143,
"danmaku": 2913,
"reply": 1600,
"favorite": 13258,
"coin": 11028,
"share": 6945,
"now_rank": 0,
"his_rank": 0,
"like": 56717,
"dislike": 0,
"evaluation": "",
"vt": 0
},
"argue_info": {
"argue_msg": "",
"argue_type": 0,
"argue_link": ""
},
"dynamic": "",
"cid": 498005170,
"dimension": {
"width": 3840,
"height": 2160,
"rotate": 0
},
"premiere": null,
"teenage_mode": 0,
"is_chargeable_season": false,
"is_story": false,
"is_upower_exclusive": false,
"is_upower_play": false,
"is_upower_preview": false,
"enable_vt": 0,
"vt_display": "",
"no_cache": false,
"pages": [
{
"cid": 498005170,
"page": 1,
"from": "vupload",
"part": "熟肉",
"duration": 199,
"vid": "",
"weblink": "",
"dimension": {
"width": 3840,
"height": 2160,
"rotate": 0
},
"first_frame": "http://i2.hdslb.com/bfs/storyff/n220130152l4jjnekxs22fximvf1o3o9_firsti.jpg"
},
{
"cid": 498005570,
"page": 2,
"from": "vupload",
"part": "为某些勇士准备的生肉",
"duration": 199,
"vid": "",
"weblink": "",
"dimension": {
"width": 3840,
"height": 2160,
"rotate": 0
},
"first_frame": "http://i1.hdslb.com/bfs/storyff/n220130156scqg4mbvpwx29mpll975qy_firsti.jpg"
}
],
"subtitle": {
"allow_submit": false,
"list": []
},
"is_season_display": false,
"user_garb": {
"url_image_ani_cut": ""
},
"honor_reply": {},
"like_icon": "",
"need_jump_bv": false,
"disable_show_up_info": false,
"is_story_play": 0
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
从中我们可以得到 cid
(我猜是 content ID
的简写),接下来我们可以用 cid
取到视频流。当然也可以做一些别的事情比如下载弹幕文件(xml 格式)。
有相当一部分视频拥有多个分 P(见上框运行结果中的 $.data.pages
),每个分 P 都对应着一个 cid
,可以让用户再做一个选择。
对于 JSON 格式,也有像是
XPath
对于 XML 那样的JSONPath
表达式可以用。
pages: list[dict] = video_data["data"]["pages"]
user_choice = 0 # 假定用户选择了第1个分P
cid = pages[user_choice]["cid"]
stream = biliapis.get_video_stream_dash(cid=cid, **ids)
print(json.dumps(stream, ensure_ascii=False, indent=4))
2
3
4
5
6
Output
{
"code": 0,
"message": "0",
"ttl": 1,
"data": {
"from": "local",
"result": "suee",
"message": "",
"quality": 32,
"format": "flv480",
"timelength": 198738,
"accept_format": "hdflv2,hdflv2,flv,flv720,flv480,mp4",
"accept_description": [
"超清 4K",
"高清 1080P+",
"高清 1080P",
"高清 720P",
"清晰 480P",
"流畅 360P"
],
"accept_quality": [
120,
112,
80,
64,
32,
16
],
"video_codecid": 7,
"seek_param": "start",
"seek_type": "offset",
"dash": {
"duration": 199,
"minBufferTime": 1.5,
"min_buffer_time": 1.5,
"video": [
{
"id": 32,
"baseUrl": "https://cn-cq-gd-live-03.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=76ad04e8122b6db10a2d1ff512741576&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20320&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=80000000",
"base_url": "https://cn-cq-gd-live-03.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=76ad04e8122b6db10a2d1ff512741576&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20320&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=80000000",
"backupUrl": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000"
],
"bandwidth": 431459,
"mimeType": "video/mp4",
"mime_type": "video/mp4",
"codecs": "avc1.64001F",
"width": 852,
"height": 480,
"frameRate": "29.412",
"frame_rate": "29.412",
"sar": "640:639",
"startWithSap": 1,
"start_with_sap": 1,
"SegmentBase": {
"Initialization": "0-1011",
"indexRange": "1012-1523"
},
"segment_base": {
"initialization": "0-1011",
"index_range": "1012-1523"
},
"codecid": 7
},
{
"id": 32,
"baseUrl": "https://cn-cq-gd-bcache-21.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30033.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=5f07d64e16c928c399aca6068f8936ee&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20316&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=55730&logo=80000000",
"base_url": "https://cn-cq-gd-bcache-21.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30033.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=5f07d64e16c928c399aca6068f8936ee&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20316&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=55730&logo=80000000",
"backupUrl": [
"https://upos-sz-mirrorbd.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30033.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bdbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=f9d53ad6a809325a74dd99acddfdcea5&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=55730&logo=40000000",
"https://upos-sz-mirrorbd.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30033.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bdbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=f9d53ad6a809325a74dd99acddfdcea5&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=55730&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirrorbd.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30033.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bdbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=f9d53ad6a809325a74dd99acddfdcea5&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=55730&logo=40000000",
"https://upos-sz-mirrorbd.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30033.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bdbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=f9d53ad6a809325a74dd99acddfdcea5&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=55730&logo=40000000"
],
"bandwidth": 444423,
"mimeType": "video/mp4",
"mime_type": "video/mp4",
"codecs": "hev1.1.6.L120.90",
"width": 852,
"height": 480,
"frameRate": "29.412",
"frame_rate": "29.412",
"sar": "640:639",
"startWithSap": 1,
"start_with_sap": 1,
"SegmentBase": {
"Initialization": "0-1076",
"indexRange": "1077-1588"
},
"segment_base": {
"initialization": "0-1076",
"index_range": "1077-1588"
},
"codecid": 12
},
{
"id": 16,
"baseUrl": "https://cn-cq-gd-bcache-23.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30011.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=168596b1dca4f71f35bd61d07a6c5a7d&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20318&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26273&logo=80000000",
"base_url": "https://cn-cq-gd-bcache-23.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30011.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=168596b1dca4f71f35bd61d07a6c5a7d&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20318&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26273&logo=80000000",
"backupUrl": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30011.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=fc5d580c028c4b69d6e2a2b1cfa9e4a9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26273&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30011.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=fc5d580c028c4b69d6e2a2b1cfa9e4a9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26273&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30011.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=fc5d580c028c4b69d6e2a2b1cfa9e4a9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26273&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170-1-30011.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=fc5d580c028c4b69d6e2a2b1cfa9e4a9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26273&logo=40000000"
],
"bandwidth": 209519,
"mimeType": "video/mp4",
"mime_type": "video/mp4",
"codecs": "hev1.1.6.L120.90",
"width": 640,
"height": 360,
"frameRate": "29.412",
"frame_rate": "29.412",
"sar": "1:1",
"startWithSap": 1,
"start_with_sap": 1,
"SegmentBase": {
"Initialization": "0-1071",
"indexRange": "1072-1583"
},
"segment_base": {
"initialization": "0-1071",
"index_range": "1072-1583"
},
"codecid": 12
},
{
"id": 16,
"baseUrl": "https://cn-cq-gd-bcache-22.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30016.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=55c43222e9da23bd3d8aeacf40d88c88&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20317&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26094&logo=80000000",
"base_url": "https://cn-cq-gd-bcache-22.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30016.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=55c43222e9da23bd3d8aeacf40d88c88&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20317&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26094&logo=80000000",
"backupUrl": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30016.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=7f892021b5e7bfb4e36ae5f24fcdeaa1&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26094&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30016.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=7f892021b5e7bfb4e36ae5f24fcdeaa1&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26094&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30016.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=7f892021b5e7bfb4e36ae5f24fcdeaa1&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26094&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30016.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=7f892021b5e7bfb4e36ae5f24fcdeaa1&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=26094&logo=40000000"
],
"bandwidth": 208091,
"mimeType": "video/mp4",
"mime_type": "video/mp4",
"codecs": "avc1.64001E",
"width": 640,
"height": 360,
"frameRate": "29.412",
"frame_rate": "29.412",
"sar": "1:1",
"startWithSap": 1,
"start_with_sap": 1,
"SegmentBase": {
"Initialization": "0-1015",
"indexRange": "1016-1527"
},
"segment_base": {
"initialization": "0-1015",
"index_range": "1016-1527"
},
"codecid": 7
}
],
"audio": [
{
"id": 30280,
"baseUrl": "https://cn-cq-gd-bcache-20.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30280.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=e276caf208b2e091537bba60a64d30e8&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20315&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=80000000",
"base_url": "https://cn-cq-gd-bcache-20.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30280.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=e276caf208b2e091537bba60a64d30e8&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20315&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=80000000",
"backupUrl": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30280.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=c6f1af9956ddf79ccc3a4cee266fb9b9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30280.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=c6f1af9956ddf79ccc3a4cee266fb9b9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30280.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=c6f1af9956ddf79ccc3a4cee266fb9b9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30280.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=c6f1af9956ddf79ccc3a4cee266fb9b9&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000"
],
"bandwidth": 131190,
"mimeType": "audio/mp4",
"mime_type": "audio/mp4",
"codecs": "mp4a.40.2",
"width": 0,
"height": 0,
"frameRate": "",
"frame_rate": "",
"sar": "",
"startWithSap": 0,
"start_with_sap": 0,
"SegmentBase": {
"Initialization": "0-907",
"indexRange": "908-1419"
},
"segment_base": {
"initialization": "0-907",
"index_range": "908-1419"
},
"codecid": 0
},
{
"id": 30216,
"baseUrl": "https://cn-cq-gd-bcache-20.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30216.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=d05d3bbdf34265b63b54817cc17ec4f3&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20315&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=8434&logo=80000000",
"base_url": "https://cn-cq-gd-bcache-20.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30216.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=d05d3bbdf34265b63b54817cc17ec4f3&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20315&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=8434&logo=80000000",
"backupUrl": [
"https://upos-sz-mirrorali.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30216.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=alibv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=193efe078b344a6d6ca25f7acce94a9d&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=8434&logo=40000000",
"https://upos-sz-mirrorali.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30216.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=alibv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=193efe078b344a6d6ca25f7acce94a9d&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=8434&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirrorali.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30216.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=alibv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=193efe078b344a6d6ca25f7acce94a9d&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=8434&logo=40000000",
"https://upos-sz-mirrorali.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30216.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=alibv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=193efe078b344a6d6ca25f7acce94a9d&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=8434&logo=40000000"
],
"bandwidth": 67226,
"mimeType": "audio/mp4",
"mime_type": "audio/mp4",
"codecs": "mp4a.40.2",
"width": 0,
"height": 0,
"frameRate": "",
"frame_rate": "",
"sar": "",
"startWithSap": 0,
"start_with_sap": 0,
"SegmentBase": {
"Initialization": "0-941",
"indexRange": "942-1453"
},
"segment_base": {
"initialization": "0-941",
"index_range": "942-1453"
},
"codecid": 0
},
{
"id": 30232,
"baseUrl": "https://cn-cq-gd-bcache-19.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30232.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=f73de0e2f5997fd0de022a187cd4dfe1&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20314&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=80000000",
"base_url": "https://cn-cq-gd-bcache-19.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30232.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=f73de0e2f5997fd0de022a187cd4dfe1&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20314&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=80000000",
"backupUrl": [
"https://upos-sz-mirror08c.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30232.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=08cbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=3da87fe5a3490a32ca22942e91d0f549&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000",
"https://upos-sz-mirror08c.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30232.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=08cbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=3da87fe5a3490a32ca22942e91d0f549&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirror08c.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30232.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=08cbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=3da87fe5a3490a32ca22942e91d0f549&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000",
"https://upos-sz-mirror08c.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30232.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=08cbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=hw&upsig=3da87fe5a3490a32ca22942e91d0f549&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=16460&logo=40000000"
],
"bandwidth": 131190,
"mimeType": "audio/mp4",
"mime_type": "audio/mp4",
"codecs": "mp4a.40.2",
"width": 0,
"height": 0,
"frameRate": "",
"frame_rate": "",
"sar": "",
"startWithSap": 0,
"start_with_sap": 0,
"SegmentBase": {
"Initialization": "0-907",
"indexRange": "908-1419"
},
"segment_base": {
"initialization": "0-907",
"index_range": "908-1419"
},
"codecid": 0
}
],
"dolby": {
"type": 0,
"audio": null
},
"flac": null
},
"support_formats": [
{
"quality": 120,
"format": "hdflv2",
"new_description": "4K 超清",
"display_desc": "4K",
"superscript": "",
"codecs": [
"avc1.640033",
"hev1.1.6.L153.90"
]
},
{
"quality": 112,
"format": "hdflv2",
"new_description": "1080P 高码率",
"display_desc": "1080P",
"superscript": "高码率",
"codecs": [
"avc1.640032",
"hev1.1.6.L120.90"
]
},
{
"quality": 80,
"format": "flv",
"new_description": "1080P 高清",
"display_desc": "1080P",
"superscript": "",
"codecs": [
"avc1.640032",
"hev1.1.6.L120.90"
]
},
{
"quality": 64,
"format": "flv720",
"new_description": "720P 高清",
"display_desc": "720P",
"superscript": "",
"codecs": [
"avc1.640028",
"hev1.1.6.L120.90"
]
},
{
"quality": 32,
"format": "flv480",
"new_description": "480P 清晰",
"display_desc": "480P",
"superscript": "",
"codecs": [
"avc1.64001F",
"hev1.1.6.L120.90"
]
},
{
"quality": 16,
"format": "mp4",
"new_description": "360P 流畅",
"display_desc": "360P",
"superscript": "",
"codecs": [
"avc1.64001E",
"hev1.1.6.L120.90"
]
}
],
"high_format": null,
"last_play_time": 0,
"last_play_cid": 0,
"view_info": null
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
又取到流了家人们
在字典 $.data.dash
中,存在两个列表 video
和 audio
,它们之中的字典包含了各个质量的媒体流。这就是为什么客户端能根据网络质量在各个画质间自动快速切换。
让我们随便取一个质量的视频流,看看是怎么个事。
video_streams = stream["data"]["dash"]["video"]
audio_streams = stream["data"]["dash"]["audio"]
print(json.dumps(video_streams[0], ensure_ascii=False, indent=4))
2
3
4
Output
{
"id": 32,
"baseUrl": "https://cn-cq-gd-live-03.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=76ad04e8122b6db10a2d1ff512741576&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20320&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=80000000",
"base_url": "https://cn-cq-gd-live-03.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=bcache&oi=2101216138&trid=0000f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=76ad04e8122b6db10a2d1ff512741576&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&cdnid=20320&bvc=vod&nettype=0&orderid=0,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=80000000",
"backupUrl": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000"
],
"backup_url": [
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=1,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000",
"https://upos-sz-mirrorcos.bilivideo.com/upgcxcode/70/51/498005170/498005170_nb2-1-30032.m4s?e=ig8euxZM2rNcNbdlhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1721647531&gen=playurlv2&os=cosbv&oi=2101216138&trid=f27869831cf14549b8700398999a40d6u&mid=0&platform=pc&og=cos&upsig=73ec14f105c9a1c1b0144b49b7bac210&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform,og&bvc=vod&nettype=0&orderid=2,3&buvid=&build=0&f=u_0_0&agrr=1&bw=54104&logo=40000000"
],
"bandwidth": 431459,
"mimeType": "video/mp4",
"mime_type": "video/mp4",
"codecs": "avc1.64001F",
"width": 852,
"height": 480,
"frameRate": "29.412",
"frame_rate": "29.412",
"sar": "640:639",
"startWithSap": 1,
"start_with_sap": 1,
"SegmentBase": {
"Initialization": "0-1011",
"indexRange": "1012-1523"
},
"segment_base": {
"initialization": "0-1011",
"index_range": "1012-1523"
},
"codecid": 7
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
可以看到里面除了媒体流地址,还有各种各样的提供给解码器(或者说播放器?)的信息。不过既然我们只需要下载它们,那就只需要关心地址就好(吗?)
对照 bilicodes
中的信息,我们可以知道这个流是什么质量的。(其实从编码参数中的分辨率也能看出来)
print(bilicodes.stream_dash_video_quality[video_streams[0]["id"]])
Output
480P
得到了媒体流地址后,我们就可以开始下载了。对于偏大的文件,最好使用 requests
的流式传输。
下载流时记得带上指向 B 站域名的
Referer
请求头,服务器会检验这个字段。
这里我们假设用户选择了当前目录( ./
)作为保存位置,并对于音频和视频都选择了质量最好的流。
从标题和分 P 名生成文件名,使用正则表达式去除不能作为文件名的字符
# 假定用户选择了最高质量的流
video_stream = max(video_streams, key=lambda x: x["height"])
audio_stream = max(audio_streams, key=lambda x: x["bandwidth"])
url_v = video_stream["base_url"]
url_a = audio_stream["base_url"]
save_dir = "./"
title = video_data["data"]["title"] + "_" + pages[user_choice]["part"]
# 通过cid生成临时文件名
tmpfile_au = os.path.join(save_dir, "%d_au.m4a" % cid)
tmpfile_vi = os.path.join(save_dir, "%d_vi.m4v" % cid)
# 通过title和分P名生成最终文件名
file_final = os.path.join(save_dir, re.sub(r"[<>:\'\"/\\|?*]", "_", title) + ".mp4")
# 视频流
with open(tmpfile_vi, "wb+") as fp:
with requests.get(url_v, stream=True, headers=biliapis.DEFAULT_HEADERS) as resp:
for chunk in resp.iter_content(chunk_size=8192):
if chunk:
fp.write(chunk)
# 音频流
with open(tmpfile_au, "wb+") as fp:
with requests.get(url_a, stream=True, headers=biliapis.DEFAULT_HEADERS) as resp:
for chunk in resp.iter_content(chunk_size=8192):
if chunk:
fp.write(chunk)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
通过命令行调用 ffmpeg 进行合流,合流完毕后删除音频流与视频流
关于 ffmpeg 从命令行的调用,参见 ffmpeg 官方文档等网站。也可使用另外的库比如python-ffmpeg
。
os.system(
'ffmpeg -i "%s" -i "%s" -vcodec copy -acodec copy "%s"'
% (tmpfile_vi, tmpfile_au, file_final)
)
os.remove(tmpfile_vi)
os.remove(tmpfile_au)
2
3
4
5
6
尽管还有亿些需要改善的细节,但这就是最基本的视频下载流程了。