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

安装后在 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_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.3.tar.gz (216.5 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.3-cp310-abi3-win_arm64.whl (147.9 kB view details)

Uploaded CPython 3.10+Windows ARM64

nonebot_plugin_kuwo-0.2.3-cp310-abi3-win_amd64.whl (148.6 kB view details)

Uploaded CPython 3.10+Windows x86-64

nonebot_plugin_kuwo-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (247.6 kB view details)

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

nonebot_plugin_kuwo-0.2.3-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.3-cp310-abi3-macosx_11_0_arm64.whl (224.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

nonebot_plugin_kuwo-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl (225.2 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

  • Download URL: nonebot_plugin_kuwo-0.2.3.tar.gz
  • Upload date:
  • Size: 216.5 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.3.tar.gz
Algorithm Hash digest
SHA256 904b4932f5b1df7f015683f4be83a69d9fe5fd91c71ebfd03fd4c7c57074eccc
MD5 68ea3080daebe1c02c6353db7ca5f74e
BLAKE2b-256 67ed38c102a2cb234245af62de5ed2c7984749208b904d15f9f579cb4116b0c6

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.3-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 3d5936c9571cadc5a1685ebfe5adfe4cf79150e5337906bbce6bb6871c58922b
MD5 893165b43ba99029fb252cba961ac75b
BLAKE2b-256 9b4aa7ad444d9bd7fd3328e3a39a732ca3065b644ce1e4185c61e4235e10835f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bbb46fb443a353370f54806711f91807551e0da80d7d0bff0f839fa96b3362c3
MD5 61a2ce7c00a630c9b7d4220a4727e909
BLAKE2b-256 878359ef0572ef6516efbffb45605efb6157f6eae497168818dc4bd15e7beb08

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c24366c9c0f1c5c69e4c152f26f5888d9b84e630062d10d63aea98fb5a2da21
MD5 3eb2775aa7f83de63218433c6a16410c
BLAKE2b-256 fa7cf8363e0de9fa25822e7f5aac60c438ab97b8d9f795f0649312ecccd65288

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d42b7cbe0f7ae77deb1498e685310807a3371fbf97667300b2063ef0a8610404
MD5 27a1da59bc63071c2082aaea33b63951
BLAKE2b-256 e71e4dcd4ace8d4fd74de2569132d83a9c6ecd34271bcb2aee584a7580bf9eda

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a03c266088d1894db9452abe0e8057ff70630f1e965c67a23901ecaa11b2254d
MD5 0d869a195ea7343f80d6e437203ff338
BLAKE2b-256 d5fa57b6ac63372665575be87d28e3a5fd81c37be804f20720b127980a27853d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for nonebot_plugin_kuwo-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 3941b576913cb1ad869286df18e0cd436df2a7a51fc3c462361092de570c66c8
MD5 7bc78bea0e71193b713a14f3be785f2f
BLAKE2b-256 37cdf64f7cd61491108c4d3a6c0411351b0a6b0eb281310a3389ecf6f7027bca

See more details on using hashes here.

Provenance

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