mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Add property to include/exclude files by pattern
This commit is contained in:
@@ -20,11 +20,13 @@ Opening terminal / cmd in the directory of the jar and the config file and execu
|
|||||||
`java -jar mkvaudiosubtitleschanger.jar -l [path to mkv or dir with mkv]`
|
`java -jar mkvaudiosubtitleschanger.jar -l [path to mkv or dir with mkv]`
|
||||||
|
|
||||||
### Additional arameters
|
### Additional arameters
|
||||||
|
These properties overwrite already existing values in the config file.
|
||||||
```properties
|
```properties
|
||||||
-c,--config path to config
|
-c,--config path to config
|
||||||
-e,--exclude-directories <arg> Directories to exclude
|
-e,--exclude-directories <arg> Directories to exclude
|
||||||
-h,--help "for help this is" - Yoda
|
-h,--help "for help this is" - Yoda
|
||||||
-k,--forcedKeywords <arg> Additional keywords to identify forcedtracks"
|
-i,--include-pattern <arg> Include files matching pattern
|
||||||
|
-k,--forcedKeywords <arg> Additional keywords to identify forced tracks"
|
||||||
-l,--library <arg> path to library
|
-l,--library <arg> path to library
|
||||||
-s,--safe-mode Test run (no files will be changes)
|
-s,--safe-mode Test run (no files will be changes)
|
||||||
-t,--threads <arg> thread count
|
-t,--threads <arg> thread count
|
||||||
|
|||||||
@@ -41,6 +41,9 @@ public class Main {
|
|||||||
config.getForcedKeywords().addAll(List.of(cmd.getOptionValues(FORCED_KEYWORDS.prop())));
|
config.getForcedKeywords().addAll(List.of(cmd.getOptionValues(FORCED_KEYWORDS.prop())));
|
||||||
if (cmd.hasOption(EXCLUDE_DIRECTORY.prop()))
|
if (cmd.hasOption(EXCLUDE_DIRECTORY.prop()))
|
||||||
config.getExcludedDirectories().addAll(List.of(cmd.getOptionValues(EXCLUDE_DIRECTORY.prop())));
|
config.getExcludedDirectories().addAll(List.of(cmd.getOptionValues(EXCLUDE_DIRECTORY.prop())));
|
||||||
|
if (cmd.hasOption(INCLUDE_PATTERN.prop())) {
|
||||||
|
config.setIncludePattern(Config.compilePattern(cmd.getOptionValue(INCLUDE_PATTERN.prop()), INCLUDE_PATTERN));
|
||||||
|
}
|
||||||
config.isValid();
|
config.isValid();
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
log.error(e);
|
log.error(e);
|
||||||
@@ -58,6 +61,7 @@ public class Main {
|
|||||||
options.addOption(optionOf(SAFE_MODE, "s", false));
|
options.addOption(optionOf(SAFE_MODE, "s", false));
|
||||||
options.addOption(optionOf(FORCED_KEYWORDS, "k", Option.UNLIMITED_VALUES, false));
|
options.addOption(optionOf(FORCED_KEYWORDS, "k", Option.UNLIMITED_VALUES, false));
|
||||||
options.addOption(optionOf(EXCLUDE_DIRECTORY, "e", Option.UNLIMITED_VALUES, false));
|
options.addOption(optionOf(EXCLUDE_DIRECTORY, "e", Option.UNLIMITED_VALUES, false));
|
||||||
|
options.addOption(optionOf(INCLUDE_PATTERN, "i", true));
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,11 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.regex.PatternSyntaxException;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.MKV_TOOL_NIX;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
|
||||||
|
|
||||||
@Log4j2
|
@Log4j2
|
||||||
@Getter
|
@Getter
|
||||||
@@ -31,6 +33,7 @@ public class Config {
|
|||||||
private int threadCount;
|
private int threadCount;
|
||||||
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs"));
|
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs"));
|
||||||
private Set<String> excludedDirectories = new HashSet<>();
|
private Set<String> excludedDirectories = new HashSet<>();
|
||||||
|
private Pattern includePattern;
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private String mkvtoolnixPath;
|
private String mkvtoolnixPath;
|
||||||
private String libraryPath;
|
private String libraryPath;
|
||||||
@@ -75,6 +78,7 @@ public class Config {
|
|||||||
setWindows(System.getProperty("os.name").toLowerCase().contains("windows"));
|
setWindows(System.getProperty("os.name").toLowerCase().contains("windows"));
|
||||||
getForcedKeywords().addAll(loadForcedKeywords(config));
|
getForcedKeywords().addAll(loadForcedKeywords(config));
|
||||||
getExcludedDirectories().addAll(loadExcludeDirectories(config));
|
getExcludedDirectories().addAll(loadExcludeDirectories(config));
|
||||||
|
loadIncludePattern(config);
|
||||||
} catch (YamlInvalidContentException | YamlKeyNotFoundException | IOException e) {
|
} catch (YamlInvalidContentException | YamlKeyNotFoundException | IOException e) {
|
||||||
log.fatal("Config could not be loaded: {}", e.getMessage());
|
log.fatal("Config could not be loaded: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
@@ -105,6 +109,23 @@ public class Config {
|
|||||||
return config.getStringList(ConfigProperty.EXCLUDE_DIRECTORY.prop(), new ArrayList<>());
|
return config.getStringList(ConfigProperty.EXCLUDE_DIRECTORY.prop(), new ArrayList<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadIncludePattern(YAML config) throws YamlKeyNotFoundException {
|
||||||
|
if (config.isSet(INCLUDE_PATTERN.prop())) {
|
||||||
|
includePattern = compilePattern(config.getString(INCLUDE_PATTERN.prop()), INCLUDE_PATTERN);
|
||||||
|
} else {
|
||||||
|
includePattern = Pattern.compile(".*");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Pattern compilePattern(String pattern, ConfigProperty origin) {
|
||||||
|
try {
|
||||||
|
return Pattern.compile(pattern);
|
||||||
|
} catch (PatternSyntaxException e) {
|
||||||
|
log.error("{} is not a valid regex pattern!", origin.prop());
|
||||||
|
throw new RuntimeException(String.format("%s is not a valid regex pattern!%n", origin.prop()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String loadMkvToolNixPath(YAML config) throws YamlKeyNotFoundException {
|
private String loadMkvToolNixPath(YAML config) throws YamlKeyNotFoundException {
|
||||||
return config.isSet(MKV_TOOL_NIX.prop())
|
return config.isSet(MKV_TOOL_NIX.prop())
|
||||||
? config.getString(MKV_TOOL_NIX.prop())
|
? config.getString(MKV_TOOL_NIX.prop())
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -28,6 +29,7 @@ public class MkvFileCollector implements FileCollector {
|
|||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.map(Path::toFile)
|
.map(Path::toFile)
|
||||||
.filter(f -> f.getAbsolutePath().endsWith(".mkv"))
|
.filter(f -> f.getAbsolutePath().endsWith(".mkv"))
|
||||||
|
.filter(f -> Config.getInstance().getIncludePattern().matcher(f.getName()).matches())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Couldn't find file or directory!", e);
|
log.error("Couldn't find file or directory!", e);
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ public enum ConfigProperty {
|
|||||||
LIBRARY("library", "path to library"),
|
LIBRARY("library", "path to library"),
|
||||||
SAFE_MODE("safe-mode", "Test run (no files will be changes)"),
|
SAFE_MODE("safe-mode", "Test run (no files will be changes)"),
|
||||||
HELP("help", "\"for help this is\" - Yoda"),
|
HELP("help", "\"for help this is\" - Yoda"),
|
||||||
EXCLUDE_DIRECTORY("exclude-directories", "Directories to exclude");
|
EXCLUDE_DIRECTORY("exclude-directories", "Directories to exclude"),
|
||||||
|
INCLUDE_PATTERN("include-pattern", "Include files matching pattern");
|
||||||
|
|
||||||
private final String property;
|
private final String property;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|||||||
Reference in New Issue
Block a user