mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Improve attribute processor
This commit is contained in:
@@ -52,8 +52,8 @@ public class Main implements Runnable {
|
|||||||
|
|
||||||
InputConfig.setInstance(config);
|
InputConfig.setInstance(config);
|
||||||
AttributeUpdaterKernel kernel = InputConfig.getInstance().getCoherent() != null
|
AttributeUpdaterKernel kernel = InputConfig.getInstance().getCoherent() != null
|
||||||
? new CoherentAttributeUpdaterKernel(new CachedMkvFileProcessor())
|
? new CoherentAttributeUpdaterKernel(config, new CachedMkvFileProcessor())
|
||||||
: new DefaultAttributeUpdaterKernel(new CachedMkvFileProcessor());
|
: new DefaultAttributeUpdaterKernel(config, new CachedMkvFileProcessor());
|
||||||
kernel.execute();
|
kernel.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,12 +26,21 @@ import java.util.concurrent.Executors;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RequiredArgsConstructor
|
|
||||||
public abstract class AttributeUpdaterKernel {
|
public abstract class AttributeUpdaterKernel {
|
||||||
|
|
||||||
|
protected final InputConfig config;
|
||||||
protected final FileProcessor processor;
|
protected final FileProcessor processor;
|
||||||
|
protected final AttributeProcessor attributeProcessor;
|
||||||
protected final ResultStatistic statistic = ResultStatistic.getInstance();
|
protected final ResultStatistic statistic = ResultStatistic.getInstance();
|
||||||
private final ExecutorService executor = Executors.newFixedThreadPool(InputConfig.getInstance().getThreads());
|
|
||||||
|
private final ExecutorService executor;
|
||||||
|
|
||||||
|
public AttributeUpdaterKernel(InputConfig config, FileProcessor processor) {
|
||||||
|
this.config = config;
|
||||||
|
this.processor = processor;
|
||||||
|
this.attributeProcessor = new AttributeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
|
||||||
|
this.executor = Executors.newFixedThreadPool(config.getThreads());
|
||||||
|
}
|
||||||
|
|
||||||
protected ProgressBarBuilder pbBuilder() {
|
protected ProgressBarBuilder pbBuilder() {
|
||||||
return new ProgressBarBuilder()
|
return new ProgressBarBuilder()
|
||||||
@@ -80,10 +89,10 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributeProcessor.findDefaultMatchAndApplyChanges(fileInfo);
|
attributeProcessor.findDefaultMatchAndApplyChanges(fileInfo);
|
||||||
AttributeProcessor.findForcedTracksAndApplyChanges(fileInfo);
|
attributeProcessor.findForcedTracksAndApplyChanges(fileInfo, config.isOverwriteForced());
|
||||||
AttributeProcessor.findCommentaryTracksAndApplyChanges(fileInfo);
|
attributeProcessor.findCommentaryTracksAndApplyChanges(fileInfo);
|
||||||
AttributeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo);
|
attributeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo);
|
||||||
|
|
||||||
checkStatusAndUpdate(fileInfo);
|
checkStatusAndUpdate(fileInfo);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import java.util.stream.Collectors;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
||||||
|
|
||||||
public CoherentAttributeUpdaterKernel(FileProcessor processor) {
|
public CoherentAttributeUpdaterKernel(InputConfig config, FileProcessor processor) {
|
||||||
super(processor);
|
super(config, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -5,15 +5,11 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.tongfei.progressbar.ProgressBarBuilder;
|
import me.tongfei.progressbar.ProgressBarBuilder;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DefaultAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
public class DefaultAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
||||||
|
|
||||||
public DefaultAttributeUpdaterKernel(FileProcessor processor) {
|
public DefaultAttributeUpdaterKernel(InputConfig config, FileProcessor processor) {
|
||||||
super(processor);
|
super(config, processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -9,11 +9,19 @@ import java.util.function.Supplier;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class AttributeProcessor {
|
public class AttributeProcessor {
|
||||||
private static final SubtitleTrackComparator subtitleTrackComparator =
|
private final SubtitleTrackComparator subtitleTrackComparator;
|
||||||
new SubtitleTrackComparator(InputConfig.getInstance().getPreferredSubtitles().toArray(new String[0]));
|
private final Set<String> commentaryKeywords;
|
||||||
|
private final Set<String> hearingImpairedKeywords;
|
||||||
|
private final Set<String> forcedKeywords;
|
||||||
|
|
||||||
private static List<TrackAttributes> filterForPossibleDefaults(List<TrackAttributes> tracks) {
|
public AttributeProcessor(String[] preferredSubtitles, Set<String> forcedKeywords, Set<String> commentaryKeywords, Set<String> hearingImpairedKeywords) {
|
||||||
InputConfig config = InputConfig.getInstance();
|
this.subtitleTrackComparator = new SubtitleTrackComparator(preferredSubtitles);
|
||||||
|
this.commentaryKeywords = commentaryKeywords;
|
||||||
|
this.hearingImpairedKeywords = hearingImpairedKeywords;
|
||||||
|
this.forcedKeywords = forcedKeywords;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<TrackAttributes> filterForPossibleDefaults(List<TrackAttributes> tracks) {
|
||||||
Stream<TrackAttributes> attributes = tracks.stream();
|
Stream<TrackAttributes> attributes = tracks.stream();
|
||||||
|
|
||||||
if (true) { // TODO: config for including commentary
|
if (true) { // TODO: config for including commentary
|
||||||
@@ -21,7 +29,7 @@ public class AttributeProcessor {
|
|||||||
.filter(attr -> !attr.commentary())
|
.filter(attr -> !attr.commentary())
|
||||||
.filter(attr -> {
|
.filter(attr -> {
|
||||||
if (attr.trackName() == null) return true;
|
if (attr.trackName() == null) return true;
|
||||||
return config.getCommentaryKeywords().stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
return commentaryKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -31,7 +39,7 @@ public class AttributeProcessor {
|
|||||||
.filter(attr -> !attr.hearingImpaired())
|
.filter(attr -> !attr.hearingImpaired())
|
||||||
.filter(attr -> {
|
.filter(attr -> {
|
||||||
if (attr.trackName() == null) return true;
|
if (attr.trackName() == null) return true;
|
||||||
return config.getHearingImpaired().stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
return hearingImpairedKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
||||||
});;
|
});;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,16 +47,12 @@ public class AttributeProcessor {
|
|||||||
.filter(attr -> !attr.forced())
|
.filter(attr -> !attr.forced())
|
||||||
.filter(attr -> {
|
.filter(attr -> {
|
||||||
if (attr.trackName() == null) return true;
|
if (attr.trackName() == null) return true;
|
||||||
return config.getForcedKeywords().stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
return forcedKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
|
||||||
})
|
})
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findDefaultMatchAndApplyChanges(FileInfo fileInfo) {
|
public void findDefaultMatchAndApplyChanges(FileInfo fileInfo, AttributeConfig... configs) {
|
||||||
findDefaultMatchAndApplyChanges(fileInfo, InputConfig.getInstance().getAttributeConfig().toArray(new AttributeConfig[0]));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void findDefaultMatchAndApplyChanges(FileInfo fileInfo, AttributeConfig... configs) {
|
|
||||||
Map<String, List<TrackAttributes>> audiosByLanguage = new HashMap<>(fileInfo.getTracks().size());
|
Map<String, List<TrackAttributes>> audiosByLanguage = new HashMap<>(fileInfo.getTracks().size());
|
||||||
Map<String, List<TrackAttributes>> subsByLanguage = new HashMap<>(fileInfo.getTracks().size());
|
Map<String, List<TrackAttributes>> subsByLanguage = new HashMap<>(fileInfo.getTracks().size());
|
||||||
filterForPossibleDefaults(fileInfo.getTracks()).forEach(track -> {
|
filterForPossibleDefaults(fileInfo.getTracks()).forEach(track -> {
|
||||||
@@ -75,7 +79,7 @@ public class AttributeProcessor {
|
|||||||
() -> subsByLanguage.get(fileInfo.getMatchedConfig().getSubtitleLanguage()).stream().max(subtitleTrackComparator).get());
|
() -> subsByLanguage.get(fileInfo.getMatchedConfig().getSubtitleLanguage()).stream().max(subtitleTrackComparator).get());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void applyDefaultChanges(FileInfo fileInfo, Function<FileInfo, List<TrackAttributes>> tracks, String language, Supplier<TrackAttributes> targetDefaultSupplier) {
|
private void applyDefaultChanges(FileInfo fileInfo, Function<FileInfo, List<TrackAttributes>> tracks, String language, Supplier<TrackAttributes> targetDefaultSupplier) {
|
||||||
tracks.apply(fileInfo).stream()
|
tracks.apply(fileInfo).stream()
|
||||||
.filter(TrackAttributes::defaultt)
|
.filter(TrackAttributes::defaultt)
|
||||||
.forEach(attr -> fileInfo.getChanges().getDefaultTrack().put(attr, false));
|
.forEach(attr -> fileInfo.getChanges().getDefaultTrack().put(attr, false));
|
||||||
@@ -89,12 +93,12 @@ public class AttributeProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findForcedTracksAndApplyChanges(FileInfo fileInfo) {
|
public void findForcedTracksAndApplyChanges(FileInfo fileInfo, boolean overwrite) {
|
||||||
Stream<TrackAttributes> forcedTracks = fileInfo.getTracks().stream()
|
Stream<TrackAttributes> forcedTracks = fileInfo.getTracks().stream()
|
||||||
.filter(track -> track.trackName() != null)
|
.filter(track -> track.trackName() != null)
|
||||||
.filter(track -> InputConfig.getInstance().getForcedKeywords().stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))));
|
.filter(track -> forcedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))));
|
||||||
|
|
||||||
if (InputConfig.getInstance().isOverwriteForced()) {
|
if (overwrite) {
|
||||||
fileInfo.getTracks().stream().filter(TrackAttributes::forced).forEach(attr -> {
|
fileInfo.getTracks().stream().filter(TrackAttributes::forced).forEach(attr -> {
|
||||||
fileInfo.getChanges().getForcedTrack().put(attr, false);
|
fileInfo.getChanges().getForcedTrack().put(attr, false);
|
||||||
});
|
});
|
||||||
@@ -107,21 +111,21 @@ public class AttributeProcessor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findCommentaryTracksAndApplyChanges(FileInfo fileInfo) {
|
public void findCommentaryTracksAndApplyChanges(FileInfo fileInfo) {
|
||||||
fileInfo.getTracks().stream()
|
fileInfo.getTracks().stream()
|
||||||
.filter(track -> !track.commentary())
|
.filter(track -> !track.commentary())
|
||||||
.filter(track -> track.trackName() != null)
|
.filter(track -> track.trackName() != null)
|
||||||
.filter(track -> InputConfig.getInstance().getCommentaryKeywords().stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))))
|
.filter(track -> commentaryKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))))
|
||||||
.forEach(attr -> {
|
.forEach(attr -> {
|
||||||
fileInfo.getChanges().getCommentaryTrack().put(attr, true);
|
fileInfo.getChanges().getCommentaryTrack().put(attr, true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void findHearingImpairedTracksAndApplyChanges(FileInfo fileInfo) {
|
public void findHearingImpairedTracksAndApplyChanges(FileInfo fileInfo) {
|
||||||
fileInfo.getTracks().stream()
|
fileInfo.getTracks().stream()
|
||||||
.filter(track -> !track.commentary())
|
.filter(track -> !track.commentary())
|
||||||
.filter(track -> track.trackName() != null)
|
.filter(track -> track.trackName() != null)
|
||||||
.filter(track -> InputConfig.getInstance().getHearingImpaired().stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))))
|
.filter(track -> hearingImpairedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))))
|
||||||
.forEach(attr -> {
|
.forEach(attr -> {
|
||||||
fileInfo.getChanges().getHearingImpairedTrack().put(attr, true);
|
fileInfo.getChanges().getHearingImpairedTrack().put(attr, true);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class SetConfigParameterTest {
|
|||||||
return Stream.of(
|
return Stream.of(
|
||||||
Arguments.of(args("--commentary-keywords", "test"), 1, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
Arguments.of(args("--commentary-keywords", "test"), 1, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
||||||
Arguments.of(args("--commentary-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
Arguments.of(args("--commentary-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
||||||
Arguments.of(args(), 2, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
Arguments.of(args(), 3, (Function<InputConfig, Set<String>>) InputConfig::getCommentaryKeywords),
|
||||||
Arguments.of(args("--forced-keywords", "test"), 1, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
Arguments.of(args("--forced-keywords", "test"), 1, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
||||||
Arguments.of(args("--forced-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
Arguments.of(args("--forced-keywords", "test", "test1", "test2", "test3", "test4"), 5, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
||||||
Arguments.of(args(), 3, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
Arguments.of(args(), 3, (Function<InputConfig, Set<String>>) InputConfig::getForcedKeywords),
|
||||||
|
|||||||
@@ -2,18 +2,15 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
|||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
||||||
import org.apache.logging.log4j.util.Strings;
|
import org.apache.logging.log4j.util.Strings;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.List;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Map;
|
import java.util.*;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
|
||||||
@@ -70,13 +67,11 @@ class AttributeProcessorTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("attributeConfigMatching")
|
@MethodSource("attributeConfigMatching")
|
||||||
void findDefaultMatchAndApplyChanges(List<TrackAttributes> tracks, AttributeConfig[] config, String expectedConfig, Map<TrackAttributes, Boolean> changes) {
|
void findDefaultMatchAndApplyChanges(List<TrackAttributes> tracks, AttributeConfig[] config, String expectedConfig, Map<TrackAttributes, Boolean> changes) {
|
||||||
InputConfig.getInstance().setPreferredSubtitles(new HashSet<>());
|
AttributeProcessor attributeProcessor = new AttributeProcessor(new String[]{}, Set.of(), Set.of(), Set.of());
|
||||||
InputConfig.getInstance().setCommentaryKeywords(new HashSet<>());
|
|
||||||
InputConfig.getInstance().setForcedKeywords(new HashSet<>());
|
|
||||||
|
|
||||||
FileInfo fileInfo = new FileInfo(null);
|
FileInfo fileInfo = new FileInfo(null);
|
||||||
fileInfo.addTracks(tracks);
|
fileInfo.addTracks(tracks);
|
||||||
AttributeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config);
|
attributeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config);
|
||||||
assertEquals(Strings.isBlank(expectedConfig), fileInfo.getMatchedConfig() == null);
|
assertEquals(Strings.isBlank(expectedConfig), fileInfo.getMatchedConfig() == null);
|
||||||
assertEquals(expectedConfig, fileInfo.getMatchedConfig().toStringShort());
|
assertEquals(expectedConfig, fileInfo.getMatchedConfig().toStringShort());
|
||||||
assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size());
|
assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size());
|
||||||
@@ -105,14 +100,30 @@ class AttributeProcessorTest {
|
|||||||
|
|
||||||
private static Stream<Arguments> filterForPossibleDefaults() {
|
private static Stream<Arguments> filterForPossibleDefaults() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
|
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||||
|
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "forced"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||||
|
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "commentary"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||||
|
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, withName(AUDIO_GER, "SHD"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
|
||||||
|
Arguments.of(List.of(AUDIO_GER, AUDIO_ENG, SUB_GER, SUB_GER_FORCED, AUDIO_GER_COMMENTARY, AUDIO_GER_HEARING), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("filterForPossibleDefaults")
|
@MethodSource("filterForPossibleDefaults")
|
||||||
void filterForPossibleDefaults(List<TrackAttributes> tracks, Set<TrackAttributes> expected) {
|
void filterForPossibleDefaults(List<TrackAttributes> tracks, Set<TrackAttributes> expected) throws InvocationTargetException, IllegalAccessException {
|
||||||
|
AttributeProcessor attributeProcessor = new AttributeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SHD"));
|
||||||
|
Optional<Method> method = Arrays.stream(AttributeProcessor.class.getDeclaredMethods())
|
||||||
|
.filter(m -> m.getName().equals("filterForPossibleDefaults"))
|
||||||
|
.findFirst();
|
||||||
|
|
||||||
|
assertTrue(method.isPresent());
|
||||||
|
Method underTest = method.get();
|
||||||
|
underTest.setAccessible(true);
|
||||||
|
List<TrackAttributes> result = (List<TrackAttributes>) underTest.invoke(attributeProcessor, tracks);
|
||||||
|
assertEquals(expected.size(), result.size());
|
||||||
|
for (TrackAttributes track : result) {
|
||||||
|
assertTrue(expected.contains(track));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Stream<Arguments> findForcedTracksAndApplyChanges() {
|
private static Stream<Arguments> findForcedTracksAndApplyChanges() {
|
||||||
@@ -139,15 +150,11 @@ class AttributeProcessorTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("findForcedTracksAndApplyChanges")
|
@MethodSource("findForcedTracksAndApplyChanges")
|
||||||
void findForcedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, boolean overwrite, Map<TrackAttributes, Boolean> changes) {
|
void findForcedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, boolean overwrite, Map<TrackAttributes, Boolean> changes) {
|
||||||
InputConfig.getInstance().setPreferredSubtitles(new HashSet<>());
|
AttributeProcessor attributeProcessor = new AttributeProcessor(new String[]{}, keywords, Set.of(), Set.of());
|
||||||
InputConfig.getInstance().setCommentaryKeywords(new HashSet<>());
|
|
||||||
InputConfig.getInstance().setHearingImpaired(new HashSet<>());
|
|
||||||
InputConfig.getInstance().setForcedKeywords(keywords);
|
|
||||||
InputConfig.getInstance().setOverwriteForced(overwrite);
|
|
||||||
|
|
||||||
FileInfo fileInfo = new FileInfo(null);
|
FileInfo fileInfo = new FileInfo(null);
|
||||||
fileInfo.addTracks(tracks);
|
fileInfo.addTracks(tracks);
|
||||||
AttributeProcessor.findForcedTracksAndApplyChanges(fileInfo);
|
attributeProcessor.findForcedTracksAndApplyChanges(fileInfo, overwrite);
|
||||||
|
|
||||||
assertEquals(changes.size(), fileInfo.getChanges().getForcedTrack().size());
|
assertEquals(changes.size(), fileInfo.getChanges().getForcedTrack().size());
|
||||||
changes.forEach((key, value) -> {
|
changes.forEach((key, value) -> {
|
||||||
@@ -180,14 +187,11 @@ class AttributeProcessorTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("findCommentaryTracksAndApplyChanges")
|
@MethodSource("findCommentaryTracksAndApplyChanges")
|
||||||
void findCommentaryTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
|
void findCommentaryTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
|
||||||
InputConfig.getInstance().setPreferredSubtitles(new HashSet<>());
|
AttributeProcessor attributeProcessor = new AttributeProcessor(new String[]{}, Set.of(), keywords, Set.of());
|
||||||
InputConfig.getInstance().setCommentaryKeywords(keywords);
|
|
||||||
InputConfig.getInstance().setHearingImpaired(new HashSet<>());
|
|
||||||
InputConfig.getInstance().setForcedKeywords(new HashSet<>());
|
|
||||||
|
|
||||||
FileInfo fileInfo = new FileInfo(null);
|
FileInfo fileInfo = new FileInfo(null);
|
||||||
fileInfo.addTracks(tracks);
|
fileInfo.addTracks(tracks);
|
||||||
AttributeProcessor.findCommentaryTracksAndApplyChanges(fileInfo);
|
attributeProcessor.findCommentaryTracksAndApplyChanges(fileInfo);
|
||||||
|
|
||||||
assertEquals(changes.size(), fileInfo.getChanges().getCommentaryTrack().size());
|
assertEquals(changes.size(), fileInfo.getChanges().getCommentaryTrack().size());
|
||||||
changes.forEach((key, value) -> {
|
changes.forEach((key, value) -> {
|
||||||
@@ -220,14 +224,11 @@ class AttributeProcessorTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("findCommentaryTracksAndApplyChanges")
|
@MethodSource("findCommentaryTracksAndApplyChanges")
|
||||||
void findHearingImpairedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
|
void findHearingImpairedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
|
||||||
InputConfig.getInstance().setPreferredSubtitles(new HashSet<>());
|
AttributeProcessor attributeProcessor = new AttributeProcessor(new String[]{}, Set.of(), Set.of(), keywords);
|
||||||
InputConfig.getInstance().setCommentaryKeywords(new HashSet<>());
|
|
||||||
InputConfig.getInstance().setHearingImpaired(keywords);
|
|
||||||
InputConfig.getInstance().setForcedKeywords(new HashSet<>());
|
|
||||||
|
|
||||||
FileInfo fileInfo = new FileInfo(null);
|
FileInfo fileInfo = new FileInfo(null);
|
||||||
fileInfo.addTracks(tracks);
|
fileInfo.addTracks(tracks);
|
||||||
AttributeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo);
|
attributeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo);
|
||||||
|
|
||||||
assertEquals(changes.size(), fileInfo.getChanges().getHearingImpairedTrack().size());
|
assertEquals(changes.size(), fileInfo.getChanges().getHearingImpairedTrack().size());
|
||||||
changes.forEach((key, value) -> {
|
changes.forEach((key, value) -> {
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType;
|
||||||
|
|
||||||
public class FileInfoTestUtil {
|
public class FileInfoTestUtil {
|
||||||
public static final TrackAttributes AUDIO_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.AUDIO);
|
|
||||||
public static final TrackAttributes AUDIO_ENG_DEFAULT = new TrackAttributes(1, "eng", "", true, false, false, false, TrackType.AUDIO);
|
|
||||||
public static final TrackAttributes AUDIO_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.AUDIO);
|
||||||
public static final TrackAttributes AUDIO_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.AUDIO);
|
||||||
|
public static final TrackAttributes AUDIO_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.AUDIO);
|
||||||
|
public static final TrackAttributes AUDIO_ENG_DEFAULT = new TrackAttributes(1, "eng", "", true, false, false, false, TrackType.AUDIO);
|
||||||
public static final TrackAttributes AUDIO_GER_FORCED = new TrackAttributes(0, "ger", "", false, true, false, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_GER_FORCED = new TrackAttributes(0, "ger", "", false, true, false, false, TrackType.AUDIO);
|
||||||
public static final TrackAttributes AUDIO_ENG_FORCED = new TrackAttributes(1, "eng", "", false, true, false, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_ENG_FORCED = new TrackAttributes(1, "eng", "", false, true, false, false, TrackType.AUDIO);
|
||||||
public static final TrackAttributes AUDIO_GER_COMMENTARY = new TrackAttributes(0, "ger", "", false, false, true, false, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_GER_COMMENTARY = new TrackAttributes(0, "ger", "", false, false, true, false, TrackType.AUDIO);
|
||||||
@@ -15,10 +15,10 @@ public class FileInfoTestUtil {
|
|||||||
public static final TrackAttributes AUDIO_GER_HEARING = new TrackAttributes(0, "ger", "", false, false, false, true, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_GER_HEARING = new TrackAttributes(0, "ger", "", false, false, false, true, TrackType.AUDIO);
|
||||||
public static final TrackAttributes AUDIO_ENG_HEARING = new TrackAttributes(1, "ger", "", false, false, false, true, TrackType.AUDIO);
|
public static final TrackAttributes AUDIO_ENG_HEARING = new TrackAttributes(1, "ger", "", false, false, false, true, TrackType.AUDIO);
|
||||||
|
|
||||||
public static final TrackAttributes SUB_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.SUBTITLES);
|
|
||||||
public static final TrackAttributes SUB_ENG_DEFAULT = new TrackAttributes(1, "eng", "", true, false, false, false, TrackType.SUBTITLES);
|
|
||||||
public static final TrackAttributes SUB_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.SUBTITLES);
|
public static final TrackAttributes SUB_GER = new TrackAttributes(0, "ger", "", false, false, false, false, TrackType.SUBTITLES);
|
||||||
public static final TrackAttributes SUB_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.SUBTITLES);
|
public static final TrackAttributes SUB_ENG = new TrackAttributes(1, "eng", "", false, false, false, false, TrackType.SUBTITLES);
|
||||||
|
public static final TrackAttributes SUB_GER_DEFAULT = new TrackAttributes(0, "ger", "", true, false, false, false, TrackType.SUBTITLES);
|
||||||
|
public static final TrackAttributes SUB_ENG_DEFAULT = new TrackAttributes(1, "eng", "", true, false, false, false, TrackType.SUBTITLES);
|
||||||
public static final TrackAttributes SUB_GER_FORCED = new TrackAttributes(0, "ger", "", false, true, false, false, TrackType.SUBTITLES);
|
public static final TrackAttributes SUB_GER_FORCED = new TrackAttributes(0, "ger", "", false, true, false, false, TrackType.SUBTITLES);
|
||||||
public static final TrackAttributes SUB_ENG_FORCED = new TrackAttributes(1, "eng", "", false, true, false, false, TrackType.SUBTITLES);
|
public static final TrackAttributes SUB_ENG_FORCED = new TrackAttributes(1, "eng", "", false, true, false, false, TrackType.SUBTITLES);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user