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 使用场景,提供搜索、直链、音乐卡片、语音和文件发送能力。

当前实现重点:

  • 命令解析使用 nonebot-plugin-alconna
  • 消息输出统一使用 uniseg
  • 配置统一使用 get_plugin_config(Config)
  • 文件缓存统一使用 nonebot-plugin-localstore
  • .mflac 解密核心使用 Rust + PyO3 + maturin

功能

  • 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

安装后在 NoneBot 项目中启用插件:

[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_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 表示关闭按大小清理

音质枚举:

  • 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

开发

项目强制使用 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-adapter-onebot

项目结构

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

Uploaded CPython 3.10+Windows ARM64

nonebot_plugin_kuwo-0.2.2-cp310-abi3-win_amd64.whl (148.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

nonebot_plugin_kuwo-0.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (247.7 kB view details)

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

nonebot_plugin_kuwo-0.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (239.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

nonebot_plugin_kuwo-0.2.2-cp310-abi3-macosx_11_0_arm64.whl (224.6 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

nonebot_plugin_kuwo-0.2.2-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.2.tar.gz.

File metadata

  • Download URL: nonebot_plugin_kuwo-0.2.2.tar.gz
  • Upload date:
  • Size: 211.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.2.tar.gz
Algorithm Hash digest
SHA256 3c3872a7508c0bc2511a9d43e9e6cf1b98f81919670c9e7bb6c265f8afa53eeb
MD5 ee55d632b29844478c64c9e65b1bf89e
BLAKE2b-256 2818ba05770bb42bc8a72401ebed3e12c06cb66f87bd023f8230be80468b06e6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.2-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 02ca59f0ce839330e02728f18d38811e04d16eb8593b02988af7d461874e4a87
MD5 1d11224e76a0a92dfe5dce9bf9b4fcad
BLAKE2b-256 f9c057239e7ca122ac07e50d072eb233bda8b44781ee87d07b3f9912b9df018f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c5ffd1c8099550379d1ca7e26c31a1c825122c574a47e9b90e4fb6d62932f2ff
MD5 f63758ef19e6bd5b0d831ee2c6ff82ce
BLAKE2b-256 ed3883d1d8e645a5e48f748c0067035548c835b90905d69851e2479632d36642

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11f327d1426f185621c0c6820ffed2995b0b4fb8e3d2b3d17e9cd9688cedfb37
MD5 4eab5ca1cddd38c30ed3f816a9ad9766
BLAKE2b-256 a6f237a1c1114c1ffaad3c785d68cba39e88c006a25d99c211e0162cb1ce91b9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 207ea47a5a3cb99b6639de6f23eb54033d411274a5d063ccaaf8d237402f8dee
MD5 d38fde7a720999d4dcb09c5f8265fa08
BLAKE2b-256 88d451c9e672d3de6bb1bd2b7a159244b45e4fbeb6ae6bcc226f8c929d5765ab

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 39c01ca7f8b4aca05418b019532aa6c525225d79d55ef01b13d9d3472429e839
MD5 46e72074762fc7d068f6829faba53630
BLAKE2b-256 0d75a14222cddccbc4d9dfc562b6891e003678cb777c406686e282fdd4700edb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 c836125073aa9ae724c72adc87dcf6c398ec917f11c89a9910b49dba48545d94
MD5 7deeeb34577c402b6997de48ffd9ca24
BLAKE2b-256 b92d17f1c08565165e44d6eaa91b9e88ddefe660bce669007e54cc114613db95

See more details on using hashes here.

Provenance

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