2 unstable releases
0.4.1 | Oct 2, 2023 |
---|---|
0.4.0 |
|
0.3.2 | Aug 28, 2023 |
0.2.0 |
|
0.1.1 |
|
#7 in #ncm
53 downloads per month
22KB
285 lines
ncm_parser
A single file ncm parser. Here, the ncm is an encrypted music file format which is widely used on NeteaseCloudMuic.
For more details see https://www.cnblogs.com/cyx-b/p/13443003.html
API Documentation is avaliable here.
一个单文件实现的 .ncm 解析器。
Minimum Required Rust Version
Nightly now. 4 nightly-only features are enabled:
#![feature(iter_next_chunk)]
#![feature(iter_advance_by)]
#![feature(iterator_try_collect)]
#![feature(doc_auto_cfg)]
When these features get stable, I'll bump the version to 1.0.
Possible bugs
在版本 0.4.0 之前,我已经测试过 129 个 ncm 文件,几乎所有的 bug 都出在 ncm metadata 的解析上。如果遇到问题的话就尝试自己解析吧。
I've tested 129 ncm files before version 0.4.0, and almost all of the bugs are in the parsing of the ncm metadata. Try parsing it yourself if you run into problems.
Examples
use ncm_parser::NCMMetadata;
use std::fs::File;
use std::io::{Read, Write};
use std::path::Path;
fn main() {
// Open .ncm file
let ncm_file_name = Path::new("xxx.ncm");
let mut ncm_file = std::fs::read(ncm_file_name).unwrap();
// Parse ncm file with `from_iter`
let mut ncm_file_from_iter =
ncm_parser::from_iter(ncm_file.into_iter()).unwrap();
// Directly parse ncm file with `from_reader`
let mut ncm_file_from_reader =
ncm_parser::from_reader(File::open(ncm_file_name).unwrap()).unwrap();
// Both functions get same result.
assert_eq!(
ncm_file_from_iter.get_image().unwrap(),
ncm_file_from_reader.get_image().unwrap()
);
assert_eq!(
ncm_file_from_iter.get_metadata().unwrap(),
ncm_file_from_reader.get_metadata().unwrap()
);
assert_eq!(
ncm_file_from_iter.get_music().unwrap(),
ncm_file_from_reader.get_music().unwrap()
);
// Parse metadata
let ncm_meta = ncm_file_from_iter.get_parsed_metadata().unwrap();
let image = ncm_file_from_iter.get_image_unchecked();
let metadata = ncm_file_from_iter.get_metadata_unchecked();
let music = ncm_file_from_iter.get_music_unchecked();
// Save music
let music_name = ncm_file_name.with_extension(&ncm_meta.format);
std::fs::write(music_name, &music).unwrap();
// Get image format
let image_ext = ncm_meta.album_pic_url.rsplit_once('.').unwrap().1;
// Save cover image
let image_name = ncm_file_name.with_extension(image_ext);
std::fs::write(image_name, &image).unwrap();
// Save metadata
let meta_name = ncm_file_name.with_extension("json");
std::fs::write(meta_name, &metadata).unwrap();
}
Contribute
Feel free to contribute everything you like.
License
Currently licensed under MIT.
Dependencies
~1–1.7MB
~38K SLoC