XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/bilibili-API-collect

修改【protobuf实时弹幕】接口 并添加【protobuf历史弹幕】接口

f97772d
SocialSisterYi <45892418+SocialSisterYi@users.noreply.github.com>
提交于

代码差异

2 个文件 +114 -81
Modified danmaku/danmaku_proto.md +29 -76
@@ -5,7 +5,6 @@
5 5 新的api是以6分钟为一个单位加载,即每次加载6分钟内的弹幕
6 6
7 7 - [获取实时弹幕](#获取实时弹幕)
8 - [实例](#实例)
9 8
10 9 ---
11 10
@@ -38,6 +37,8 @@
38 37
39 38 **proto回复:**
40 39
40 porto定义见:[bilibili.community.service.dm.v1.DmSegMobileReply](..\grpc_api\bilibili\community\service\dm\v1.proto)
41
41 42 消息`DmSegMobileReply`:
42 43
43 44 | 名称 | 类型 | 含义 | 备注 |
@@ -61,94 +62,46 @@
61 62 | pool | int32 | 弹幕池 | 0:普通池<br />1:字幕池<br />2:特殊池(代码/BAS弹幕) |
62 63 | idStr | string | 弹幕dmID | 字串形式<br />唯一 可用于操作参数 |
63 64
64 protobuf结构体:
65
66 **bilidm.proto**
67
68 ```protobuf
69 syntax = "proto3";
70
71 message DanmakuElem {
72 int64 id = 1; //弹幕dmID
73 int32 progress = 2; //出现时间
74 int32 mode = 3; //弹幕类型
75 int32 fontsize = 4; //文字大小
76 uint32 color = 5; //弹幕颜色
77 string midHash = 6; //发送者UID的HASH
78 string content = 7; //弹幕内容
79 int64 ctime = 8; //发送时间
80 int32 weight = 9; //权重
81 string action = 10; //动作?
82 int32 pool = 11; //弹幕池
83 string idStr = 12; //弹幕dmID(字串形式)
84 }
85
86 message DmSegMobileReply {
87 repeated DanmakuElem elems = 1; //弹幕条目
88 }
89 ```
90
91 65 **示例:**
92 66
93 获取视频`av810872(CID=1176840)`的实时弹幕分包1
94
95 ```shell
96 curl -G 'http://api.bilibili.com/x/v2/dm/web/seg.so' \
97 -o 'danmaku.bin'
98 ```
99
100 响应正文为protubuf二进制数据
101
102 ## 实例
103
104 获取炮姐弹幕第1包,[BV1Js411o76u](https://www.bilibili.com/video/BV1Js411o76u)
67 获取视频`av810872(CID=1176840)`(炮姐)的实时弹幕分包1
105 68
106 编译proto结构文件
107
108 ```shell
109 protoc --python_out=. bilidm.proto
110 ```
111
112 生成bilidm_pb2.py
113
114
115 以下为python测试代码,输出第一包的第一条弹幕
69 **注:proto定义需要编译**
116 70
117 71 ```python
118 import bilidm_pb2
119 72 import requests
73 import google.protobuf.text_format as text_format
74 import bilibili.community.service.dm.v1_pb2 as Danmaku
75
76 url = 'http://api.bilibili.com/x/v2/dm/web/seg.so'
77 params = {
78 'type':1, #弹幕类型
79 'oid':1176840, #cid
80 'pid':810872, #avid
81 'segment_index':1 #弹幕分段
82 }
83 resp = requests.get(url,params)
84 data = resp.content
120 85
121 AVID = 810872
122 CID = 1176840
123 SEG = 1
124 url = f'http://api.bilibili.com/x/v2/dm/web/seg.so?type=1&oid={CID}&pid={AVID}&segment_index={SEG}'
125
126 data = requests.get(url)
127 target = bilidm_pb2.DmSegMobileReply()
128 target.ParseFromString(data.content)
86 danmaku_seg = Danmaku.DmSegMobileReply()
87 danmaku_seg.ParseFromString(data)
129 88
130 print(target.elems[0])
131 print(target.elems[0].content)
89 print(text_format.MessageToString(danmaku_seg.elems[0],as_utf8=True))
132 90 ```
133 91
134 92 输出:
135 93
136 94 ```
137 id: 682225690
138 progress: 44125
95 id: 711923911
96 progress: 47880
139 97 mode: 1
140 fontsize: 25
141 color: 16777215
142 midHash: "af4aa003"
143 content: "\346\210\221\347\202\256\350\277\230\350\203\275\345\206\215\346\210\230500\345\271\264\357\274\201\357\274\201\357\274\201\346\210\221\347\202\256\350\277\230\350\203\275\345\206\215\346\210\230500\345\271\264\357\274\201\357\274\201\357\274\201\346\210\221\347\202\256\350\277\230\350\203\275\345\206\215\346\210\230500\345\271\264\357\274\201\357\274\201\357\274\201\346\210\221\347\202\256\350\277\230\350\203\275\345\206\215\346\210\230500\345\271\264"
144 ctime: 1416323487
98 fontsize: 18
99 color: 10092288
100 midHash: "59417e95"
101 content: "世界第一电击公主殿下,遇到你是我一生最美好的风景!吾炮赛高,永生不离!唯我超电磁炮永世长存! "
102 ctime: 1418799826
145 103 weight: 6
146 idStr: "682225690"
147
148 我炮还能再战500年!!!我炮还能再战500年!!!我炮还能再战500年!!!我炮还能再战500年
104 idStr: "711923911"
105 attr: 1
149 106 ```
107
Modified danmaku/history.md +85 -5
@@ -1,7 +1,10 @@
1 1 # 历史弹幕
2 2
3 **注:历史弹幕的xml接口已经失效,现已改为protobuf接口**
4
3 5 - [查询历史弹幕日期](#查询历史弹幕日期)
4 - [获取历史弹幕](#获取历史弹幕)
6 - [获取历史弹幕protobuf接口](#获取历史弹幕protobuf接口)
7 - [~~获取历史弹幕xml接口~~](#获取历史弹幕xml接口)
5 8
6 9 ---
7 10
@@ -13,6 +16,8 @@
13 16
14 17 认证方式:Cookie(SESSDATA)
15 18
19 **注:查询历史弹幕需要登录**
20
16 21 **url参数:**
17 22
18 23 | 参数名 | 类型 | 内容 | 必要性 | 备注 |
@@ -48,7 +53,8 @@
48 53 curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
49 54 --data-urlencode 'type=1' \
50 55 --data-urlencode 'oid=144541892' \
56 --data-urlencode 'month=2020-01' \
57 -b 'SESSDATA=xxx'
51 58 ```
52 59
53 60 <details>
@@ -83,7 +89,8 @@ curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
83 89 curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
84 90 --data-urlencode 'type=1' \
85 91 --data-urlencode 'oid=144541892' \
92 --data-urlencode 'month=2019-12' \
93 -b 'SESSDATA=xxx'
86 94 ```
87 95
88 96 <details>
@@ -100,7 +107,73 @@ curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
100 107
101 108 </details>
102 109
103 ## 获取历史弹幕
110 ## 获取历史弹幕protobuf接口
111
112 > http://api.bilibili.com/x/v2/dm/web/history/seg.so
113
114 *请求方式:GET*
115
116 认证方式:Cookie(SESSDATA)
117
118 **url参数:**
119
120 | 参数名 | 类型 | 内容 | 必要性 | 备注 |
121 | ------ | ---- | -------- | ------ | ----------- |
122 | type | num | 弹幕类 | 必要 | 1:视频弹幕 |
123 | oid | num | 视频CID | 必要 | |
124 | date | str | 弹幕日期 | 必要 | YYYY-MM-DD |
125
126 **proto回复:**
127
128 porto定义见:[bilibili.community.service.dm.v1.DmSegMobileReply](..\grpc_api\bilibili\community\service\dm\v1.proto)
129
130 详细说明见[protobuf弹幕](danmaku_proto.md)
131
132 获取视频`av84271171(CID=144541892)`2020-01-21的历史弹幕
133
134 **注:proto定义需要编译**
135
136 ```python
137 import requests
138 import google.protobuf.text_format as text_format
139 import bilibili.community.service.dm.v1_pb2 as Danmaku
140
141 url = 'http://api.bilibili.com/x/v2/dm/web/history/seg.so'
142 params = {
143 'type':1, #弹幕类型
144 'oid':144541892, #cid
145 'date':'2020-01-21' #弹幕日期
146 }
147 cookies = {
148 'SESSDATA':'xxx'
149 }
150 resp = requests.get(url,params,cookies=cookies)
151 data = resp.content
152
153 danmaku_seg = Danmaku.DmSegMobileReply()
154 danmaku_seg.ParseFromString(data)
155
156 print(text_format.MessageToString(danmaku_seg.elems[0],as_utf8=True))
157 ```
158
159 输出:
160
161 ```
162 id: 27532611677585408
163 progress: 300507
164 mode: 1
165 fontsize: 25
166 color: 16777215
167 midHash: "2a28d4a6"
168 content: "章北海的老爹"
169 ctime: 1579621359
170 idStr: "27532611677585408"
171 ```
172
173 ## 获取历史弹幕xml接口
174
175 <details>
176 <summary>查看折叠内容:</summary>
104 177
105 178 > http://api.bilibili.com/x/v2/dm/history
106 179
@@ -108,6 +181,8 @@ curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
108 181
109 182 认证方式:Cookie(SESSDATA)
110 183
184 **注:查询历史弹幕需要登录**
185
111 186 结果为[标准xml格式弹幕](danmaku_xml.md#弹幕格式)
112 187
113 188 **使用deflate压缩,注意解码**
@@ -122,12 +197,15 @@ curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
122 197
123 198 **示例:**
124 199
200 获取视频`av84271171(CID=144541892)`2020-01-21的历史弹幕
201
125 202 ```shell
126 203 curl -G 'http://api.bilibili.com/x/v2/dm/history' \
127 204 --data-urlencode 'type=1' \
128 205 --data-urlencode 'oid=144541892' \
129 206 --data-urlencode 'date=2020-01-21' \
207 -b 'SESSDATA=xxx' \
208 --compressed -o 'danmaku.xml'
130 209 ```
131 210
132 211 <details>
@@ -163,4 +241,6 @@ curl -G 'http://api.bilibili.com/x/v2/dm/history' \
163 241 <i>
164 242 ```
165 243
244 </details>
245
166 246 </details>