Add support for multiple library paths

This commit is contained in:
RatzzFatzz
2025-12-28 23:59:33 +01:00
parent 31b155d8a3
commit be004e6146
5 changed files with 20 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
import me.tongfei.progressbar.ProgressBarBuilder;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -25,7 +26,9 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
}
protected List<File> getFiles() {
return fileProcessor.loadDirectory(config.getLibraryPath().getPath(), config.getCoherent());
return Arrays.stream(config.getLibraryPaths())
.flatMap(path -> fileProcessor.loadDirectory(path.getPath(), config.getCoherent()).stream())
.toList();
}
@Override

View File

@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
import me.tongfei.progressbar.ProgressBarBuilder;
import java.io.File;
import java.util.Arrays;
import java.util.List;
@Slf4j
@@ -23,7 +24,9 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
@Override
protected List<File> getFiles() {
return fileProcessor.loadFiles(config.getLibraryPath().getPath());
return Arrays.stream(config.getLibraryPaths())
.flatMap(path -> fileProcessor.loadFiles(path.getPath()).stream())
.toList();
}
@Override

View File

@@ -4,14 +4,15 @@ import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.io.File;
import java.util.Arrays;
public class ValidFileValidator implements ConstraintValidator<ValidFile, File> {
public class ValidFileValidator implements ConstraintValidator<ValidFile, File[]> {
@Override
public void initialize(ValidFile constraintAnnotation) {
}
@Override
public boolean isValid(File file, ConstraintValidatorContext context) {
return file != null && file.exists();
public boolean isValid(File[] files, ConstraintValidatorContext context) {
return files != null && files.length > 0 && Arrays.stream(files).allMatch(File::exists);
}
}

View File

@@ -29,8 +29,8 @@ public class InputConfig implements CommandLine.IVersionProvider {
CommandLine.Model.CommandSpec spec;
@ValidFile(message = "does not exist")
@CommandLine.Parameters(description = "path to library")
private File libraryPath;
@CommandLine.Parameters(description = "paths to library", arity = "1..*")
private File[] libraryPaths;
@Option(names = {"-a", "--attribute-config"}, arity = "1..*", converter = AttributeConfigConverter.class,
description = "List of audio:subtitle pairs for matching defaults in order (e.g. jpn:eng jpn:ger)")
@@ -91,7 +91,7 @@ public class InputConfig implements CommandLine.IVersionProvider {
return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]")
.add("configPath=" + configPath)
.add("spec=" + spec)
.add("libraryPath=" + libraryPath)
.add("libraryPath=" + libraryPaths)
.add("attributeConfig=" + Arrays.toString(attributeConfig))
.add("mkvToolNix=" + mkvToolNix)
.add("safeMode=" + safeMode)

View File

@@ -12,7 +12,6 @@ import java.io.StringWriter;
import java.util.stream.Stream;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.*;
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
import static org.junit.jupiter.api.Assertions.*;
class ValidationExecutionStrategyTest {
@@ -24,16 +23,17 @@ class ValidationExecutionStrategyTest {
.setExecutionStrategy(new ValidationExecutionStrategy())
.parseArgs("-a", "ger:ger", "-m", TEST_MKVTOOLNIX_DIR, TEST_FILE);
assertEquals(TEST_FILE, underTest.getConfig().getLibraryPath().getPath().replace("\\", "/"));
assertEquals(TEST_FILE, underTest.getConfig().getLibraryPaths()[0].getPath().replace("\\", "/"));
assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/"));
}
private static Stream<Arguments> validateFailure() {
return Stream.of(
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): <libraryPath>"),
Arguments.of(new String[]{"/arstarstarst"}, "libraryPath does not exist"),
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): <libraryPaths>"),
Arguments.of(new String[]{"/arstarstarst"}, "libraryPaths does not exist"),
Arguments.of(new String[]{TEST_DIR + " /arstarstarst"}, "libraryPaths does not exist"),
Arguments.of(new String[]{"/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 (<attributeConfig>)"),
Arguments.of(new String[]{"/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"),
Arguments.of(new String[]{"/arstarstarst", "-a", "jpn:ger"}, "libraryPaths does not exist"),
Arguments.of(new String[]{"/arstarstarst", "-m"}, "Missing required parameter for option '--mkvtoolnix' (<mkvToolNix>)"),
Arguments.of(new String[]{"./", "-m", TEST_INVALID_DIR}, "mkvToolNix does not exist"),
Arguments.of(new String[]{"./", "-t"}, "Missing required parameter for option '--threads' (<threads>)"),