Skip to main content

QQ Music QMCv2 (.mflac/.mgg) decryption Python extension written in Rust

Project description

ybpyqmc

QQ Music QMCv2 加密音频解密库,Rust 编写,通过 PyO3 + maturin 提供 Python 接口。

支持格式:.mflac / .mflac0 / .mflac1 / .mgg / .mgg0 / .mgg1


安装

pip install ybpyqmc

使用方法

流式解密示例

import ybpyqmc as pyqmc

# 从 ekey 创建解密器
cipher = pyqmc.QMCv2Cipher.new_from_ekey(ekey_str)

# 解密数据块(in-place,直接修改 bytearray)
chunk = bytearray(encrypted_bytes)
cipher.decrypt(chunk, offset)
# chunk 现在已是解密后的音频数据

HTTP Range 流式传输示例

import ybpyqmc as pyqmc

cipher = pyqmc.QMCv2Cipher.new_from_ekey(ekey_str)
offset = 0

async def stream_generator():
    async for chunk in music_response.content.iter_chunked(524288):
        chunk = bytearray(chunk)
        cipher.decrypt(chunk, offset)
        offset += len(chunk)
        yield bytes(chunk)

API 文档

QMCv2Cipher.new_from_ekey(ekey: str) -> QMCv2Cipher

从 ekey 字符串创建解密器。

  • ekey:音乐平台 API 返回的 ekey 字符串(Base64 编码,支持带 "yt" 前缀)
  • 返回:QMCv2Cipher 实例
  • 抛出:ValueError(ekey 无效时)

cipher.decrypt(data: bytearray, offset: int) -> None

原地解密音频数据块。

  • data:待解密的 bytearray,解密结果直接写回此缓冲区
  • offsetdata[0] 在原始加密文件中的绝对字节偏移量。完整文件从头解密传 0;HTTP Range 请求传 Range 起始值
  • 返回:Nonedata 已被原地修改)

解密器是无状态的,同一个实例可以用于任意偏移量的数据块,无需重新创建。


算法说明

ekey (Base64)
    │
    ▼
TC-TEA CBC 解密(固定密钥)
    │
    ▼
RC4 原始密钥(256 字节)
    │
    ▼
QMC 改进版 RC4 Keystream
  ├─ 前 128 字节:Hash 段(由密钥哈希值推导)
  └─ 之后每 5120 字节为一段,每段独立初始化 RC4
    │
    ▼
加密音频 XOR Keystream = 解密音频(FLAC / OGG / MP3…)

开源协议

MIT License

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

ybpyqmc-0.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl (263.3 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

ybpyqmc-0.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl (263.3 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

ybpyqmc-0.1.0-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl (263.6 kB view details)

Uploaded PyPymanylinux: glibc 2.28+ ARM64

ybpyqmc-0.1.0-cp38-abi3-win_arm64.whl (123.0 kB view details)

Uploaded CPython 3.8+Windows ARM64

ybpyqmc-0.1.0-cp38-abi3-win_amd64.whl (130.1 kB view details)

Uploaded CPython 3.8+Windows x86-64

ybpyqmc-0.1.0-cp38-abi3-manylinux_2_28_x86_64.whl (273.0 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ x86-64

ybpyqmc-0.1.0-cp38-abi3-manylinux_2_28_aarch64.whl (266.7 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.28+ ARM64

ybpyqmc-0.1.0-cp38-abi3-macosx_11_0_arm64.whl (231.0 kB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

ybpyqmc-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl (235.2 kB view details)

Uploaded CPython 3.8+macOS 10.12+ x86-64

File details

Details for the file ybpyqmc-0.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ybpyqmc-0.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 729b1f5f2330cf516e55336333e953ebe47a83841f9eb3ad688d70c3df8292c7
MD5 7a7015c8086b26a055d999bf14c1c214
BLAKE2b-256 7f18fea0bcdf3529151cae7d786810962a08bd3883b22e90726218f58f1821f2

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ybpyqmc-0.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 1b851f07d801603ef8636e50d753289592613a59f5a114c628d0f86386e0545e
MD5 b886f536e6755702d1946c54eb17a15f
BLAKE2b-256 082a5b0439862337644761e25f40938d8e54205ba41cf2b4acc3e29c7b93578d

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ybpyqmc-0.1.0-pp38-pypy38_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 70be55164aef8803b20f32169067091f00349f7686cae03dd379813bc340f175
MD5 96514338522df7e56554275631241d82
BLAKE2b-256 aa2d23f9944f29007f81e9d01331ea8091efa7adc0d6a52058f4ce77150846a1

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-cp38-abi3-win_arm64.whl.

File metadata

  • Download URL: ybpyqmc-0.1.0-cp38-abi3-win_arm64.whl
  • Upload date:
  • Size: 123.0 kB
  • Tags: CPython 3.8+, Windows ARM64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ybpyqmc-0.1.0-cp38-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 1745bb3ab4be6370dcb4378e25e0e671ebfc425233adcae2db46e00192130fdd
MD5 60dd6d55af6aacaa6d1d201439471858
BLAKE2b-256 428cbe3f627f9943b57b283680629cb073f8b32126cc6dc0dec25dacae0ae760

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-cp38-abi3-win_amd64.whl.

File metadata

  • Download URL: ybpyqmc-0.1.0-cp38-abi3-win_amd64.whl
  • Upload date:
  • Size: 130.1 kB
  • Tags: CPython 3.8+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for ybpyqmc-0.1.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6faefc05db3490e3008ad21bb4d559d5353f9b0163d2f86eada929df09f9dc19
MD5 10669c52ec9e6c4b40eddb5bc57ffb18
BLAKE2b-256 1f2d60b08ace89738676f7ea1344abe16a8fb9e97684851125f634f4b9219cd8

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-cp38-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ybpyqmc-0.1.0-cp38-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b0d4f963732f876ecf3ece99e7fce12058c8b1c9d00368a5bceca6064f466964
MD5 415d5044f9611a11b78d9961608449a7
BLAKE2b-256 3f8b08b3a57070f78991e26afda54e703317401bc5b93a6d8f4f4abf66d3a65a

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-cp38-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for ybpyqmc-0.1.0-cp38-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 5251894a14883801bcbcdd27a3768d3c7f74ca82b5d64642c48812b1e2f1087f
MD5 424cb1368d896fcc8db89df734653cfb
BLAKE2b-256 9649d27eaaf7240533c91d967a7f4888aa7e34570cd675017cad1a51947e483d

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ybpyqmc-0.1.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 27712637a176e7fb1b778eea96233181a629b0be3a5f82a279ead5cdbec9731a
MD5 29a2278c7ce16590da186484bfad84e8
BLAKE2b-256 5bdef41abb23fedc92846694f2fc8a5258736dd86f8d48234e31a45b5dd07f6b

See more details on using hashes here.

File details

Details for the file ybpyqmc-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for ybpyqmc-0.1.0-cp38-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ef63484088592310d67f4ec9402e36a39cb41dad940bdf699bbd64966dd7dba1
MD5 9ee899e87385cf0cbf07dd898045f702
BLAKE2b-256 19f8f0d6f23005289c08c3f9fb7be2544ff0b3b23507f3fa7bbdb694f8c5b1a3

See more details on using hashes here.

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