From 4b56e8c9d1b60914c154720561ba759a343d5bbf Mon Sep 17 00:00:00 2001 From: Kostya Shishkov Date: Thu, 4 Jun 2020 18:29:09 +0200 Subject: [PATCH] registry: add detect_format_by_name() --- nihav-registry/src/detect.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nihav-registry/src/detect.rs b/nihav-registry/src/detect.rs index 2621000..92bb920 100644 --- a/nihav-registry/src/detect.rs +++ b/nihav-registry/src/detect.rs @@ -332,6 +332,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::*; -- 2.39.5