Skip to content

Commit

Permalink
feat: bili_ticket 算法 Java 实现 及 信息补充 及 错误修正 (SocialSisterYi#1061)
Browse files Browse the repository at this point in the history
* feat: 空间头图及拼写错误修正

* feat(fav/info.md): code 11010

* fix(misc/sign/wbi.md): java extra params

* feat(misc/sign/bili_ticket.md): description and java demo

* feat(video_ranking/dynamic.md): 分区视频相关接口

* fix(video_ranking/dynamic.md): 未关闭的标签

* feat(README.md): 补充链接

* feat(clientinfo/ip.md): 查询任意 IP 地址的归属地

* feat: get buvid3 buvid4 from api

* feat: new error code & format

* feat(misc/picture.md): 图片格式化更多规则
  • Loading branch information
SessionHu authored Jul 25, 2024
1 parent 750dd6a commit 18c1efb
Show file tree
Hide file tree
Showing 14 changed files with 1,078 additions and 56 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ B站 API 采用 C/S 结构,大多数接口为 REST API 和 gRPC,少部分接
- [x] [APP API 签名](docs/misc/sign/APP.md)`appkey``sign`
- [x] [已知的 APPKey](docs/misc/sign/APPKey.md)
- [x] [Wbi 签名](docs/misc/sign/wbi.md)`wts``w_rid`
- [ ] [bili_ticket](docs/misc/sign/bili_ticket.md)

- [x] [公共错误码](docs/misc/errcode.md)
- [x] [图片格式化](docs/misc/picture.md)
- [x] [bvid 说明](docs/misc/bvid_desc.md)
- [ ] [设备唯一标识BUVID](docs/misc/device_identity.md)
- [ ] [获取 buvid3 / buvid4](docs/misc/buvid3_4.md)
- [ ] [gRPC API 接口定义](grpc_api)
- [ ] [登录](docs/login)
- [x] [登录操作 (人机认证)](docs/login/login_action)
Expand Down Expand Up @@ -207,6 +209,7 @@ B站 API 采用 C/S 结构,大多数接口为 REST API 和 gRPC,少部分接
- [ ] 动态列表
- [x] [特定话题动态列表](docs/dynamic/tag_dynamics.md)
- [ ] [动态内容](docs/dynamic/get_dynamic_detail.md)
- [ ] [导航栏动态](docs/dynamic/nav.md)
- [ ] [相簿](docs/album)
- [x] [基本信息](docs/album/info.md)
- [x] [相簿列表](docs/album/list.md)
Expand Down Expand Up @@ -357,6 +360,7 @@ OR Aifadian:[https://afdian.net/@ShakaiAneE](https://afdian.net/@ShakaiAneE)
- [SocialSisterYi/bcut-asr](https://github.com/SocialSisterYi/bcut-asr): 使用必剪API的语音字幕识别
- [CzJam/Bili_Realtime_Data](https://github.com/CzJam/Bili_Realtime_Data): Bilibili粉丝与视频实时数据统计
- [kingwingfly/fav](https://github.com/kingwingfly/fav): 自动同步bili收藏夹、合集视频到本地的CLI工具(Rust实现,并提供一个文档测试完善的Rust风格的用于构建有状态爬虫的核心库)
- [linyuye/Bilibili_crawler](https://github.com/linyuye/Bilibili_crawler): 基于bilibili懒加载api爬取b站动态,视频等评论区

### 其他

Expand Down
93 changes: 92 additions & 1 deletion docs/clientinfo/ip.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 通过ip确定地理位置

## 通过ip确定位置
## 根据请求IP确定属地

> https://api.bilibili.com/x/web-interface/zone
Expand Down Expand Up @@ -60,3 +60,94 @@ curl 'https://api.bilibili.com/x/web-interface/zone'
```

</details>

## 查询任意 IP 地址的归属地

> https://api.live.bilibili.com/ip_service/v1/ip_service/get_ip_addr
> https://api.live.bilibili.com/client/v1/Ip/getInfoNew
注: 两接口等效

*请求方式:GET*

**URL参数:**


| 参数名 | 类型 | 内容 | 必要性 | 备注 |
| ------ | ---- | -------- | ------ | ---- |
| ip | str | IP地址 | 不必要 | IPv4或IPv6地址不限, 留空与[根据请求IP确定地理位置](#根据请求ip确定地理位置)基本相同 |

**JSON回复:**

根对象:

| 字段 | 类型 | 内容 | 备注 |
| ------- | ---- | -------- | ------- |
| code | num | 返回值 | 0: 成功 |
| message | str | 错误信息 | 默认为空 |
| msg | str | 错误信息 | 同message |
| data | obj | 信息本体 | 出错时为空数组 |

`data`对象:

[根据请求IP确定地理位置](#根据请求ip确定地理位置)回复的`data`对象基本相同, 但无 `country_code` 字段

**示例:**

查询请求IP地址的归属地:

```shell
curl -G 'https://api.live.bilibili.com/client/v1/Ip/getInfoNew'
```

<details>
<summary>查看响应示例:</summary>


```json
{
"code": 0,
"msg": "",
"message": "",
"data": {
"addr": "104.28.156.113",
"country": "新加坡",
"province": "新加坡",
"city": "",
"isp": "cloudflare.com",
"latitude": "1.352083",
"longitude": "103.819836"
}
}
```

</details>

查询IP地址`8.8.8.8`的归属地:

```shell
curl -G 'https://api.live.bilibili.com/ip_service/v1/ip_service/get_ip_addr' \
--data-urlencode 'ip=8.8.8.8'
```

<details>
<summary>查看响应示例:</summary>

```json
{
"code": 0,
"msg": "",
"message": "",
"data": {
"addr": "8.8.8.8",
"country": "GOOGLE.COM",
"province": "GOOGLE.COM",
"city": "",
"isp": "level3.com",
"latitude": "",
"longitude": ""
}
}
```

</details>
2 changes: 1 addition & 1 deletion docs/fav/info.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

| 字段 | 类型 | 内容 | 备注 |
| ------- | ----------------------------- | -------- | --------------------------------------------------- |
| code | num | 返回值 | 0:成功<br />-400:请求错误<br />-403:访问权限不足 |
| code | num | 返回值 | 0:成功<br />-400:请求错误<br />-403:访问权限不足<br />11010: 内容不存在 |
| message | str | 错误信息 | 默认为0 |
| data | 有效时:obj<br />无效或:null | 信息本体 | |

Expand Down
2 changes: 1 addition & 1 deletion docs/live/manage.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ curl 'https://api.live.bilibili.com/room/v1/Room/update' \

| 字段 | 类型 | 内容 | 备注 |
| ------- | ---- | -------- | ------------------------------------------------------------ |
| code | num | 返回值 | 0:成功<br />65530:token错误(登录错误)<br />1:错误<br />60009:分区不存在<br />60013:非常抱歉,您所在的地区受实名认证限制无法开播<br />**(其他错误码有待补充)** |
| code | num | 返回值 | 0:成功<br />65530:token错误(登录错误)<br />1:错误<br />60009:分区不存在<br />60024: 目标分区需要人脸认证<br />60013:非常抱歉,您所在的地区受实名认证限制无法开播<br />**(其他错误码有待补充)** |
| msg | str | 错误信息 | 默认为空 |
| message | str | 错误信息 | 默认为空 |
| data | obj | 信息本体 | |
Expand Down
48 changes: 48 additions & 0 deletions docs/misc/buvid3_4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 获取 buvid3 / buvid4

## 游客获取 buvid3 / buvid4

> https://api.bilibili.com/x/frontend/finger/spi
*请求方式: GET*

**JSON回复:**

根对象:

| 字段 | 类型 | 内容 | 备注 |
| ------- | ---- | -------- | -------- |
| code | num | 返回值 | 0:成功 |
| message | str | 信息 | ok: 成功 |
| data | obj | 数据本体 | |

`data`对象:

| 字段 | 类型 | 内容 | 备注 |
| ---- | ---- | ------ | ---- |
| b_3 | str | buvid3 | 需手动存放至 cookie 中 |
| b_4 | str | buvid4 | 同上 |

**示例:**

注: 建议自行生成, 不要复制本处示例的 buvid3 / buvid4.

```shell
curl -G 'https://api.bilibili.com/x/frontend/finger/spi'
```

<details>
<summary>查看响应示例:</summary>

```json
{
"code": 0,
"data": {
"b_3": "D9656DA8-9BEF-F464-5B72-C4849AFD336379044infoc",
"b_4": "F6E0FD4B-520C-1902-4F7B-E461D8D1F5AB79044-024072309-666onEZSnlHVPjoRp4kDYg=="
},
"message": "ok"
}
```

</details>
22 changes: 6 additions & 16 deletions docs/misc/bvid_desc.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,9 @@ print(av2bv(avid: 111298867365120))
print(bv2av(bvid: "BV1L9Uoa9EUx"))
```


### Java

```
```java
import java.math.BigInteger;

/**
Expand All @@ -266,27 +265,22 @@ public class AVBVConverter {

private static final String DATA = "FcwAPNKTMug3GV5Lj7EJnHpWsx4tb8haYeviqBz6rkCy12mUSDQX9RdoZf";

public static String av2bv(int aidParam) {
public static String av2bv(long aidParam) {
BigInteger aid = BigInteger.valueOf(aidParam);
char[] bytes = {'B', 'V', '1', '0', '0', '0', '0', '0', '0', '0', '0', '0'};
int bvIndex = bytes.length - 1;
BigInteger tmp = MAX_AID.or(aid).xor(XOR_CODE);
while (tmp.compareTo(BigInteger.ZERO) > 0) {
bytes[bvIndex] = DATA.charAt(tmp.mod(BigInteger.valueOf(BASE)).intValue());
tmp = tmp.divide(BigInteger.valueOf(BASE));
bvIndex -= 1;
bvIndex--;
}
swap(bytes, 3, 9);
swap(bytes, 4, 7);
StringBuilder sb = new StringBuilder(bytes.length);
for (Character ch : bytes) {
sb.append(ch);
}
return sb.toString();
return new String(bytes);
}

public static int bv2av(String bvid) {
public static long bv2av(String bvid) {
char[] bvidArr = bvid.toCharArray();
swap(bvidArr, 3, 9);
swap(bvidArr, 4, 7);
Expand All @@ -296,7 +290,7 @@ public class AVBVConverter {
tmp = tmp.multiply(BigInteger.valueOf(BASE)).add(BigInteger.valueOf(DATA.indexOf(c)));
}
BigInteger xor = tmp.and(MASK_CODE).xor(XOR_CODE);
return xor.intValue();
return xor.longValue();
}


Expand All @@ -314,21 +308,17 @@ public class AVBVConverter {
final int aid2 = 305988942;
final String bv2 = "BV1aP411K7it";

//av ==> bv
assert av2bv(aid1).equals(bv1);
assert av2bv(aid2).equals(bv2);

//bv ==>av
assert bv2av(bv1) == aid1;
assert bv2av(bv2) == aid2;
}
}
```


### Golang

```go
Expand Down
2 changes: 1 addition & 1 deletion docs/misc/device_identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 设备唯一标识 BUVID

注意区分于 Web 端的 buvid3, buvid4.
注意区分于 Web 端的 [buvid3, buvid4](buvid3_4.md).

BUVID 在 APP 首次安装于某设备, 且首次启动时生成.

Expand Down
32 changes: 24 additions & 8 deletions docs/misc/picture.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
# 图片格式化

对于\*.hdslb.com/bfs下的图片文件都可以使用以下格式化参数
对于 `*.hdslb.com/bfs` 下的图片文件都可以使用以下可选格式化参数.

> \*.hdslb.com/bfs/\*/\*.\[jpg/png/gif\]@{width}w\_{high}h\_{quality}q.{format}
使用 `@` 开始参数 (无论格式如何, 无论是否有参数, 通过计算 HASH 发现, 使用 `@` 均会导致返回图片不同), 多个参数以 `_` 分隔, 图片格式无需分隔且必须放在最后

| 可选参数 | 含义 | 备注 |
| -------- | ---------------- | ---------------- |
| width | 图片最大限制宽度 | |
| high | 图片最大限制高度 | |
| quality | 图片质量百分比 | 仅限webp |
| format | 图片格式 | 仅限png/jpg/webp/[avg_color](#avg_color格式说明) |
参见: [#191](https://github.com/SocialSisterYi/bilibili-API-collect/issues/191)

注: jpg 即 jpeg, 二者等效. 网页端常用 AVIF, WebP.

| 参数 | 格式 | 含义 | 备注 |
| ---- | ------- | ---------------- | ---------------- |
| w | ${int}w | 图片最大限制宽度 | 范围 [1, 9223372036854775807] |
| h | ${int}h | 图片最大限制高度 | 范围 [1, 9223372036854775807] |
| s | ${int}s | 作用尚不明确 | 不影响输出结果, 范围 [1, 9223372036854775807] |
| e | ${int}e | 改变大小 | 0: 保留比例取其小, 1: 保留比例取其大, 2: 不保留原比例 |
| p | ${int}p | 缩放倍数 | 默认100, 范围 [1, 1000] |
| o | ${int}o | 作用尚不明确 | 不影响输出结果 范围 [0, 1] |
| q | ${int}q | 图片质量百分比 | 仅限webp/jpeg/avif |
| c | ${int}c | 裁切图片(如果宽高允许) | 0: 不裁切但会修改图片, 1: 上传时的预设规则(若无则右下), 2: 左上, 3: 右上 |
| f | ${int}f | 作用尚不明确 | [0, 1]: 不改变图片, 2: 会改变图片 |
| progressive | progressive | 图片编码方式 | 仅限 jpeg(无: baseline, 有: progressive)/png(无:non-interlaced, 有: interlaced) |
| ! | !${str} | 加载来源 | web-home-carousel-cover, header, web-dynamic, web-avatar-space-header, ... |
| . | .${str} | 图片格式 | 仅限 png/jpeg/webp/avif/[avg_color](#avg_color格式说明) |

**示例:**

<details>
<summary>查看示例:</summary>

原始图片

https://i1.hdslb.com/bfs/archive/e5fff1472bad1c0c6bcb3004205f9be23b58ffc0.jpg
Expand Down Expand Up @@ -43,6 +58,7 @@ https://i1.hdslb.com/bfs/archive/e5fff1472bad1c0c6bcb3004205f9be23b58ffc0.jpg@1q

![](https://i1.hdslb.com/bfs/archive/[email protected])

</details>

## avg_color格式说明

Expand Down
Loading

0 comments on commit 18c1efb

Please sign in to comment.