// check for ID3v{2-4}
let mut buf = [0; 5];
- br.peek_buf(&mut buf).unwrap();
- if &buf[0..3] == b"ID3" && buf[3] > 0 && buf[3] < 5 && buf[4] == 0 { //ID3 tag found, must be a raw stream
- br.read_skip(6).unwrap();
- let mut size = 0;
- for _ in 0..4 {
- let b = br.read_byte().unwrap();
- if (b & 0x80) != 0 {
- println!("Invalid ID3 size");
- break;
+ loop {
+ if br.peek_buf(&mut buf).is_err() {
+ break;
+ }
+ if &buf[0..3] == b"ID3" && buf[3] > 0 && buf[3] < 5 && buf[4] == 0 { //ID3 tag found, must be a raw stream
+ br.read_skip(6).unwrap();
+ let mut size = 0;
+ for _ in 0..4 {
+ let b = br.read_byte().unwrap();
+ if (b & 0x80) != 0 {
+ println!("Invalid ID3 size");
+ break;
+ }
+ size = (size << 7) | u64::from(b);
}
- size = (size << 7) | u64::from(b);
+ start += size + 10;
+ br.read_skip(size as usize).unwrap();
+ is_raw = true;
+ } else {
+ break;
}
- start = size + 10;
- is_raw = true;
}
// check for ID3v1
br.seek(SeekFrom::End(-128)).unwrap();
br.peek_buf(&mut buf[..3]).unwrap();
if &buf[0..3] == b"TAG" {
end = Some(off);
+ // check for Lyrics v2
+ let mut sig = [0; 9];
+ br.seek(SeekFrom::End(-128 - 9)).unwrap();
+ br.peek_buf(&mut sig).unwrap();
+ if &sig == b"LYRICS200" {
+ br.seek(SeekFrom::Current(-6)).unwrap();
+ let mut sizestr = [0; 6];
+ br.peek_buf(&mut sizestr).unwrap();
+ if let Ok(sstr) = std::str::from_utf8(&sizestr) {
+ if let Ok(size) = sstr.parse::<u64>() {
+ end = Some(br.tell() - size);
+ }
+ }
+ }
}
// check for APETAG
let mut buf = [0; 8];