mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-13 14:12:31 +00:00
Only read RIFF INFO LISTs instead of all LISTs
Signed-off-by: Serial <69764315+Serial-ATA@users.noreply.github.com>
This commit is contained in:
parent
c285b36629
commit
028afaa9ee
2 changed files with 67 additions and 56 deletions
|
@ -17,7 +17,7 @@ ape = {version = "0.3.0", optional = true}
|
|||
# Wav
|
||||
riff = {version = "1.0.1", optional = true}
|
||||
# Mp3
|
||||
id3 = {version = "0.6.3", optional = true} # De/Encoding
|
||||
id3 = {version = "0.6.4", optional = true} # De/Encoding
|
||||
mp3-duration = {version = "0.1.10", optional = true} # Duration
|
||||
# Ogg
|
||||
lewton = {version = "0.10.2", optional = true} # Decoding
|
||||
|
|
|
@ -11,21 +11,31 @@ where
|
|||
{
|
||||
let chunk = riff::Chunk::read(&mut data, 0)?;
|
||||
|
||||
let mut list: Option<riff::Chunk> = None;
|
||||
let mut lists: Vec<riff::Chunk> = Vec::new();
|
||||
|
||||
for child in chunk.iter(&mut data) {
|
||||
let chunk_id = child.id();
|
||||
let value_upper = std::str::from_utf8(&chunk_id.value)?.to_uppercase();
|
||||
let value_bytes = value_upper.as_bytes();
|
||||
|
||||
if value_bytes == LIST_ID {
|
||||
// TODO: actually check for the INFO id rather than any LIST
|
||||
list = Some(child);
|
||||
if &chunk_id.value == LIST_ID {
|
||||
lists.push(child)
|
||||
}
|
||||
}
|
||||
|
||||
return if lists.is_empty() {
|
||||
Err(Error::Wav(
|
||||
"This file doesn't contain a LIST chunk".to_string(),
|
||||
))
|
||||
} else {
|
||||
let mut info: Option<riff::Chunk> = None;
|
||||
|
||||
for child in lists {
|
||||
if &child.read_type(&mut data)?.value == b"INFO" {
|
||||
info = Some(child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return if let Some(list) = list {
|
||||
if let Some(list) = info {
|
||||
let mut content = list.read_contents(&mut data)?;
|
||||
|
||||
content.drain(0..4); // Get rid of the chunk ID
|
||||
|
@ -77,6 +87,7 @@ where
|
|||
Err(Error::Wav(
|
||||
"This file doesn't contain an INFO chunk".to_string(),
|
||||
))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue