add nihav-llaudio crate with FLAC, Monkey's Audio, TTA and WavPack support
[nihav.git] / nihav-registry / src / detect.rs
index 2621000eb889edbd45e536f7b5613175bf313269..210d0008faa25b5540ce0eb1bde16241dd4d960c 100644 (file)
@@ -254,6 +254,28 @@ const DETECTORS: &[DetectConditions] = &[
         extensions: ".smk",
         conditions: &[CheckItem{offs: 0, cond: &CC::Or(&CC::Str(b"SMK2"), &CC::Str(b"SMK4"))}],
     },
+    DetectConditions {
+        demux_name: "ape",
+        extensions: ".ape",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"MAC ") },
+                      CheckItem{offs: 4, cond: &CC::In(Arg::U16LE(3800), Arg::U16LE(3990))}],
+    },
+    DetectConditions {
+        demux_name: "flac",
+        extensions: ".flac",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"fLaC") }],
+    },
+    DetectConditions {
+        demux_name: "tta",
+        extensions: ".tta",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"TTA1") }],
+    },
+    DetectConditions {
+        demux_name: "wavpack",
+        extensions: ".wv",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"wvpk") },
+                      CheckItem{offs: 8, cond: &CC::In(Arg::U16LE(0x402), Arg::U16LE(0x410))}],
+    },
     DetectConditions {
         demux_name: "vivo",
         extensions: ".viv",
@@ -282,6 +304,11 @@ const DETECTORS: &[DetectConditions] = &[
         extensions: ".vmd",
         conditions: &[],
     },
+    DetectConditions {
+        demux_name: "vx",
+        extensions: ".vx",
+        conditions: &[CheckItem{offs: 0, cond: &CC::Str(b"VXDS") }],
+    },
 ];
 
 /// Tries to detect container format.
@@ -332,6 +359,22 @@ pub fn detect_format(name: &str, src: &mut ByteReader) -> Option<(&'static str,
     result
 }
 
+/// Tries to detect container format for provided file name.
+pub fn detect_format_by_name(name: &str) -> Option<(&'static str)> {
+    if name.is_empty() {
+        return None;
+    }
+    let lname = name.to_lowercase();
+    for detector in DETECTORS {
+        for ext in detector.extensions.split(',') {
+            if lname.ends_with(ext) {
+                return Some(detector.demux_name);
+            }
+        }
+    }
+    None
+}
+
 #[cfg(test)]
 mod test {
     use super::*;