Crates.io | ncm_parser |
lib.rs | ncm_parser |
version | 0.4.1 |
source | src |
created_at | 2023-07-23 19:05:38.17648 |
updated_at | 2023-10-02 01:06:04.196336 |
description | A single file ncm parser |
homepage | |
repository | https://github.com/shuangsilab/ncm_dumper |
max_upload_size | |
id | 923914 |
size | 23,601 |
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 解析器。
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.
在版本 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.
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();
}
Feel free to contribute everything you like.
Currently licensed under MIT.