diff --git a/src/ape/constants.rs b/src/ape/constants.rs index 7ddde003..a657af82 100644 --- a/src/ape/constants.rs +++ b/src/ape/constants.rs @@ -1,3 +1,4 @@ -#[allow(unused)] pub(super) const INVALID_KEYS: [&str; 4] = ["ID3", "TAG", "OGGS", "MP+"]; -pub(crate) const APE_PREAMBLE: &[u8; 8] = b"APETAGEX"; + +// https://wiki.hydrogenaud.io/index.php?title=APE_Tags_Header +pub(crate) const APE_PREAMBLE: &[u8; 8] = b"APETAGEX"; \ No newline at end of file diff --git a/src/id3/v1/constants.rs b/src/id3/v1/constants.rs index b6dc5193..22d4da0d 100644 --- a/src/id3/v1/constants.rs +++ b/src/id3/v1/constants.rs @@ -196,7 +196,7 @@ pub const GENRES: [&str; 192] = [ "Psybient", ]; -pub const VALID_ITEMKEYS: [ItemKey; 7] = [ +pub(crate) const VALID_ITEMKEYS: [ItemKey; 7] = [ ItemKey::TrackTitle, ItemKey::TrackArtist, ItemKey::AlbumTitle, diff --git a/src/id3/v1/read.rs b/src/id3/v1/read.rs index f269c5b8..1183bf14 100644 --- a/src/id3/v1/read.rs +++ b/src/id3/v1/read.rs @@ -19,10 +19,13 @@ pub fn parse_id3v1(reader: [u8; 128]) -> Id3v1Tag { tag.album = decode_text(&reader[60..90]); tag.year = decode_text(&reader[90..94]); - let range = if reader[119] == 0 && reader[123] != 0 { + // Determine the range of the comment (30 bytes for ID3v1 and 28 for ID3v1.1) + // We check for the null terminator 28 bytes in, and for a non-zero track number after it. + // A track number of 0 is invalid. + let range = if reader[122] == 0 && reader[123] != 0 { tag.track_number = Some(reader[123]); - 94_usize..122 + 94_usize..123 } else { 94..124 }; diff --git a/src/ogg/constants.rs b/src/ogg/constants.rs index c00a8fc1..023eb9df 100644 --- a/src/ogg/constants.rs +++ b/src/ogg/constants.rs @@ -1,9 +1,11 @@ +// https://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-620004.2.1 pub const VORBIS_IDENT_HEAD: &[u8] = &[1, 118, 111, 114, 98, 105, 115]; pub const VORBIS_COMMENT_HEAD: &[u8] = &[3, 118, 111, 114, 98, 105, 115]; -#[allow(unused)] pub const VORBIS_SETUP_HEAD: &[u8] = &[5, 118, 111, 114, 98, 105, 115]; +// https://datatracker.ietf.org/doc/pdf/rfc7845.pdf#section-5.1 pub const OPUSTAGS: &[u8] = &[79, 112, 117, 115, 84, 97, 103, 115]; pub const OPUSHEAD: &[u8] = &[79, 112, 117, 115, 72, 101, 97, 100]; +// https://www.speex.org/docs/manual/speex-manual/node8.html pub const SPEEXHEADER: &[u8] = &[83, 112, 101, 101, 120, 32, 32, 32]; diff --git a/src/ogg/speex/properties.rs b/src/ogg/speex/properties.rs index a365f32f..b708f81f 100644 --- a/src/ogg/speex/properties.rs +++ b/src/ogg/speex/properties.rs @@ -20,7 +20,7 @@ pub struct SpeexProperties { vbr: bool, overall_bitrate: u32, audio_bitrate: u32, - nominal_bitrate: u32, + nominal_bitrate: i32, } impl From for FileProperties { @@ -47,7 +47,7 @@ impl SpeexProperties { vbr: bool, overall_bitrate: u32, audio_bitrate: u32, - nominal_bitrate: u32, + nominal_bitrate: i32, ) -> Self { Self { duration, @@ -102,8 +102,8 @@ impl SpeexProperties { self.audio_bitrate } - /// Audio bitrate (kbps) - pub fn nominal_bitrate(&self) -> u32 { + /// Audio bitrate (bps) + pub fn nominal_bitrate(&self) -> i32 { self.nominal_bitrate } } @@ -149,7 +149,7 @@ where } properties.channels = channels as u8; - properties.nominal_bitrate = first_page_content.read_u32::()?; + properties.nominal_bitrate = first_page_content.read_i32::()?; // The size of the frames in samples let _frame_size = first_page_content.read_u32::()?; @@ -167,7 +167,7 @@ where properties.duration = Duration::from_millis(length as u64); properties.overall_bitrate = ((file_length * 8) / length) as u32; - properties.audio_bitrate = properties.nominal_bitrate / 1000; + properties.audio_bitrate = (properties.nominal_bitrate as u64 / 1000) as u32; } } diff --git a/src/ogg/vorbis/properties.rs b/src/ogg/vorbis/properties.rs index c4c16dc5..6d3e662a 100644 --- a/src/ogg/vorbis/properties.rs +++ b/src/ogg/vorbis/properties.rs @@ -91,17 +91,17 @@ impl VorbisProperties { self.version } - /// Maximum bitrate + /// Maximum bitrate (bps) pub fn bitrate_max(&self) -> i32 { self.bitrate_maximum } - /// Nominal bitrate + /// Nominal bitrate (bps) pub fn bitrate_nominal(&self) -> i32 { self.bitrate_nominal } - /// Minimum bitrate + /// Minimum bitrate (bps) pub fn bitrate_min(&self) -> i32 { self.bitrate_minimum }