mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Add support for multiple library paths
This commit is contained in:
@@ -7,6 +7,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import me.tongfei.progressbar.ProgressBarBuilder;
|
import me.tongfei.progressbar.ProgressBarBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -25,7 +26,9 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected List<File> getFiles() {
|
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
|
@Override
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import me.tongfei.progressbar.ProgressBarBuilder;
|
import me.tongfei.progressbar.ProgressBarBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -23,7 +24,9 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<File> getFiles() {
|
protected List<File> getFiles() {
|
||||||
return fileProcessor.loadFiles(config.getLibraryPath().getPath());
|
return Arrays.stream(config.getLibraryPaths())
|
||||||
|
.flatMap(path -> fileProcessor.loadFiles(path.getPath()).stream())
|
||||||
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import jakarta.validation.ConstraintValidator;
|
|||||||
import jakarta.validation.ConstraintValidatorContext;
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
public class ValidFileValidator implements ConstraintValidator<ValidFile, File> {
|
public class ValidFileValidator implements ConstraintValidator<ValidFile, File[]> {
|
||||||
@Override
|
@Override
|
||||||
public void initialize(ValidFile constraintAnnotation) {
|
public void initialize(ValidFile constraintAnnotation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isValid(File file, ConstraintValidatorContext context) {
|
public boolean isValid(File[] files, ConstraintValidatorContext context) {
|
||||||
return file != null && file.exists();
|
return files != null && files.length > 0 && Arrays.stream(files).allMatch(File::exists);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ public class InputConfig implements CommandLine.IVersionProvider {
|
|||||||
CommandLine.Model.CommandSpec spec;
|
CommandLine.Model.CommandSpec spec;
|
||||||
|
|
||||||
@ValidFile(message = "does not exist")
|
@ValidFile(message = "does not exist")
|
||||||
@CommandLine.Parameters(description = "path to library")
|
@CommandLine.Parameters(description = "paths to library", arity = "1..*")
|
||||||
private File libraryPath;
|
private File[] libraryPaths;
|
||||||
|
|
||||||
@Option(names = {"-a", "--attribute-config"}, arity = "1..*", converter = AttributeConfigConverter.class,
|
@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)")
|
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() + "[", "]")
|
return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]")
|
||||||
.add("configPath=" + configPath)
|
.add("configPath=" + configPath)
|
||||||
.add("spec=" + spec)
|
.add("spec=" + spec)
|
||||||
.add("libraryPath=" + libraryPath)
|
.add("libraryPath=" + libraryPaths)
|
||||||
.add("attributeConfig=" + Arrays.toString(attributeConfig))
|
.add("attributeConfig=" + Arrays.toString(attributeConfig))
|
||||||
.add("mkvToolNix=" + mkvToolNix)
|
.add("mkvToolNix=" + mkvToolNix)
|
||||||
.add("safeMode=" + safeMode)
|
.add("safeMode=" + safeMode)
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import java.io.StringWriter;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.*;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.PathUtils.*;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.args;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class ValidationExecutionStrategyTest {
|
class ValidationExecutionStrategyTest {
|
||||||
@@ -24,16 +23,17 @@ class ValidationExecutionStrategyTest {
|
|||||||
.setExecutionStrategy(new ValidationExecutionStrategy())
|
.setExecutionStrategy(new ValidationExecutionStrategy())
|
||||||
.parseArgs("-a", "ger:ger", "-m", TEST_MKVTOOLNIX_DIR, TEST_FILE);
|
.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("\\", "/"));
|
assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> validateFailure() {
|
private static Stream<Arguments> validateFailure() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): <libraryPath>"),
|
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): <libraryPaths>"),
|
||||||
Arguments.of(new String[]{"/arstarstarst"}, "libraryPath does not exist"),
|
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",}, "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[]{"/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[]{"./", "-m", TEST_INVALID_DIR}, "mkvToolNix does not exist"),
|
||||||
Arguments.of(new String[]{"./", "-t"}, "Missing required parameter for option '--threads' (<threads>)"),
|
Arguments.of(new String[]{"./", "-t"}, "Missing required parameter for option '--threads' (<threads>)"),
|
||||||
|
|||||||
Reference in New Issue
Block a user