Skip to main content

NoneBot2 plugin for Kuwo music search and track delivery.

Project description

nonebot-plugin-kuwo

logo

基于 NoneBot2 的酷我音乐插件

LICENSE python Adapters

uv ruff rust

基于 NoneBot2 的酷我音乐插件,面向 NapCat / OneBot V11 使用场景,提供搜索、直链、音乐卡片、语音和文件发送能力。

功能

  • kwsearch <关键词>
    • 返回搜索结果列表
    • 支持 text / image
  • kw搜索 <关键词>
    • kwsearch 中文别名
  • kw <关键词> [-q/--quality <quality>]
    • 搜索后直接取第一首歌
    • 支持 text / card / record / file
  • kwid <rid> [-q/--quality <quality>]
    • 直接通过 rid 获取歌曲
    • 支持 text / card / record / file

安装

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

如果你使用其他包管理器,也可以选择:

pdm add nonebot-plugin-kuwo
poetry add nonebot-plugin-kuwo

安装后,在 NoneBot2 项目的 pyproject.toml 中加入:

plugins = ["nonebot_plugin_kuwo"]

配置

COMMAND_START=["/"]
LOG_LEVEL=INFO
RENDER_BACKEND=playwright

KUWO_SEARCH_LIMIT=5
KUWO_LIST_RENDER_MODE=text
KUWO_TRACK_RENDER_MODE=text
KUWO_DEFAULT_QUALITY=standard
KUWO_TRACK_CACHE_RETENTION_DAYS=1
KUWO_TRACK_CACHE_MAX_SIZE_MB=1024

配置项说明:

配置项 默认值 说明
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_CACHE_RETENTION_DAYS 1 文件缓存保留天数,0 表示关闭按天清理
KUWO_TRACK_CACHE_MAX_SIZE_MB 1024 文件缓存总大小上限,0 表示关闭按大小清理

RENDER_BACKENDnonebot-plugin-htmlrender 的配置项。使用 KUWO_LIST_RENDER_MODE=image 时需要设置为 playwright;未配置时图片渲染会失败并自动回退到文本列表。当前项目已按 nonebot-plugin-htmlrender>=0.7.1 验证:默认 RENDER_STARTUP_MODE=off 时不会在 NoneBot 启动阶段预热浏览器,首次图片渲染会按需启动,详情见 nonebot-plugin-htmlrender 文档

音质枚举:

  • standard
  • exhigh
  • lossless
  • hires
  • hifi
  • sur
  • jymaster

特殊规则:

  • KUWO_TRACK_RENDER_MODE=card 且未显式设置 KUWO_LIST_RENDER_MODE 时,搜索列表默认切到 image
  • record 模式强制回落到 standard
  • card 模式音质上限固定为 lossless
  • KUWO_TRACK_CACHE_MAX_SIZE_MB 小于 600 时仅记录警告,不阻止启动

使用

搜索列表

kwsearch / kw搜索 当前支持两种输出:

  • text
    • 每行格式:序号. 音乐id 歌曲名-歌手
  • image
    • 使用 nonebot-plugin-htmlrender 生成图片列表
    • 直接复用搜索接口返回的 web_albumpic_short
    • 渲染失败时自动回退到文本

单曲输出

kw / kwid 当前支持四种输出:

  • text
    • 有封面时发送 图片 + 文本
    • 文本包含:歌曲名、歌手、专辑、时长、码率、直链
    • 若接口返回 ekey,文本中会额外带上 ekey
  • card
    • 发送自定义音乐卡片
    • urlaudio 都使用真实直链
  • record
    • 发送语音段
    • 始终使用 standard
  • file
    • 下载到本地缓存后发送文件段
    • .mflac 会先解密成可播放的 .flac

音质参数

kwkwid 都支持:

-q
--quality

示例:

/kw Summer Pockets -q lossless
/kwid 553152678 --quality exhigh

文件缓存与 .mflac

file 模式使用 nonebot-plugin-localstore 的插件缓存目录,并在其下维护 tracks/ 子目录。

普通可直接发送的格式:

  • mp3
  • flac
  • aac
  • ogg
  • wav

缓存策略:

  • 相同 rid + bitrate 优先复用缓存
  • 缓存命中会刷新文件时间
  • 默认按 1 天和 1024MB 双重策略清理
  • 两个值都设为 0 时,不做自动清理

