About
The lib for the tool to convert ncm file to mp3/flac/...
网易云音乐的ncm文件转换工具ncm_c的库。
Usage
use NcmFile;
let ncm = open.unwrap;
ncm.save.unwrap;
Encoding
The pipeline is reversible: [encode::encode_ncm] wraps a plaintext audio
stream back into a valid .ncm container. The audio body is XOR-based and
therefore symmetric — the same keystream both decrypts and encrypts.
use ;
use Read;
// Decode an existing file to plaintext audio + metadata...
let mut ncm = open.unwrap;
let mut audio = Vecnew;
ncm.read_to_end.unwrap;
let meta = open.unwrap.into_parts.0;
// ...then re-encode. `key_data` is the raw content key: any non-empty slice
// yields a decodable file (the NetEase client uses a per-file random key).
let key_data: = .collect;
let out = create.unwrap;
encode_ncm.unwrap;
Async streaming (stream feature)
With the stream feature, stream::NcmStream decodes a .ncm as it
arrives over the network: it parses the header off the front of the stream,
then is itself a futures::Stream yielding the decrypted audio body. The
adapters are plain poll-based wrappers over the futures traits (no
async fn in traits), so they are executor-agnostic — tokio, smol, async-std
all work.
use StreamExt;
use NcmStream;
use io;
let resp = get.await?;
// Map the stream's error into `io::Error`, which `NcmStream` requires.
let bytes = resp.bytes_stream.map_err;
let mut ncm = open.await?;
println!;
let mut file = create.await?;
while let Some = ncm.next.await
Bridging to tokio
NcmStream is a futures::Stream, which tokio consumes directly (as above).
For the reverse direction — turning our decoded futures::Stream<Item = Bytes>
into a tokio::io::AsyncRead — wrap it with tokio_util::io::StreamReader; to
feed a tokio AsyncRead source into NcmStream::open, turn it into a
stream first with tokio_util::io::ReaderStream:
use ;
// tokio AsyncRead source -> stream -> decoded NcmStream
let src = open.await?;
let ncm = open.await?;
// decoded futures::Stream -> tokio AsyncRead
let mut reader = new;
copy.await?;
For lower-level composition, stream::DecryptStream transforms a body-only
chunk stream when you already hold a [Key] (from [NcmFile::into_cipher]),
and stream::EncryptSink is the encoding dual.
features
cover_download: providewith_covermethod to download cover image from internet if not contained in ncm file.stream: async,futures-basedstream::NcmStream/stream::DecryptStream/stream::EncryptSinkadapters for decoding and encoding over afutures::Stream.