bilibili-API-collect/danmaku/history.md

246 lines
7.2 KiB
Markdown
Raw Normal View History

2020-03-21 00:26:16 +08:00
# 历史弹幕
**注历史弹幕的xml接口已经失效现已改为protobuf接口**
2020-11-20 20:13:12 +08:00
- [查询历史弹幕日期](#查询历史弹幕日期)
- [获取历史弹幕protobuf接口](#获取历史弹幕protobuf接口)
- [~~获取历史弹幕xml接口~~](#获取历史弹幕xml接口)
2020-11-20 20:13:12 +08:00
---
2020-03-21 00:26:16 +08:00
## 查询历史弹幕日期
> http://api.bilibili.com/x/v2/dm/history/index
2020-03-21 00:26:16 +08:00
2020-07-14 18:44:44 +08:00
*请求方式GET*
2020-03-21 00:26:16 +08:00
认证方式CookieSESSDATA
**注:查询历史弹幕需要登录**
2020-06-08 22:44:46 +08:00
**url参数**
2020-03-21 00:26:16 +08:00
2020-11-27 23:39:07 +08:00
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
| ------ | ---- | ------------ | ------ | ------- |
| type | num | 1 | 必要 | |
| oid | num | 视频cid | 必要 | |
2020-11-27 23:39:07 +08:00
| month | str | 查询目标年月 | 必要 | YYYY-MM |
2020-03-21 14:37:55 +08:00
**json回复**
2020-04-16 18:47:19 +08:00
根对象:
2020-03-25 12:05:53 +08:00
| 字段 | 类型 | 内容 | 备注 |
| ------- | ------------------------------- | -------- | ------------------------------------------------- |
| code | num | 返回值 | 0成功<br />-400请求错误<br />-101账号未登录 |
| message | str | 错误信息 | 默认为0 |
| ttl | num | 1 | |
2020-03-25 12:05:53 +08:00
| data | 有弹幕array<br />无弹幕null | 日期列表 | |
2020-03-21 14:37:55 +08:00
`data`数组:
| 项 | 类型 | 内容 | 备注 |
| ---- | ---- | ------------------- | ---------- |
2020-11-27 23:39:07 +08:00
| 0 | str | 存在弹幕的日期1 | YYYY-MM-DD |
| n | str | 存在弹幕的日期(n+1) | YYYY-MM-DD |
2020-03-21 14:37:55 +08:00
| …… | str | …… | …… |
2020-03-21 00:26:16 +08:00
2020-04-16 18:47:19 +08:00
**示例:**
2020-03-21 00:26:16 +08:00
2020-03-25 12:05:53 +08:00
查询了cid为144541892的视频位于2020年1月中有历史弹幕记录的日期
```shell
curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
--data-urlencode 'type=1' \
--data-urlencode 'oid=144541892' \
--data-urlencode 'month=2020-01' \
-b 'SESSDATA=xxx'
```
2020-03-21 00:26:16 +08:00
2020-08-31 16:37:38 +08:00
<details>
<summary>查看响应示例:</summary>
2020-03-21 00:26:16 +08:00
```json
{
"code": 0,
"message": "0",
"ttl": 1,
"data": [
"2020-01-21",
"2020-01-22",
"2020-01-23",
"2020-01-24",
"2020-01-25",
"2020-01-26",
"2020-01-27",
"2020-01-28",
"2020-01-29",
"2020-01-30",
"2020-01-31"
]
}
```
2020-08-31 16:37:38 +08:00
</details>
2020-03-25 12:05:53 +08:00
返回结果的 `data` 项说明这些日期有弹幕发送。若查询的月份中视频无弹幕,则 `data` 项为 `null`
2020-03-21 00:26:16 +08:00
```shell
curl -G 'http://api.bilibili.com/x/v2/dm/history/index' \
--data-urlencode 'type=1' \
--data-urlencode 'oid=144541892' \
--data-urlencode 'month=2019-12' \
-b 'SESSDATA=xxx'
```
2020-03-21 00:26:16 +08:00
2020-08-31 16:37:38 +08:00
<details>
<summary>查看响应示例:</summary>
2020-03-21 00:26:16 +08:00
```json
{
"code": 0,
"message": "0",
"ttl": 1,
"data": null
}
```
2020-08-31 16:37:38 +08:00
</details>
## 获取历史弹幕protobuf接口
> http://api.bilibili.com/x/v2/dm/web/history/seg.so
*请求方式GET*
认证方式CookieSESSDATA
**url参数**
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
| ------ | ---- | -------- | ------ | ----------- |
| type | num | 弹幕类 | 必要 | 1视频弹幕 |
| oid | num | 视频cid | 必要 | |
| date | str | 弹幕日期 | 必要 | YYYY-MM-DD |
**proto回复**
porto定义见[bilibili.community.service.dm.v1.DmSegMobileReply](../grpc_api/bilibili/community/service/dm/v1.proto)
详细说明见[protobuf弹幕](danmaku_proto.md)
获取视频`av84271171(cid=144541892)`2020-01-21的历史弹幕
**注proto定义需要编译**
```python
import requests
import google.protobuf.text_format as text_format
import bilibili.community.service.dm.v1_pb2 as Danmaku
url = 'http://api.bilibili.com/x/v2/dm/web/history/seg.so'
params = {
'type':1, #弹幕类型
'oid':144541892, #cid
'date':'2020-01-21' #弹幕日期
}
cookies = {
'SESSDATA':'xxx'
}
resp = requests.get(url,params,cookies=cookies)
data = resp.content
danmaku_seg = Danmaku.DmSegMobileReply()
danmaku_seg.ParseFromString(data)
print(text_format.MessageToString(danmaku_seg.elems[0],as_utf8=True))
```
输出:
```
id: 27532611677585408
progress: 300507
mode: 1
fontsize: 25
color: 16777215
midHash: "2a28d4a6"
content: "章北海的老爹"
ctime: 1579621359
idStr: "27532611677585408"
```
## 获取历史弹幕xml接口
<details>
<summary>查看折叠内容:</summary>
2020-03-21 00:26:16 +08:00
> http://api.bilibili.com/x/v2/dm/history
2020-03-21 00:26:16 +08:00
2020-07-14 18:44:44 +08:00
*请求方式GET*
2020-03-21 00:26:16 +08:00
认证方式CookieSESSDATA
**注:查询历史弹幕需要登录**
结果为[标准xml格式弹幕](danmaku_xml.md#弹幕格式)
2020-03-21 14:37:55 +08:00
**使用deflate压缩注意解码**
2020-06-08 22:44:46 +08:00
**url参数**
2020-03-21 00:26:16 +08:00
2020-11-27 23:39:07 +08:00
| 参数名 | 类型 | 内容 | 必要性 | 备注 |
| ------ | ---- | -------- | ------ | ---------- |
| type | num | 1 | 必要 | |
| oid | num | 视频cid | 必要 | |
2020-11-27 23:39:07 +08:00
| date | str | 弹幕日期 | 必要 | YYYY-MM-DD |
2020-03-21 00:26:16 +08:00
2020-04-16 18:47:19 +08:00
**示例:**
2020-03-21 00:26:16 +08:00
获取视频`av84271171(cid=144541892)`2020-01-21的历史弹幕
```shell
curl -G 'http://api.bilibili.com/x/v2/dm/history' \
--data-urlencode 'type=1' \
--data-urlencode 'oid=144541892' \
--data-urlencode 'date=2020-01-21' \
-b 'SESSDATA=xxx' \
--compressed -o 'danmaku.xml'
```
2020-03-21 00:26:16 +08:00
2020-08-31 18:00:47 +08:00
<details>
<summary>查看响应示例:</summary>
2020-03-21 00:26:16 +08:00
```xml
<?xml version="1.0" encoding="UTF-8"?>
<i>
<chatserver>chat.bilibili.com</chatserver>
<chatid>144541892</chatid>
<mission>0</mission>
<maxlimit>1500</maxlimit>
<state>0</state>
<real_name>0</real_name>
<d p="473.43400,1,25,15138834,1579622380,0,ec16f2d,27532609919123456">敬礼</d>
<d p="3.10200,1,25,16777215,1579622362,0,a2bd7474,27532609920696320">悄默声的更新啊怎么</d>
<d p="17.52300,1,25,16777215,1579622357,0,972c932b,27532609906016258">久等了</d>
<d p="40.81800,1,25,16777215,1579622343,0,bbca6701,27532609906540546">不都是乱纪元才浸泡</d>
<d p="243.39800,1,25,15138834,1579622336,0,77b00ed9,27532609924890624">已阅,狗屁不通。大字报在地上搞搞就行,别弄到天上去</d>
<d p="559.80000,1,25,16777215,1579622334,0,9affc7f5,27532609909686274">CSSC。。。</d>
<d p="398.29700,1,25,16777215,1579622331,0,18d4707,27532609926463488">看到了个寂寞</d>
<d p="34.81000,1,25,38979,1579622327,0,319d7700,27532609926987776">有耳朵了!</d>
<d p="18.65700,1,25,16777215,1579622321,0,bbca6701,27532609912307714">雪天不用浸泡吧</d>
<d p="305.99800,1,25,16777215,1579622316,0,878c315b,27532609928560640">未来史学派</d>
<d p="7.86200,1,25,16777215,1579622309,0,c5136613,27532609913880578">浸泡!!!!!!!</d>
<d p="368.95600,1,25,16777215,1579622302,0,18d4707,27532609914404866">章召忠</d>
<d p="25.19800,1,25,16777215,1579622286,0,4dab6898,27532609931706368">mi24av</d>
<d p="41.10100,1,25,16777215,1579622274,0,33d31036,27532609932230656">泪奔</d>
<d p="627.69800,1,25,16777215,1579622264,0,d79a826a,27532609933279232">组建太空军</d>
<d p="310.58900,1,25,16777215,1579622243,0,18d4707,27532609918074882">是未来史学派?</d>
<d p="723.34800,1,25,16777215,1579622239,0,844fa9e7,27532609919123458">刘培强还行</d>
…………
<i>
2020-08-31 18:00:47 +08:00
```
</details>
2020-08-31 18:00:47 +08:00
</details>