音乐控制/解密
This commit is contained in:
1 parent
9e6d73e191
commit
ff1d5cd517
41 files changed
+10827
-4
No files matched your search
@@ -0,0 +1,41 @@
|
||||
//! **临时**校验:用产物解析器确认解密出来的文件是合法音频。
|
||||
//!
|
||||
//! 用法:`cargo run --example verify_audio -- <文件路径>`
|
||||
|
||||
fn main() {
|
||||
let path = std::env::args()
|
||||
.nth(1)
|
||||
.expect("用法:verify_audio <文件路径>");
|
||||
let p = std::path::Path::new(&path);
|
||||
|
||||
let size = std::fs::metadata(p).map(|m| m.len()).unwrap_or(0);
|
||||
println!("文件 : {}", p.display());
|
||||
println!("大小 : {size} 字节");
|
||||
|
||||
// 1) 头部魔数
|
||||
let head = std::fs::read(p).map(|b| b[..16.min(b.len())].to_vec());
|
||||
match head {
|
||||
Ok(h) => println!("首帧 : {:02x?}", h),
|
||||
Err(e) => {
|
||||
println!("读取失败:{e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 2) 交给项目同款的解析器(lofty):能读出时长与格式才算真合法
|
||||
match lofty::probe::Probe::open(p).and_then(|probe| probe.read()) {
|
||||
Ok(tagged) => {
|
||||
use lofty::file::AudioFile;
|
||||
let props = tagged.properties();
|
||||
println!("时长 : {:?}", props.duration());
|
||||
println!("码率 : {:?}", props.audio_bitrate());
|
||||
println!("采样率 : {:?}", props.sample_rate());
|
||||
println!("声道 : {:?}", props.channels());
|
||||
println!("=> lofty 成功解析,文件合法可播");
|
||||
}
|
||||
Err(e) => {
|
||||
println!("lofty 解析失败:{e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user