archibate/dotfiles-opencode / skills/bilibili-api
bilibili-api
FlaggedThis skill should be used when the user asks to "use bilibili API", "download bilibili video", "get bilibili user info", "list bilibili favorites", "send bilibili danmaku", "upload video to bilibili", "monitor bilibili live room", "search bilibili", "get bilibili comments", or needs guidance on the bilibili_api Python library usage, authentication, API endpoints, or workflow patterns.
references/docs/configuration.md
View on GitHub# 配置
```python
from bilibili_api import request_settings, request_log
```
## 配置项
| name | type | default | is_bilibili_api_providing | curl_cffi | aiohttp | httpx |
| - | - | - | - | - | - | - |
| proxy | str | ` ` | ❌ | ✅ | ✅ | ✅ |
| timeout | float | `30.0` | ❌ | ✅ | ✅ | ✅ |
| verify_ssl | bool | `True` | ❌ | ✅ | ✅ | ✅ |
| trust_env | bool | `True` | ❌ | ✅ | ✅ | ✅ |
| impersonate | str | ` ` | ❌ | ✅ | ❌ | ❌ |
| http2 | bool | `False` | ❌ | ✅ | ❌ | ✅ |
| wbi_retry_times | int | `3` | ✅ | \\ | \\ | \\ |
| enable_auto_buvid | bool | `True` | ✅ | \\ | \\ | \\ |
| enable_bili_ticket | bool | `False` | ✅ | \\ | \\ | \\ |
## 代理
```python
# 1. 通过 request_settings 设置
request_settings.set_proxy("http://example.com")
# 2. 通过 Credential 传入
cred = Credential(..., proxy="http://example.com")
func(..., credential=cred)
```
## web 请求超时设置
```python
request_settings.set_timeout(1.0)
```
## 设置是否验证 ssl / 使用环境变量
```python
request_settings.set_verify_ssl(False)
request_settings.set_trust_env(True)
```
## 打印请求日志
```python
request_log.set_on(True)
```
request_log 本质为 `AsyncEvent`,即发布-订阅模式异步事件类,日志输出先经过 `AsyncEvent` ,再会到 `logging.Logger`,因此模块支持对不同事件类型的过滤。
``` python
request_log.set_on_events(["REQUEST"]) # 仅当有 http 请求时打印日志
request_log.set_ignore_events(["API_REQUEST", "API_RESPONSE"]) # 去除 Api 类相关的信息
```
request_log 默认只打印以下类型信息:
- API_REQUEST
- API_RESPONSE
- ANTI_SPIDER
- WS_CONNECT
- WS_RECV
- WS_SEND
- WS_CLOSE
## 设置 `wbi` 请求重试次数上限
> `wbi` 为 B 站对用户相关 API 采取的一个反爬虫措施,需要传入一些经过加密的参数,否则请求可能会被驳回。每次计算此参数的之后,这个值有失效可能,届时模块会 **自动重新计算** 这个参数新的值,进行重试。当重试次数超过一定次数 (`settings.wbi_retry_times`) 后,模块将发出报错。
> 手动重新计算可用 `recalculate_wbi`
```python
request_settings.set_wbi_retry_times(10) # defaults to 3
from bilibili_api import recalculate_wbi
recalculate_wbi() # 重新计算 wbi 参数
```
## 设置 `buvid` 自动生成
> `buvid` 是访问 B 站时可能需要提供的 cookie 系列,分为 `buvid3` 和 `buvid4` 字段。如果不提供部分接口可能受限。模块在用户未提供 credential 或 credential 中无 `buvid3` 或 `buvid4` 字段时,会自动生成一组 `buvid`,但过程中需要进行网络请求,此功能可通过这项设置关闭。
> 自动生成的 `buvid` 若有必要,**需要用户手动刷新**,使用 `refresh_buvid`
```python
request_settings.set_enable_auto_buvid(False)
from bilibili_api import refresh_buvid
refresh_buvid() # 刷新 buvid
```
## 设置 `bili_ticket` 自动生成
> `bili_ticket` 是访问 B 站时可能需要提供的 cookie 系列,分为 `bili_ticket` 和 `bili_ticket_expires` 字段。提供 `bili_ticket` 有时可以达到一些玄学效果。默认不启用,可以通过此项设置启用。
> `bili_ticket` 过期后模块会 **自动重新计算**。手动重新计算可用 `refresh_bili_ticket`
```python
request_settings.set_enable_bili_ticket(True)
from bilibili_api import refresh_bili_ticket
refresh_bili_ticket() # 刷新 bili_ticket
```
## 额外设置
针对不同的第三方请求库,模块会有各不相同的额外设置。相关信息见 [模块请求库相关](https://nemo2011.github.io/bilibili-api/#/request_client)。
为了对这些字段进行处理,`request_settings` 提供 `set` 函数。
``` python
request_settings.set("impersonate", "edge99") # 设置名为 impersonate 的设置为 edge99
```
`set` 函数同样支持上面出现过的 `proxy` `timeout`。
``` python
# 等价
request_settings.set_proxy("http://example.com")
request_settings.set("proxy", "http://example.com")
```
## 获取设置
``` python
# 获取 proxy
proxy = request_settings.get_proxy()
proxy = request_settings.get("proxy")
proxy = request_settings.get_all()["proxy"]
# 获取所有设置
all_settings = request_settings.get_all()
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 468k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 321k | Updated | Claude CodeCodex | Verified | Install |