mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Rework app to use picocli
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>at.pcgamingfreaks</groupId>
|
<groupId>at.pcgamingfreaks</groupId>
|
||||||
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
||||||
<version>3.0.2</version>
|
<version>4.0.0</version>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<defaultGoal>clean package</defaultGoal>
|
<defaultGoal>clean package</defaultGoal>
|
||||||
@@ -127,6 +127,11 @@
|
|||||||
<version>1.18.24</version>
|
<version>1.18.24</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>info.picocli</groupId>
|
||||||
|
<artifactId>picocli</artifactId>
|
||||||
|
<version>4.7.6</version>
|
||||||
|
</dependency>
|
||||||
<!-- region logging -->
|
<!-- region logging -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.logging.log4j</groupId>
|
<groupId>org.apache.logging.log4j</groupId>
|
||||||
|
|||||||
@@ -1,21 +1,34 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ConfigLoader;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CachedMkvFileProcessor;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.CachedMkvFileProcessor;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.AttributeUpdaterKernel;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.AttributeUpdaterKernel;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.CoherentAttributeUpdaterKernel;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.CoherentAttributeUpdaterKernel;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.DefaultAttributeUpdaterKernel;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel.DefaultAttributeUpdaterKernel;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.MkvFileCollector;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.MkvFileCollector;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class Main {
|
@CommandLine.Command(mixinStandardHelpOptions = true, versionProvider = ProjectUtil.class)
|
||||||
public static void main(String[] args) {
|
public class Main implements Runnable {
|
||||||
ConfigLoader.initConfig(args);
|
|
||||||
|
@Getter
|
||||||
|
@CommandLine.ArgGroup(exclusive = false)
|
||||||
|
private Config config = Config.getInstance();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Config.setInstance(config);
|
||||||
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null
|
AttributeUpdaterKernel kernel = Config.getInstance().getCoherent() != null
|
||||||
? new CoherentAttributeUpdaterKernel(new MkvFileCollector(), new CachedMkvFileProcessor())
|
? new CoherentAttributeUpdaterKernel(new MkvFileCollector(), new CachedMkvFileProcessor())
|
||||||
: new DefaultAttributeUpdaterKernel(new MkvFileCollector(), new CachedMkvFileProcessor());
|
: new DefaultAttributeUpdaterKernel(new MkvFileCollector(), new CachedMkvFileProcessor());
|
||||||
kernel.execute();
|
kernel.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new CommandLine(Main.class).execute(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isAudioLanguageValid;
|
||||||
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isLanguageValid;
|
||||||
|
|
||||||
|
public class AttributeConfigConverter implements CommandLine.ITypeConverter<AttributeConfig> {
|
||||||
|
private static final String SEPARATOR = ":";
|
||||||
|
private static final Pattern PATTERN = Pattern.compile("^.{3}:.{3}$");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the input string into an AttributeConfig object.
|
||||||
|
*
|
||||||
|
* @param s The input string containing audio and subtitle language configuration in format "audioLang:subtitleLang"
|
||||||
|
* @return An AttributeConfig object representing the parsed configuration
|
||||||
|
* @throws CommandLine.TypeConversionException if the input string is invalid or contains invalid language codes
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public AttributeConfig convert(String s) throws Exception {
|
||||||
|
validateInput(s);
|
||||||
|
|
||||||
|
String[] split = s.split(SEPARATOR);
|
||||||
|
AttributeConfig attr = new AttributeConfig(split[0], split[1]);
|
||||||
|
|
||||||
|
validateResult(attr);
|
||||||
|
|
||||||
|
return attr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates that the input string matches the expected pattern.
|
||||||
|
*
|
||||||
|
* @param s String to validate
|
||||||
|
* @throws CommandLine.TypeConversionException if the value doesn't match the expected pattern
|
||||||
|
*/
|
||||||
|
private static void validateInput(String s) {
|
||||||
|
if (!PATTERN.matcher(s).matches()) {
|
||||||
|
throw new CommandLine.TypeConversionException("Invalid Attribute config: " + s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates that both language codes in the AttributeConfig object are valid.
|
||||||
|
*
|
||||||
|
* @param attr AttributeConfig object to validate
|
||||||
|
* @throws CommandLine.TypeConversionException if either language code is invalid
|
||||||
|
*/
|
||||||
|
private static void validateResult(AttributeConfig attr) {
|
||||||
|
if (!isAudioLanguageValid(attr.getAudioLanguage()))
|
||||||
|
throw new CommandLine.TypeConversionException("Audio language invalid: " + attr.getAudioLanguage());
|
||||||
|
if (!isLanguageValid(attr.getSubtitleLanguage()))
|
||||||
|
throw new CommandLine.TypeConversionException("Subtitle language invalid: " + attr.getSubtitleLanguage());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.apache.commons.cli.CommandLineParser;
|
import org.apache.commons.cli.CommandLineParser;
|
||||||
import org.apache.commons.cli.DefaultParser;
|
import org.apache.commons.cli.DefaultParser;
|
||||||
import org.apache.commons.cli.HelpFormatter;
|
import org.apache.commons.cli.HelpFormatter;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -18,7 +19,7 @@ import java.util.regex.Pattern;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor
|
||||||
public class Config {
|
public class Config {
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
@Setter(AccessLevel.NONE)
|
@Setter(AccessLevel.NONE)
|
||||||
@@ -27,25 +28,40 @@ public class Config {
|
|||||||
CommandLineParser parser = new DefaultParser();
|
CommandLineParser parser = new DefaultParser();
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
|
|
||||||
private File configPath;
|
private File configPath;
|
||||||
|
@CommandLine.Option(names = {"-l", "--library"}, required = true, description = "path to library")
|
||||||
private File libraryPath;
|
private File libraryPath;
|
||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
|
@CommandLine.Option(names = {"-m", "--mkvtoolnix"}, defaultValue = "C:\\Program Files\\MKVToolNix", description = "path to mkvtoolnix installation")
|
||||||
private File mkvToolNix;
|
private File mkvToolNix;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = {"-t", "--threads"}, defaultValue = "2", description = "thread count (default: 2)")
|
||||||
private int threads;
|
private int threads;
|
||||||
|
@CommandLine.Option(names = {"-i", "--include-pattern"}, defaultValue = ".*", description = "include files matching pattern (default: \".*\")")
|
||||||
private Pattern includePattern;
|
private Pattern includePattern;
|
||||||
|
@CommandLine.Option(names = {"-s", "--safemode"}, description = "test run (no files will be changes)")
|
||||||
private boolean safeMode;
|
private boolean safeMode;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = {"-c", "--coherent"}, description = "try to match all files in dir of depth with the same attribute config")
|
||||||
private Integer coherent;
|
private Integer coherent;
|
||||||
|
@CommandLine.Option(names = {"-cf", "--force-coherent"}, description = "changes are only applied if it's a coherent match")
|
||||||
private boolean forceCoherent;
|
private boolean forceCoherent;
|
||||||
|
@CommandLine.Option(names = {"-n"}, description = "sets filter-date to last successful execution (overwrites input of filter-date)")
|
||||||
private boolean onlyNewFiles;
|
private boolean onlyNewFiles;
|
||||||
|
@CommandLine.Option(names = {"-d", "--filter-date"}, defaultValue = CommandLine.Option.NULL_VALUE, description = "only consider files created newer than entered date (format: \"dd.MM.yyyy-HH:mm:ss\")")
|
||||||
private Date filterDate;
|
private Date filterDate;
|
||||||
|
|
||||||
|
@CommandLine.Option(names = {"-fk", "--force-keywords"}, description = "Additional keywords to identify forced tracks")
|
||||||
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
|
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
|
||||||
|
@CommandLine.Option(names = {"-ck", "--commentary-keywords"}, description = "Additional keywords to identify commentary tracks")
|
||||||
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));
|
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));
|
||||||
|
@CommandLine.Option(names = {"-e", "--excluded-directory"}, description = "Directories to be excluded, combines with config file")
|
||||||
private Set<String> excludedDirectories = new HashSet<>();
|
private Set<String> excludedDirectories = new HashSet<>();
|
||||||
|
@CommandLine.Option(names = {"-ps", "--preferred-subtiltes"}, description = "Additional keywords to prefer specific subtitle tracks")
|
||||||
private Set<String> preferredSubtitles = new HashSet<>(Arrays.asList("unstyled"));
|
private Set<String> preferredSubtitles = new HashSet<>(Arrays.asList("unstyled"));
|
||||||
|
|
||||||
|
@CommandLine.Option(names = {"-a"}, required = true, arity = "1..*", converter = AttributeConfigConverter.class)
|
||||||
private List<AttributeConfig> attributeConfig;
|
private List<AttributeConfig> attributeConfig;
|
||||||
|
|
||||||
public static Config getInstance() {
|
public static Config getInstance() {
|
||||||
@@ -59,6 +75,10 @@ public class Config {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setInstance(Config c) {
|
||||||
|
config = c;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get path to specific mkvtoolnix application.
|
* Get path to specific mkvtoolnix application.
|
||||||
*
|
*
|
||||||
@@ -66,7 +86,7 @@ public class Config {
|
|||||||
*/
|
*/
|
||||||
public String getPathFor(MkvToolNix application) {
|
public String getPathFor(MkvToolNix application) {
|
||||||
return mkvToolNix.getAbsolutePath().endsWith("/") ? mkvToolNix.getAbsolutePath() + application :
|
return mkvToolNix.getAbsolutePath().endsWith("/") ? mkvToolNix.getAbsolutePath() + application :
|
||||||
mkvToolNix.getAbsolutePath() + "/" + application;
|
mkvToolNix.getAbsolutePath() + "/" + application;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getNormalizedLibraryPath() {
|
public String getNormalizedLibraryPath() {
|
||||||
|
|||||||
@@ -1,110 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator.*;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
|
||||||
import at.pcgamingfreaks.yaml.YAML;
|
|
||||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
|
||||||
import org.apache.commons.cli.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
|
||||||
|
|
||||||
public class ConfigLoader {
|
|
||||||
private static final List<ConfigValidator<?>> VALIDATORS = Stream.of(
|
|
||||||
new ConfigPathValidator(CONFIG_PATH, false),
|
|
||||||
new PathValidator(LIBRARY, true, null),
|
|
||||||
new ThreadValidator(THREADS, false, 2),
|
|
||||||
new MkvToolNixPathValidator(MKV_TOOL_NIX, true, Path.of("C:\\Program Files\\MKVToolNix").toFile()),
|
|
||||||
new BooleanValidator(SAFE_MODE, false),
|
|
||||||
new BooleanValidator(ONLY_NEW_FILES, false),
|
|
||||||
new DateValidator(FILTER_DATE, false),
|
|
||||||
new PatternValidator(INCLUDE_PATTERN, false, Pattern.compile(".*")),
|
|
||||||
new SetValidator(FORCED_KEYWORDS, false, true),
|
|
||||||
new SetValidator(COMMENTARY_KEYWORDS, false, true),
|
|
||||||
new SetValidator(EXCLUDED_DIRECTORY, false, true),
|
|
||||||
new SetValidator(PREFERRED_SUBTITLES, false, true),
|
|
||||||
new AttributeConfigValidator(),
|
|
||||||
new CoherentConfigValidator(COHERENT, false),
|
|
||||||
new BooleanValidator(FORCE_COHERENT, false)
|
|
||||||
).sorted(Comparator.comparing((ConfigValidator<?> validator) -> validator.getWeight()).reversed()).collect(Collectors.toList());
|
|
||||||
|
|
||||||
public static void initConfig(String[] args) {
|
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
|
||||||
formatter.setOptionComparator(null);
|
|
||||||
YAML yamlConfig = null;
|
|
||||||
|
|
||||||
Options options = initOptions();
|
|
||||||
CommandLine cmd = parseCommandLineArgs(formatter, options, args);
|
|
||||||
|
|
||||||
exitIfHelp(cmd, options, formatter);
|
|
||||||
exitIfVersion(cmd);
|
|
||||||
|
|
||||||
List<ValidationResult> results = new ArrayList<>();
|
|
||||||
|
|
||||||
for (ConfigValidator<?> validator: VALIDATORS) {
|
|
||||||
results.add(validator.validate(yamlConfig, cmd));
|
|
||||||
if (yamlConfig == null) {
|
|
||||||
try {
|
|
||||||
yamlConfig = Config.getInstance().getConfigPath() != null
|
|
||||||
? new YAML(Config.getInstance().getConfigPath())
|
|
||||||
: new YAML("");
|
|
||||||
} catch (IOException | YamlInvalidContentException ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (results.contains(ValidationResult.INVALID) || results.contains(ValidationResult.MISSING)) System.exit(1);
|
|
||||||
System.out.println();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Options initOptions() {
|
|
||||||
Options options = new Options();
|
|
||||||
Arrays.stream(ConfigProperty.values())
|
|
||||||
.filter(prop -> prop.abrv() != null)
|
|
||||||
.map(prop -> optionOf(prop, prop.abrv(), prop.args()))
|
|
||||||
.forEach(options::addOption);
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CommandLine parseCommandLineArgs(HelpFormatter formatter, Options options, String[] args) {
|
|
||||||
CommandLineParser parser = new DefaultParser();
|
|
||||||
|
|
||||||
try {
|
|
||||||
CommandLine cmd = parser.parse(options, args);
|
|
||||||
if (cmd == null) throw new NullPointerException();
|
|
||||||
return cmd;
|
|
||||||
} catch (ParseException | NullPointerException e) {
|
|
||||||
formatter.printHelp(130, "java -jar MKVAudioSubtitlesChanger.jar -l <path_to_library>",
|
|
||||||
"\nParameters:", options,
|
|
||||||
"\nFeature requests and bug reports: https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/issues");
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
return null; // can't be reached
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void exitIfHelp(CommandLine cmd, Options options, HelpFormatter formatter) {
|
|
||||||
if (cmd.hasOption(HELP.prop())) {
|
|
||||||
formatter.printHelp(130, "java -jar MKVAudioSubtitlesChanger.jar -l <path_to_library>",
|
|
||||||
"\nParameters:", options,
|
|
||||||
"\nFeature requests and bug reports: https://github.com/RatzzFatzz/MKVAudioSubtitleChanger/issues");
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void exitIfVersion(CommandLine cmd) {
|
|
||||||
if (cmd.hasOption(VERSION.prop())) {
|
|
||||||
System.out.printf("MKV Audio Subtitle Changer Version %s%n", ProjectUtil.getVersion());
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public enum ValidationResult {
|
public enum ValidationResult {
|
||||||
VALID,
|
VALID,
|
||||||
DEFAULT,
|
DEFAULT,
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.stream.Collectors;
|
|||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isAudioLanguageValid;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isAudioLanguageValid;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isLanguageValid;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.LanguageValidatorUtil.isLanguageValid;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class AttributeConfigValidator extends ConfigValidator<List<AttributeConfig>> {
|
public class AttributeConfigValidator extends ConfigValidator<List<AttributeConfig>> {
|
||||||
private static final String SEPARATOR = ":";
|
private static final String SEPARATOR = ":";
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import java.util.function.BiFunction;
|
|||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.ARGUMENTS;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.ARGUMENTS;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class BooleanValidator extends ConfigValidator<Boolean> {
|
public class BooleanValidator extends ConfigValidator<Boolean> {
|
||||||
|
|
||||||
public BooleanValidator(ConfigProperty property, boolean required) {
|
public BooleanValidator(ConfigProperty property, boolean required) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class CoherentConfigValidator extends ConfigValidator<Integer> {
|
public class CoherentConfigValidator extends ConfigValidator<Integer> {
|
||||||
private static final Integer DISABLED = -1;
|
private static final Integer DISABLED = -1;
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import java.io.File;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class ConfigPathValidator extends PathValidator {
|
public class ConfigPathValidator extends PathValidator {
|
||||||
public ConfigPathValidator(ConfigProperty property, boolean required) {
|
public ConfigPathValidator(ConfigProperty property, boolean required) {
|
||||||
super(property, required, null);
|
super(property, required, null);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import java.util.function.Predicate;
|
|||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Deprecated
|
||||||
public abstract class ConfigValidator<FieldType> {
|
public abstract class ConfigValidator<FieldType> {
|
||||||
protected final ConfigProperty property;
|
protected final ConfigProperty property;
|
||||||
protected final boolean required;
|
protected final boolean required;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import java.nio.file.Path;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Deprecated
|
||||||
public class DateValidator extends ConfigValidator<Date> {
|
public class DateValidator extends ConfigValidator<Date> {
|
||||||
private static final Date INVALID_DATE = new Date(0);
|
private static final Date INVALID_DATE = new Date(0);
|
||||||
private static final Date DEFAULT_DATE = new Date(1000);
|
private static final Date DEFAULT_DATE = new Date(1000);
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import java.nio.file.Path;
|
|||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix.MKV_MERGER;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix.MKV_MERGER;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix.MKV_PROP_EDIT;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.MkvToolNix.MKV_PROP_EDIT;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class MkvToolNixPathValidator extends PathValidator {
|
public class MkvToolNixPathValidator extends PathValidator {
|
||||||
private static final String EXE = ".exe";
|
private static final String EXE = ".exe";
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class PathValidator extends ConfigValidator<File> {
|
public class PathValidator extends ConfigValidator<File> {
|
||||||
|
|
||||||
public PathValidator(ConfigProperty property, boolean required, File defaultValue) {
|
public PathValidator(ConfigProperty property, boolean required, File defaultValue) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.PatternSyntaxException;
|
import java.util.regex.PatternSyntaxException;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class PatternValidator extends ConfigValidator<Pattern> {
|
public class PatternValidator extends ConfigValidator<Pattern> {
|
||||||
private static final Pattern EMPTY_PATTERN = Pattern.compile("");
|
private static final Pattern EMPTY_PATTERN = Pattern.compile("");
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import java.util.*;
|
|||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class SetValidator extends ConfigValidator<Set<String>> {
|
public class SetValidator extends ConfigValidator<Set<String>> {
|
||||||
private final boolean append;
|
private final boolean append;
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||||
import org.apache.commons.lang3.math.NumberUtils;
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class ThreadValidator extends ConfigValidator<Integer>{
|
public class ThreadValidator extends ConfigValidator<Integer>{
|
||||||
public ThreadValidator(ConfigProperty property, boolean required, Integer defaultValue) {
|
public ThreadValidator(ConfigProperty property, boolean required, Integer defaultValue) {
|
||||||
super(property, required, defaultValue);
|
super(property, required, defaultValue);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import me.tongfei.progressbar.ProgressBar;
|
|||||||
import me.tongfei.progressbar.ProgressBarBuilder;
|
import me.tongfei.progressbar.ProgressBarBuilder;
|
||||||
import me.tongfei.progressbar.ProgressBarStyle;
|
import me.tongfei.progressbar.ProgressBarStyle;
|
||||||
import net.harawata.appdirs.AppDirsFactory;
|
import net.harawata.appdirs.AppDirsFactory;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class LanguageValidatorUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isAudioLanguageValid(String language) {
|
public static boolean isAudioLanguageValid(String language) {
|
||||||
return !language.equals("OFF") && ISO3_LANGUAGES.contains(language);
|
return !language.equals("OFF") && isLanguageValid(language);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isLanguageValid(String language) {
|
public static boolean isLanguageValid(String language) {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
public class ProjectUtil {
|
public class ProjectUtil implements CommandLine.IVersionProvider {
|
||||||
private static final Properties PROJECT_PROPERTIES = new Properties();
|
private static final Properties PROJECT_PROPERTIES = new Properties();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
@@ -15,8 +17,8 @@ public class ProjectUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getVersion() {
|
public String[] getVersion() {
|
||||||
return PROJECT_PROPERTIES.getProperty("version");
|
return new String[] {getProjectName() + " " + PROJECT_PROPERTIES.getProperty("version")};
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getProjectName() {
|
public static String getProjectName() {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
|||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import picocli.CommandLine;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ class ConfigLoaderTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void initConfig() {
|
void initConfig() {
|
||||||
String[] sut = new String[]{"-a", "ger:ger", "-l", TEST_FILE,
|
String[] sut = new String[]{"-a", "ger:ger", "eng:eng", "-l", TEST_FILE,
|
||||||
"-s", "-cf", "-n",
|
"-s", "-cf", "-n",
|
||||||
"-c", "2",
|
"-c", "2",
|
||||||
"-t", "4",
|
"-t", "4",
|
||||||
@@ -21,15 +22,16 @@ class ConfigLoaderTest {
|
|||||||
"-ck", "testCommentary",
|
"-ck", "testCommentary",
|
||||||
"-ps", "testPreferred"
|
"-ps", "testPreferred"
|
||||||
};
|
};
|
||||||
ConfigLoader.initConfig(sut);
|
CommandLine.populateCommand(Config.getInstance(), sut);
|
||||||
|
|
||||||
assertTrue(Config.getInstance().getLibraryPath().exists());
|
assertTrue(Config.getInstance().getLibraryPath().exists());
|
||||||
assertEquals(List.of(new AttributeConfig("ger", "ger")), Config.getInstance().getAttributeConfig());
|
assertEquals(List.of(new AttributeConfig("ger", "ger"), new AttributeConfig("eng", "eng")),
|
||||||
|
Config.getInstance().getAttributeConfig());
|
||||||
|
|
||||||
assertTrue(Config.getInstance().isSafeMode());
|
assertTrue(Config.getInstance().isSafeMode());
|
||||||
assertTrue(Config.getInstance().isForceCoherent());
|
assertTrue(Config.getInstance().isForceCoherent());
|
||||||
assertTrue(Config.getInstance().isOnlyNewFiles());
|
assertTrue(Config.getInstance().isOnlyNewFiles());
|
||||||
assertNotNull(Config.getInstance().getFilterDate());
|
assertNull(Config.getInstance().getFilterDate());
|
||||||
|
|
||||||
assertEquals(2, Config.getInstance().getCoherent());
|
assertEquals(2, Config.getInstance().getCoherent());
|
||||||
assertEquals(4, Config.getInstance().getThreads());
|
assertEquals(4, Config.getInstance().getThreads());
|
||||||
|
|||||||
Reference in New Issue
Block a user