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;未配置时图片渲染会失败并自动回退到文本列表。

音质枚举:

  • 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.4.tar.gz (219.3 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.4-cp310-abi3-win_arm64.whl (148.1 kB view details)

Uploaded CPython 3.10+Windows ARM64

nonebot_plugin_kuwo-0.2.4-cp310-abi3-win_amd64.whl (147.9 kB view details)

Uploaded CPython 3.10+Windows x86-64

nonebot_plugin_kuwo-0.2.4-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.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (239.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

nonebot_plugin_kuwo-0.2.4-cp310-abi3-macosx_11_0_arm64.whl (224.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

nonebot_plugin_kuwo-0.2.4-cp310-abi3-macosx_10_12_x86_64.whl (225.9 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: nonebot_plugin_kuwo-0.2.4.tar.gz
  • Upload date:
  • Size: 219.3 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.4.tar.gz
Algorithm Hash digest
SHA256 1eea7988c2c7373ba5a416a3ebd4696cb83c7bf35c5810aada5900303b86ff0b
MD5 293e4740e0d48cd1234b7e45a06d9e58
BLAKE2b-256 7f5a2a7102764bbae7efef0d755f5848c8944fbfbbca949ba23b4a2bf92e0a9c

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.4.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.4-cp310-abi3-win_arm64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.4-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 4138912c1e3141bc1dfd4a8faaefe2520166eb6dce4bb08b2c4481c33d045b58
MD5 e615aea47e01658e1a0c58c43bcde4c5
BLAKE2b-256 c50d78d2ba7deffd6dea1ae27fec4ab429c3c7c7430c32a5da20f2d4145b91f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.4-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.4-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.4-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4f8cbd0780ab97807630d116d09c9547132ad1f00c10d1d8432ec46868358066
MD5 88cfb21939148baf558e1470b47bc905
BLAKE2b-256 80227c041ee50706f7157e9a402c45173a824b93bc4cbcfc86ddd8e7c74119f6

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.4-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.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.4-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 998709b7dc73137c3eea3da47af163e9fbc867f9c22e8daac8ed4991380ddf67
MD5 514844067ec3d10f24c7c32942bdd984
BLAKE2b-256 228604a1592bc1cedcd439c2add503d05c95f5ba1b08a97667348281e9fc0fe9

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.4-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.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.4-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4a3982517527dc1071e541e0cd831af7fcefcb3a1b45b2541cc9506c609e7ab4
MD5 124dfddedcc0663e4653db467b4b731b
BLAKE2b-256 faa1594ac00c9288e0dcd6c4f0499e11988ac86726760f73b83a57621b51d3a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.4-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.4-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.4-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6e63c2edd9f54457842470067cadb6a038823980e02a6965589c122e60d8baac
MD5 78b3ac221ff6f748b2463fb7cd293055
BLAKE2b-256 f84e5dd0dddd5545b50858e874e30c38abeb75a070c34d26cb29061c01da8491

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.4-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.4-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.4-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 722f2ea6a9c6d112984df756b2db0e45bf4f1753dce35013b07403cf74588170
MD5 5b8f10be4a21e13dbe5b667065aff75d
BLAKE2b-256 92a94d44d3addc911e7644f3f4fd41e229507ec65236bb3e7b18af1ea8a67de4

See more details on using hashes here.

Provenance

The following attestation bundles were made for nonebot_plugin_kuwo-0.2.4-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