.mflac 流程:

  1. 下载原始 .mflac
  2. 使用 Kuwo 返回的 ekey
  3. 提取 QMC 原始密钥
  4. 推导最终 QMCv2 密钥
  5. 本地解密为 .flac
  6. 发送解密后的文件
  7. 删除中间 .mflac

反馈问题

提交 Issue 前请先搜索已有反馈,并按模板提供插件版本、NoneBot / 适配器 / 协议端版本、相关配置、触发命令和脱敏后的 DEBUG 日志。

开发

项目强制使用 uv

uv sync
uv run maturin develop --release

常用命令:

uv run ruff check .
uv run pytest tests -q -p no:cacheprovider
cargo fmt --all

说明:

  • 发布版 wheel 会自带原生扩展 _qmc_rs
  • 源码开发或本地调试需要先执行 maturin develop

项目结构

nonebot_plugin_kuwo/
├── __init__.py
├── config.py
├── data_source.py
├── models.py
├── qmc.py
├── render.py
└── utils.py
src/
└── qmc.rs
tests/

鸣谢

许可证

本项目使用 AGPL-3.0 许可证。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nonebot_plugin_kuwo-0.2.5.tar.gz (219.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_arm64.whl (148.4 kB view details)

Uploaded CPython 3.10+Windows ARM64

nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_amd64.whl (147.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (248.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (239.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_11_0_arm64.whl (225.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_10_12_x86_64.whl (225.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file nonebot_plugin_kuwo-0.2.5.tar.gz.

File metadata

  • Download URL: nonebot_plugin_kuwo-0.2.5.tar.gz
  • Upload date:
  • Size: 219.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nonebot_plugin_kuwo-0.2.5.tar.gz
Algorithm Hash digest
SHA256 4f517d134d6de3c17e0edd2a9833e3cb478219291a6159fad5c61790d69633e8
MD5 4303b9b37501a38ea2e6dbc82f6acf22
BLAKE2b-256 ccf446a09d6487a6eece3b5a871faf54892391a43e3c1c3a9128463f8b51712c

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.5.tar.gz:

Publisher: release.yml on 006lp/nonebot-plugin-kuwo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 d5dba7efe61b5ca6da875482cacfb6270e71f7c7fb5182ee1311a5649ca8e0bd
MD5 4b4361b87ed9bf992a4abc33864f2ce6
BLAKE2b-256 6cbb9ea64bd5eb23e8abf5c85e82b0fc3b705fbc4486996c0af646dee7be7083

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_arm64.whl:

Publisher: release.yml on 006lp/nonebot-plugin-kuwo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 016ce7d5ba5b3d44d48b9ad78dde2cc50e71d51150ee82c40a9b66ed0c0dd53b
MD5 fa341e3474e9f6710ee296b388fe2bcd
BLAKE2b-256 aecd80ee52b63f8b14db09debd8f9a841a355d3c5db9544bc3201731e20fe237

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.5-cp310-abi3-win_amd64.whl:

Publisher: release.yml on 006lp/nonebot-plugin-kuwo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fea7149169aa58b1dad8aa3b65015da7e7527940c582c91038cb997f68dc5627
MD5 e5b826c1b25194cbbbf3918c3f58a2e3
BLAKE2b-256 b4aefc01704d26be1596867aa932dbb6905b26d59b3d15ecebb8bed7a5570a8f

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on 006lp/nonebot-plugin-kuwo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 21ba86ad71b963085b4ca89deca37aa8dca5c84f41151a78945b462b1614391c
MD5 99de0ca51bd38e01852415a8b9788f13
BLAKE2b-256 015028454df2c5e166117fdb74cff19d757132f25d7fa7d1d48e2ff1c59f3991

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.5-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on 006lp/nonebot-plugin-kuwo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3dbb7eaf6e6dd6b827a2ca84e8a011b1144363506368f93c912fb2e2c11bea44
MD5 0f846d9aa383b7521741cd9a2b42a3eb
BLAKE2b-256 6c48e1f4ac216e81e13fdf1eafb4e5c76cdd6550a29055dd4a4bbf135f944cdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on 006lp/nonebot-plugin-kuwo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 4813aa93f7314cb84eb2b577c09c4e2aefc06f17b8a9a56f5f6b973058d1ac85
MD5 35c5251b64ea45c362ea0d054ed87cca
BLAKE2b-256 a5352c96f19a02c181198165cac339ecab8c278ed7cec39bfb44d0ecdd918628

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.5-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on 006lp/nonebot-plugin-kuwo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page