add support for extensions matching
This commit is contained in:
@@ -1,14 +1,20 @@
|
|||||||
from: ./music
|
from: ./music
|
||||||
to: ./converted_test
|
to: ./converted_test
|
||||||
matches:
|
matches:
|
||||||
- glob: "**/*.flac"
|
- extensions:
|
||||||
|
- flac
|
||||||
|
- wav
|
||||||
|
# and/or `glob: "**/*.flac"`
|
||||||
# and/or `regex: "\.flac$"`
|
# and/or `regex: "\.flac$"`
|
||||||
|
# you can also leave it empty for the default extensions
|
||||||
|
|
||||||
to:
|
to:
|
||||||
codec: opus
|
codec: opus
|
||||||
bitrate: 160
|
bitrate: 160
|
||||||
bitrate_type: vbr # or cbr
|
bitrate_type: vbr # or cbr
|
||||||
|
|
||||||
# for mp3:
|
# for mp3:
|
||||||
|
# to:
|
||||||
# codec: mp3
|
# codec: mp3
|
||||||
# # one of: 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256 or 320
|
# # one of: 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256 or 320
|
||||||
# bitrate: 256
|
# bitrate: 256
|
||||||
|
|||||||
@@ -90,6 +90,7 @@ struct ConfigFile {
|
|||||||
struct TranscodeMatchFile {
|
struct TranscodeMatchFile {
|
||||||
glob: Option<String>,
|
glob: Option<String>,
|
||||||
regex: Option<String>,
|
regex: Option<String>,
|
||||||
|
extensions: Vec<String>,
|
||||||
to: Transcode,
|
to: Transcode,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,24 +161,39 @@ pub fn config() -> Result<Config> {
|
|||||||
.matches
|
.matches
|
||||||
.iter()
|
.iter()
|
||||||
.map(|m| {
|
.map(|m| {
|
||||||
let mut regexes = Vec::with_capacity(1);
|
let glob = m.glob.iter().map(|glob| {
|
||||||
|
|
||||||
if let Some(glob) = &m.glob {
|
|
||||||
let glob = GlobBuilder::new(glob)
|
let glob = GlobBuilder::new(glob)
|
||||||
.case_insensitive(true)
|
.case_insensitive(true)
|
||||||
.build()
|
.build()
|
||||||
.context("failed building glob")?;
|
.context("failed building glob")?;
|
||||||
let regex = Regex::new(glob.regex()).context("failed compiling regex")?;
|
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)
|
let regex = RegexBuilder::new(regex)
|
||||||
.case_insensitive(true)
|
.case_insensitive(true)
|
||||||
.build()
|
.build()
|
||||||
.context("failed compiling regex")?;
|
.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::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
if regexes.is_empty() {
|
if regexes.is_empty() {
|
||||||
regexes.push(default_regex.clone());
|
regexes.push(default_regex.clone());
|
||||||
|
|||||||
Reference in New Issue
Block a user