From 9c12d2384c55a17a4123b95f045727403f1be504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sun, 15 Sep 2024 00:27:25 +0100 Subject: [PATCH] [audio] fix: id3v2 parsing --- um_audio/src/__fixtures__/mp3_with_id3v2.bin | Bin 0 -> 64 bytes um_audio/src/lib.rs | 12 ++++++++++++ um_audio/src/metadata.rs | 2 +- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 um_audio/src/__fixtures__/mp3_with_id3v2.bin diff --git a/um_audio/src/__fixtures__/mp3_with_id3v2.bin b/um_audio/src/__fixtures__/mp3_with_id3v2.bin new file mode 100644 index 0000000000000000000000000000000000000000..d3b47e6b7ced966905371a00451f4586ffadf819 GIT binary patch literal 64 vcmeZtF=k-^0p*b3U{@f`&%nU!lUSB!YN2Otre|ni0G5Ri|9?M0;(?g}E`$hY literal 0 HcmV?d00001 diff --git a/um_audio/src/lib.rs b/um_audio/src/lib.rs index 883d45b..9a44b30 100644 --- a/um_audio/src/lib.rs +++ b/um_audio/src/lib.rs @@ -129,3 +129,15 @@ pub fn detect_audio_type(buffer: &[u8]) -> Result { Ok(AudioType::Unknown) } + +#[cfg(test)] +mod tests { + use crate::{detect_audio_type, AudioType}; + + #[test] + fn test_mp3() { + let mp3_data = include_bytes!("__fixtures__/mp3_with_id3v2.bin"); + let result = detect_audio_type(mp3_data).expect("failed to parse mp3"); + assert_eq!(result, AudioType::MP3); + } +} diff --git a/um_audio/src/metadata.rs b/um_audio/src/metadata.rs index 0a3a6a9..17afd46 100644 --- a/um_audio/src/metadata.rs +++ b/um_audio/src/metadata.rs @@ -67,7 +67,7 @@ fn get_ape_v2_size(buffer: &[u8], offset: usize) -> Result { pub fn get_header_metadata_size(buffer: &[u8], offset: usize) -> Result { let len = get_id3_header_size(buffer, offset)?; - if len == 0 { + if len != 0 { Ok(len) } else { get_ape_v2_size(buffer, offset)