mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-11-10 06:34:18 +00:00
Probe: Check custom resolvers before default implementations
This commit is contained in:
parent
6f1c84871d
commit
0019e22a40
2 changed files with 21 additions and 12 deletions
23
src/file.rs
23
src/file.rs
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
10
src/probe.rs
10
src/probe.rs
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue