package at.pcgamingfreaks.mkvaudiosubtitlechanger.model; import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.converter.AttributeConfigConverter; import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidFile; import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidMkvToolNix; import jakarta.validation.constraints.Min; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.SystemUtils; import picocli.CommandLine; import java.io.File; import java.util.*; import java.util.regex.Pattern; import picocli.CommandLine.Option; @Slf4j @Getter @Setter @NoArgsConstructor @CommandLine.Command public class InputConfig implements CommandLine.IVersionProvider { private File configPath; @CommandLine.Spec CommandLine.Model.CommandSpec spec; @Option(names = {"-a", "--attribute-config"}, required = true, arity = "1..*", converter = AttributeConfigConverter.class, description = "List of audio:subtitle pairs used to match in order and update files accordingly (e.g. jpn:eng jpn:ger)") private AttributeConfig[] attributeConfig; @ValidFile(message = "does not exist") @Option(names = {"-l", "--library"}, required = true, description = "path to library") private File libraryPath; @ValidMkvToolNix(message = "does not exist") @Option(names = {"-m", "--mkvtoolnix"}, defaultValue = "${DEFAULT_MKV_TOOL_NIX}", description = "path to mkvtoolnix installation") private File mkvToolNix; @Option(names = {"-s", "--safemode"}, description = "test run (no files will be changes)") private boolean safeMode; @Min(1) @Option(names = {"-t", "--threads"}, defaultValue = "2", description = "thread count (default: ${DEFAULT-VALUE})") private int threads; @Min(0) @Option(names = {"-c", "--coherent"}, description = "try to match all files in dir of depth with the same attribute config. Attempting increasing deeper levels until match is found (worst case applying config on single file basis)") private Integer coherent; @Option(names = {"-cf", "--force-coherent"}, description = "only applies changes if a coherent match was found for the specifically entered depth") private boolean forceCoherent; // TODO: implement usage // @Option(names = {"-n", "--only-new-file"}, description = "sets filter-date to last successful execution (overwrites input of filter-date)") // private boolean onlyNewFiles; @Option(names = {"-d", "--filter-date"}, defaultValue = Option.NULL_VALUE, description = "only consider files created newer than entered date (format: \"dd.MM.yyyy-HH:mm:ss\")") private Date filterDate; @Option(names = {"-i", "--include-pattern"}, defaultValue = ".*", description = "include files matching pattern (default: \".*\")") private Pattern includePattern; @Option(names = {"-e", "--exclude"}, arity = "1..*", description = "relative directories and files to be excluded (no wildcard)") private Set excluded = new HashSet<>(); @Option(names = {"-o", "-overwrite-forced"}, description = "remove all forced flags") private boolean overwriteForced; @Option(names = {"--forced-keywords"}, arity = "1..*", defaultValue = "forced, signs, songs", split = ", ", description = "Keywords to identify forced tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})") private Set forcedKeywords; @Option(names = {"--commentary-keywords"}, arity = "1..*", defaultValue = "comment, commentary, director", split = ", ", description = "Keywords to identify commentary tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})") private Set commentaryKeywords; @Option(names = {"--hearing-impaired"}, arity = "1..*", defaultValue = "SDH, CC", split = ", ", description = "Keywords to identify hearing impaired tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE}") private Set hearingImpaired; @Option(names = {"--preferred-subtitles"}, arity = "1..*", defaultValue = "unstyled", split = ", ", description = "Keywords to prefer specific subtitle tracks (Defaults will be overwritten; Default: ${DEFAULT-VALUE})") private Set preferredSubtitles; @Option(names = {"--debug"}, description = "Enable debug logging") private boolean debug; static { // Set default value into system properties to picocli can read the conditional value System.setProperty("DEFAULT_MKV_TOOL_NIX", SystemUtils.IS_OS_WINDOWS ? "C:\\Program Files\\MKVToolNix" : "/usr/bin/"); } @Override public String toString() { return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]") .add("configPath=" + configPath) .add("spec=" + spec) .add("attributeConfig=" + Arrays.toString(attributeConfig)) .add("libraryPath=" + libraryPath) .add("mkvToolNix=" + mkvToolNix) .add("safeMode=" + safeMode) .add("threads=" + threads) .add("coherent=" + coherent) .add("forceCoherent=" + forceCoherent) .add("filterDate=" + filterDate) .add("includePattern=" + includePattern) .add("excluded=" + excluded) .add("overwriteForced=" + overwriteForced) .add("forcedKeywords=" + forcedKeywords) .add("commentaryKeywords=" + commentaryKeywords) .add("hearingImpaired=" + hearingImpaired) .add("preferredSubtitles=" + preferredSubtitles) .add("debug=" + debug) .toString(); } @Override public String[] getVersion() throws Exception { return new String[0]; } }