diff --git a/example.audio-conv.yaml b/example.audio-conv.yaml index fd3d35f..805f595 100644 --- a/example.audio-conv.yaml +++ b/example.audio-conv.yaml @@ -1,14 +1,20 @@ from: ./music to: ./converted_test matches: - - glob: "**/*.flac" + - extensions: + - flac + - wav + # and/or `glob: "**/*.flac"` # and/or `regex: "\.flac$"` + # you can also leave it empty for the default extensions + to: codec: opus bitrate: 160 bitrate_type: vbr # or cbr # for mp3: + # to: # codec: mp3 # # one of: 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256 or 320 # bitrate: 256 diff --git a/src/config.rs b/src/config.rs index 96a54b6..a3156d7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -90,6 +90,7 @@ struct ConfigFile { struct TranscodeMatchFile { glob: Option, regex: Option, + extensions: Vec, to: Transcode, } @@ -160,24 +161,39 @@ pub fn config() -> Result { .matches .iter() .map(|m| { - let mut regexes = Vec::with_capacity(1); - - if let Some(glob) = &m.glob { + let glob = m.glob.iter().map(|glob| { let glob = GlobBuilder::new(glob) .case_insensitive(true) .build() .context("failed building glob")?; let regex = Regex::new(glob.regex()).context("failed compiling regex")?; - regexes.push(regex); - } + Ok(regex) + }); - if let Some(regex) = &m.regex { + let regex = m.regex.iter().map(|regex| { let regex = RegexBuilder::new(regex) .case_insensitive(true) .build() .context("failed compiling regex")?; - regexes.push(regex); - } + Ok(regex) + }); + + let extensions = m.extensions.iter().map(|ext| { + let mut ext = regex::escape(ext); + ext.insert_str(0, &"\\."); + ext.push_str("$"); + + let regex = RegexBuilder::new(&ext) + .case_insensitive(true) + .build() + .context("failed compiling regex")?; + Ok(regex) + }); + + let mut regexes = glob + .chain(regex) + .chain(extensions) + .collect::>>()?; if regexes.is_empty() { regexes.push(default_regex.clone());