From: Kostya Shishkov Date: Thu, 4 Jun 2020 16:29:09 +0000 (+0200) Subject: registry: add detect_format_by_name() X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=4b56e8c9d1b60914c154720561ba759a343d5bbf;p=nihav.git registry: add detect_format_by_name() --- 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::*;