nonebot-plugin-kuwo
基于 NoneBot2 与 Alconna 的酷我音乐插件,面向 NapCat / OneBot V11 与 Milky 协议使用场景,提供搜索、直链、音乐卡片、语音和文件发送能力。
安装
nb-cli
nb plugin install nonebot-plugin-kuwo --upgrade
使用 PyPI 源:
nb plugin install nonebot-plugin-kuwo --upgrade -i https://pypi.org/simple
使用包管理器安装
推荐使用 uv:
uv add nonebot-plugin-kuwo
从 GitHub 仓库主分支安装源码:
uv add git+https://github.com/006lp/nonebot-plugin-kuwo@main
安装保留 htmlrender 渲染的 legacy/0.2.7 分支:
uv add git+https://github.com/006lp/nonebot-plugin-kuwo@legacy/0.2.7
如果你使用其他包管理器,也可以选择:
pdm add nonebot-plugin-kuwo
poetry add nonebot-plugin-kuwo
安装后,在 NoneBot2 项目的 pyproject.toml 中加入:
[tool.nonebot]
plugins = ["nonebot_plugin_kuwo"]
配置
COMMAND_START=["/"]
LOG_LEVEL=INFO
KUWO_SEARCH_LIMIT=5
KUWO_LIST_RENDER_MODE=text
KUWO_TRACK_RENDER_MODE=text
KUWO_DEFAULT_QUALITY=standard
# KUWO_TRACK_PROXY_URL=http://127.0.0.1:7890
# KUWO_MILKY_MUSIC_SIGN_URL=https://sign.example.com/music_card/card
KUWO_TRACK_CACHE_RETENTION_DAYS=1
KUWO_TRACK_CACHE_MAX_SIZE_MB=1024
# KUWO_RENDER_CUSTOM_FONT=MyFont.ttf
完整配置示例见 .env.example。
插件 HTTP 客户端的连接超时为 10 秒,读取、写入和连接池等待超时也分别为 10 秒。
配置项说明:
| 配置项 | 默认值 | 说明 |
|---|---|---|
KUWO_SEARCH_LIMIT |
5 |
搜索结果条数,范围 1-10 |
KUWO_LIST_RENDER_MODE |
text |
默认搜索列表模式,支持 text / image |
KUWO_TRACK_RENDER_MODE |
text |
默认单曲输出模式,支持 text / card / record / file |
KUWO_DEFAULT_QUALITY |
standard |
默认音质 |
KUWO_TRACK_PROXY_URL |
未配置 | 由于版权相关问题,海外用户请求歌曲直链时需要使用境内 HTTP/HTTPS 代理,例如 http://user:pass@127.0.0.1:7890 |
KUWO_MILKY_MUSIC_SIGN_URL |
未配置 | 可选的 Milky 音乐卡片外部签名服务地址(兼容 NapCat / LLBot musicSignUrl POST JSON 规范),用于签发 light_app Ark JSON;未配置或签名/发送失败时自动降级为图文(text)输出 |
KUWO_TRACK_CACHE_RETENTION_DAYS |
1 |
文件缓存保留天数,0 表示关闭按天清理 |
KUWO_TRACK_CACHE_MAX_SIZE_MB |
1024 |
文件缓存总大小上限,0 表示关闭按大小清理 |
KUWO_RENDER_CUSTOM_FONT |
未配置 | 插件配置目录中的字体文件名,例如 MyFont.ttf,优先于系统字体 |
图片列表由 Rust 原生扩展内置的 resvg 渲染,不需要 Playwright / Chromium。插件不内置或下载字体,wheel 和源码包均不分发字体文件;未配置自定义字体时使用系统字体。
自定义字体用法(kuwo_render_custom_font 对应环境变量 KUWO_RENDER_CUSTOM_FONT):
- 启动一次 NoneBot,localstore 会自动生成本插件的配置目录,启动日志
Kuwo render font config directory: ...会输出实际路径。该目录由get_plugin_config_dir()获取,跟随 localstore 的目录配置。 - 将自行准备的 TTF / OTF / TTC 字体文件放入该目录。例如启用
LOCALSTORE_USE_CWD=true时,文件可放在config/nonebot_plugin_kuwo/MyFont.ttf。 - 在 NoneBot 的
.env配置中设置KUWO_RENDER_CUSTOM_FONT=MyFont.ttf,重启 NoneBot。
仅填写文件名,不填写绝对路径、子目录或字体族名称。自定义字体作为默认字体,系统字体用于缺字回退;未配置、文件不存在或填写了路径时使用系统字体并在需要时记录警告。精简容器或系统缺少中文字体时,请自行提供支持中文的字体。没有可用字体或原生渲染失败时,搜索列表会自动回退到文本并记录原因。更新字体后需重启 NoneBot 以刷新字体缓存。
旧配置 KUWO_RENDER_FONT_FILES / KUWO_RENDER_FONT_DIRS 已移除,请将字体文件移入插件配置目录并改用 KUWO_RENDER_CUSTOM_FONT。升级后也可移除仅为本插件设置的 RENDER_BACKEND=playwright。
音质枚举:
standardexhighlosslesshireshifisurjymaster
特殊规则:
KUWO_TRACK_RENDER_MODE=card且未显式设置KUWO_LIST_RENDER_MODE时,搜索列表默认切到imagerecord模式强制回落到standardcard模式音质上限固定为losslessKUWO_TRACK_CACHE_MAX_SIZE_MB小于600时仅记录警告,不阻止启动KUWO_TRACK_PROXY_URL只代理歌曲直链接口,不代理搜索、封面、详情、文件下载和 Milky 音乐卡片签名请求KUWO_MILKY_MUSIC_SIGN_URL仅用于 Milky 协议的card模式,插件不内置任何第三方签名地址,也不在本地计算签名;日志中会对 URL 凭据与查询参数脱敏- 歌曲直链接口使用
https://changenotice.kuwo.cn/mobi.s,沿用rid/br等请求参数 - 所有远程返回的直链与封面 URL 均要求为
http://或https://,防止向协议端注入file://等非预期 URI
使用
命令参数
| 参数 | 适用命令 | 说明 |
|---|---|---|
-m/--mode <mode> |
所有命令 | 指定本次输出方式,取值见下方搜索列表与单曲输出说明 |
-q/--quality <quality> |
kw / kwid |
指定本次音质,取值见配置中的音质枚举 |
参数可放在关键词或 rid 前后,并可组合使用。模式值不区分大小写;不支持的模式会提示可选值。参数仅对本次命令生效,省略时沿用对应的输出模式配置和 KUWO_DEFAULT_QUALITY。
/kwsearch 周杰伦 -m image
/kw 晴天 -m file -q lossless
/kwid 553152678 --mode record
搜索列表
kwsearch / kw搜索 当前支持两种输出:
text- 每行格式:
序号. 音乐id 歌曲名-歌手
- 每行格式:
image- 使用 Rust 原生扩展(
resvg)把搜索列表渲染成 PNG - 复用搜索接口的
web_albumpic_short,并发下载封面后以内嵌图片渲染 - 封面下载超过 5 MiB、尺寸超过单边 4096px / 总计 4194304 像素、格式不支持或解码失败时使用矢量占位图
- 并发搜索的图片任务排队执行,原生渲染在线程中运行;画布上限为 8388608 像素
- 渲染失败时自动回退到文本
- 使用 Rust 原生扩展(
单曲输出
kw / kwid 当前支持四种输出:
text- 有封面时发送
图片 + 文本 - 文本包含:歌曲名、歌手、专辑、时长、码率、直链
- 若接口返回
ekey,文本中会额外带上ekey
- 有封面时发送
card- 发送自定义音乐卡片
url和audio都使用真实直链/kw与/kwid的封面均优先取自歌曲详情的albumPic;/kw获取详情封面失败或没有封面时复用搜索结果封面,不影响音频直链获取
record- 发送语音段
- 始终使用
standard
file- 下载到本地缓存后发送文件段
.mflac会先解密成可播放的.flac,.mgg会先解密成可播放的.ogg- 上传文件名使用
[quality]歌曲名 - 歌手.扩展名,quality为最终生效音质,例如[lossless]Summer - rionos.flac
Milky 协议说明
插件通过 nonebot-plugin-alconna 的 uniseg 支持 Milky 协议(需用户侧安装并启用 nonebot-adapter-milky;使用 light_app 音乐卡片时需 nonebot-adapter-milky>=1.2.0 及支持 Milky v1.2+ 的协议端),插件本体不强依赖具体适配器:
text/image:搜索图片列表以base64://发送,单曲封面以 HTTP(S)uri发送。record:与 OneBot V11 一致,强制使用standard(128kmp3)并将直链作为record段发送,由协议端转码为 SILK。file:通过 Alconna 导出为本地file://URI 并调用upload_group_file/upload_private_file,需要 NoneBot 与 Milky 协议端部署在同一宿主机或共享一致的缓存目录挂载路径。card(light_app音乐卡片):- Milky 协议(v1.0–v1.3)不提供原生
music消息段,也不在协议端内置音乐签名;v1.2+ 仅提供通用light_app小程序消息段透传已签名的 QQ Ark JSON。 - 未配置
KUWO_MILKY_MUSIC_SIGN_URL时:自动记录警告并降级为text图文输出(且不会额外将音质压低到lossless),避免 Alconna 回退发送无意义的[musicshare]。 - 配置
KUWO_MILKY_MUSIC_SIGN_URL后:按 NapCat / LLBotmusicSignUrl规范发送POSTJSON(type="custom"、subtype="kuwo"、url、audio、title、singer、image),兼容直接返回 Ark JSON 或data字段包装;签名后通过插件私有 Alconna 扩展导出为 Milkylight_app发送(不污染全局MusicShare导出器)。 - 若签名接口异常、返回非法 JSON、适配器版本过低不支持
light_app或协议端发送light_app失败,均会自动记录警告并回退为text图文输出。
- Milky 协议(v1.0–v1.3)不提供原生
文件缓存与加密格式(.mflac / .mgg)
file 模式使用 nonebot-plugin-localstore 的插件缓存目录,并在其下维护 tracks/ 子目录。
普通可直接发送的格式:
mp3flacaacoggwav
缓存策略:
- 相同
rid + bitrate优先复用缓存 - 缓存命中会刷新文件时间
- 默认按
1天和1024MB双重策略清理 - 两个值都设为
0时,不做自动清理 - 单个歌曲文件下载上限为
512 MiB,超限会停止下载并清理临时文件 - 下载和封面请求禁用 HTTP 内容压缩,压缩响应会被拒绝,避免解压后超出资源限额
- 缓存路径必须位于插件缓存目录中,清理时跳过符号链接;下载取消或失败时清理
.part文件;文件发送/上传期间会被锁定保护,不会被并发缓存清理误删 .mflac/.mgg解密在线程中执行;取消时先等待原生任务结束,再释放文件操作锁并清理临时文件
.mflac / .mgg 流程:
- 下载原始
.mflac/.mgg - 使用 Kuwo 返回的
ekey - 提取 QMC 原始密钥
- 推导最终 QMCv2 密钥
- 本地解密为
.flac/.ogg - 发送解密后的文件
- 删除中间加密文件
反馈问题
提交 Issue 前请先搜索已有反馈,并按模板提供插件版本、NoneBot / 适配器 / 协议端版本、相关配置、触发命令和脱敏后的 DEBUG 日志。
开发
项目强制使用 uv。
当前版本 0.3.4 的本地验证环境为 Python 3.13.17 / Rust 1.99.0,插件支持 Python >=3.10,原生扩展使用 abi3-py310。Python 与 Cargo 的项目版本统一为 0.3.4,版本变更后需同步更新 uv.lock 和 Cargo.lock。
构建工具使用 maturin>=1.16.0,<2.0,Rust 绑定使用 pyo3 0.29.3;Release 工作流固定使用 maturin 1.16.0。
uv sync --dev --locked
uv run maturin develop --release --locked
更新依赖后需要重新构建原生扩展:
uv lock --upgrade
cargo update
uv sync --dev --locked
uv run maturin develop --release --locked
常用命令:
uv run ruff check .
uv run pytest tests -q -p no:cacheprovider
cargo fmt --all --check
说明:
- 发布版 wheel 会自带原生扩展
_qmc_rs - 源码开发或本地调试需要先执行
maturin develop
项目结构
nonebot_plugin_kuwo/
├── _native.py
├── __init__.py
├── config.py
├── data_source.py
├── files.py
├── models.py
├── qmc.py
├── render.py
└── utils.py
src/
├── qmc.rs
└── render.rs
tests/
接口请求和 HTTP 客户端集中在 data_source.py,缓存、下载与解密集中在 files.py;QMC 回归测试通过 tests/test_qmc.py 调用原生扩展,Rust 实现文件不内嵌测试模块。
命令注册、参数读取和流程编排保留在 __init__.py,通过 Alconna 的 Arparma 获取解析结果、通过 UniMessage 构建跨适配器消息。HTTP 客户端初始化和关闭函数直接注册到 NoneBot 的启动与关闭钩子,导入阶段不创建客户端。开发约定参考 NoneBot 插件发布规范和 Alconna 响应器文档。
模型的数字字段由 Pydantic 统一校验,兼容整数与数字字符串;空值或畸形数据会转换为插件的接口响应异常。原生扩展按需加载,接口签名统一维护在 _qmc_rs.pyi。缓存与图片渲染共享取消等待逻辑,确保后台原生任务结束后才释放各自的操作锁;模块仅按这些明确职责划分。
鸣谢
- LiuLang 提供 DES 解密算法思路
- UnblockNeteaseMusic/server 提供音乐直链接口
许可证
本项目使用 AGPL-3.0 许可证。
Metadata
Release files for nonebot-plugin-kuwo 0.3.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nonebot_plugin_kuwo-0.3.4.tar.gz | 260.0 kB | With provenance | Details for nonebot_plugin_kuwo-0.3.4.tar.gz |
Built distributions (wheels)
Total release size: 11.3 MB
Release files / nonebot_plugin_kuwo-0.3.4.tar.gz
| Download URL | nonebot_plugin_kuwo-0.3.4.tar.gz |
|---|---|
| Size | 260.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9570eb3daac6e667312dbed1ed8ca47ccde3d1cc30dc8705b223c0a943cf9c84
|
|
BLAKE2b-256 checksum How to use checksums |
fd4c2bd5e854ae7745d75b4ea2ffa236322d4965dd6736a98b69ca49f5376509
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / nonebot_plugin_kuwo-0.3.4-cp310-abi3-win_arm64.whl
| Download URL | nonebot_plugin_kuwo-0.3.4-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
3e5423cbfdbddeece105f59e64144d06b5af0b224f6756365de8e3d7b7aaaf47
|
|
BLAKE2b-256 checksum How to use checksums |
6217d3c673532618e8521c3de9e4bd625def21bab5d6c89b4fcbfcfd58972d0b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / nonebot_plugin_kuwo-0.3.4-cp310-abi3-win_amd64.whl
| Download URL | nonebot_plugin_kuwo-0.3.4-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c2af4c6e628c5a697dc2ba59de99b0802f81defa3d40fc522f305e77032cc3d3
|
|
BLAKE2b-256 checksum How to use checksums |
f796fdbcffef49ca07933b4453994100a8c966c1ebcde9351b5b6e39d7377cf1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / nonebot_plugin_kuwo-0.3.4-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | nonebot_plugin_kuwo-0.3.4-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 2.0 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
96ea9d96be10d3f88997f07798a54a9f598125b3aed2b66e64004e79ebed5da5
|
|
BLAKE2b-256 checksum How to use checksums |
f40626e51d09b09e131a922a684ed909b89396dc04c039d3aea8c24f5e4eea58
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / nonebot_plugin_kuwo-0.3.4-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | nonebot_plugin_kuwo-0.3.4-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
bae17857681b170fe450c6342e58ebcf48b7c288fd6b6e533c378996d64152c6
|
|
BLAKE2b-256 checksum How to use checksums |
23d53acc6c5adc0a9421b94ab3455394a2216ea3cb59e90a93a39cee5fb6dcda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / nonebot_plugin_kuwo-0.3.4-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | nonebot_plugin_kuwo-0.3.4-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3d2c86d65c11f92e712a1417a0625a645e2f7f14cccbdc4de275188d3b60064c
|
|
BLAKE2b-256 checksum How to use checksums |
fd19b83fa194a338070f1e3c8a127fec326a0bd0d134eda137c08631d419198b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / nonebot_plugin_kuwo-0.3.4-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | nonebot_plugin_kuwo-0.3.4-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
b149f601effe9e7093d9e9166086745f49d335292032d0de9d77712293546ccb
|
|
BLAKE2b-256 checksum How to use checksums |
555f90de693ce427c8ff0890c71365b5c577637a9a34c9190a6705b90b381c3d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for nonebot-plugin-kuwo 0.3.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 7 files in this release have been uploaded with provenance metadata.
Attestation for nonebot_plugin_kuwo-0.3.4.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.