Probe: Check custom resolvers before default implementations

This commit is contained in:
Serial 2024-01-02 14:34:43 -05:00 committed by Alex
parent 6f1c84871d
commit 0019e22a40
2 changed files with 21 additions and 12 deletions

View file

@ -817,6 +817,16 @@ impl FileType {
{
let ext = ext.as_ref().to_str()?.to_ascii_lowercase();
// Give custom resolvers priority
if let Some((ty, _)) = custom_resolvers()
.lock()
.ok()?
.iter()
.find(|(_, f)| f.extension() == Some(ext.as_str()))
{
return Some(Self::Custom(ty));
}
match ext.as_str() {
"aac" => Some(Self::Aac),
"ape" => Some(Self::Ape),
@ -830,18 +840,7 @@ impl FileType {
"mp4" | "m4a" | "m4b" | "m4p" | "m4r" | "m4v" | "3gp" => Some(Self::Mp4),
"mpc" | "mp+" | "mpp" => Some(Self::Mpc),
"spx" => Some(Self::Speex),
e => {
if let Some((ty, _)) = custom_resolvers()
.lock()
.ok()?
.iter()
.find(|(_, f)| f.extension() == Some(e))
{
Some(Self::Custom(ty))
} else {
None
}
},
_ => None,
}
}

View file

@ -531,6 +531,16 @@ impl<R: Read + Seek> Probe<R> {
self.inner.seek(SeekFrom::Start(starting_position))?;
// Give custom resolvers priority
if let Ok(lock) = custom_resolvers().lock() {
#[allow(clippy::significant_drop_in_scrutinee)]
for (_, resolve) in lock.iter() {
if let ret @ Some(_) = resolve.guess(&buf[..buf_len]) {
return Ok(ret);
}
}
}
// Guess the file type by using these 36 bytes
match FileType::from_buffer_inner(&buf[..buf_len]) {
// We were able to determine a file type