summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKostya Shishkov <kostya.shishkov@gmail.com>2021-11-23 11:30:20 +0100
committerKostya Shishkov <kostya.shishkov@gmail.com>2021-11-23 11:30:20 +0100
commit695000c46091c478a9ed4bd7e5d3e7860eaad2c6 (patch)
tree1e805e9312d415a918b73aea0915045de484b634
parentdbca8a6d522fde14d236bb09e09d199259288267 (diff)
downloadnihav-player-695000c46091c478a9ed4bd7e5d3e7860eaad2c6.tar.gz
improve ID3 handling
-rw-r--r--sndplay/src/demux.rs45
1 files changed, 33 insertions, 12 deletions
diff --git a/sndplay/src/demux.rs b/sndplay/src/demux.rs
index ac483da..de9a067 100644
--- a/sndplay/src/demux.rs
+++ b/sndplay/src/demux.rs
@@ -281,20 +281,27 @@ pub fn detect_tags(br: &mut ByteReader) -> (bool, u64, Option<u64>) {
// 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();
@@ -302,6 +309,20 @@ pub fn detect_tags(br: &mut ByteReader) -> (bool, u64, Option<u64>) {
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];