Apply forced track if sub lang is OFF

This commit is contained in:
RatzzFatzz
2025-12-24 16:22:17 +01:00
parent 13283e3765
commit f18fdbdda6
6 changed files with 207 additions and 101 deletions

View File

@@ -37,10 +37,10 @@ public class AttributeConfigConverter implements CommandLine.ITypeConverter<Attr
* @return valid {@link AttributeConfig} * @return valid {@link AttributeConfig}
*/ */
private static AttributeConfig validateResult(AttributeConfig attr) { private static AttributeConfig validateResult(AttributeConfig attr) {
if (!isLanguageValid(attr.getAudioLanguage())) if (!isLanguageValid(attr.getAudioLang()))
throw new CommandLine.TypeConversionException("Audio language invalid: " + attr.getAudioLanguage()); throw new CommandLine.TypeConversionException("Audio language invalid: " + attr.getAudioLang());
if (!isLanguageValid(attr.getSubtitleLanguage())) if (!isLanguageValid(attr.getSubLang()))
throw new CommandLine.TypeConversionException("Subtitle language invalid: " + attr.getSubtitleLanguage()); throw new CommandLine.TypeConversionException("Subtitle language invalid: " + attr.getSubLang());
return attr; return attr;
} }

View File

@@ -4,8 +4,6 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.SubtitleTrackComparator;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*; import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream; import java.util.stream.Stream;
public class AttributeChangeProcessor { public class AttributeChangeProcessor {
@@ -21,7 +19,51 @@ public class AttributeChangeProcessor {
this.forcedKeywords = forcedKeywords; this.forcedKeywords = forcedKeywords;
} }
private List<TrackAttributes> filterForPossibleDefaults(List<TrackAttributes> tracks) { /**
* Looks for default matches and applies them if found.
*/
public void findAndApplyDefaultMatch(FileInfo fileInfo, AttributeConfig... configs) {
Map<String, List<TrackAttributes>> audiosByLanguage = new HashMap<>(fileInfo.getTracks().size());
Map<String, List<TrackAttributes>> subsByLanguage = new HashMap<>(fileInfo.getTracks().size());
getPossibleDefaults(fileInfo.getTracks()).forEach(track -> {
if (TrackType.AUDIO.equals(track.type()))
audiosByLanguage.computeIfAbsent(track.language(), (k) -> new ArrayList<>()).add(track);
else if (TrackType.SUBTITLES.equals(track.type()))
subsByLanguage.computeIfAbsent(track.language(), (k) -> new ArrayList<>()).add(track);
});
for (AttributeConfig config : configs) {
if (("OFF".equals(config.getAudioLang()) || audiosByLanguage.containsKey(config.getAudioLang()))
&& ("OFF".equals(config.getSubLang()) || subsByLanguage.containsKey(config.getSubLang()))) {
fileInfo.setMatchedConfig(config);
break;
}
}
if (fileInfo.getMatchedConfig() == null) return;
AttributeConfig match = fileInfo.getMatchedConfig();
removeExistingDefaults(fileInfo);
if (!"OFF".equals(match.getAudioLang())) applyNewDefault(fileInfo, audiosByLanguage.get(fileInfo.getMatchedConfig().getAudioLang()).get(0));
if (!"OFF".equals(match.getSubLang())) applyNewDefault(fileInfo, subsByLanguage.get(fileInfo.getMatchedConfig().getSubLang()).stream().max(subtitleTrackComparator).get());
}
/**
* If match with xxx:OFF was found forced track in audio language is applied as default.
* Forced track detection takes changes of {@link AttributeChangeProcessor#findAndApplyForcedTracks} into consideration.
*/
public void applyForcedAsDefault(FileInfo fileInfo) {
AttributeConfig c = fileInfo.getMatchedConfig();
if (c == null) return;
if (!"OFF".equals(c.getAudioLang()) && "OFF".equals(c.getSubLang())) {
getForcedTracks(fileInfo)
.filter(track -> c.getAudioLang().equals(track.language()))
.findFirst()
.ifPresent(track -> applyNewDefault(fileInfo, track));
}
}
private Stream<TrackAttributes> getPossibleDefaults(List<TrackAttributes> tracks) {
Stream<TrackAttributes> attributes = tracks.stream(); Stream<TrackAttributes> attributes = tracks.stream();
return attributes return attributes
@@ -34,55 +76,26 @@ public class AttributeChangeProcessor {
.filter(attr -> { .filter(attr -> {
if (attr.trackName() == null) return true; if (attr.trackName() == null) return true;
return forcedKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0); return forcedKeywords.stream().noneMatch(keyword -> keyword.compareToIgnoreCase(attr.trackName()) == 0);
})
.toList();
}
public void findDefaultMatchAndApplyChanges(FileInfo fileInfo, AttributeConfig... configs) {
Map<String, List<TrackAttributes>> audiosByLanguage = new HashMap<>(fileInfo.getTracks().size());
Map<String, List<TrackAttributes>> subsByLanguage = new HashMap<>(fileInfo.getTracks().size());
filterForPossibleDefaults(fileInfo.getTracks()).forEach(track -> {
if (TrackType.AUDIO.equals(track.type()))
audiosByLanguage.computeIfAbsent(track.language(), (k) -> new ArrayList<>()).add(track);
else if (TrackType.SUBTITLES.equals(track.type()))
subsByLanguage.computeIfAbsent(track.language(), (k) -> new ArrayList<>()).add(track);
}); });
for (AttributeConfig config : configs) {
if (("OFF".equals(config.getAudioLanguage()) || audiosByLanguage.containsKey(config.getAudioLanguage()))
&& ("OFF".equals(config.getSubtitleLanguage()) || subsByLanguage.containsKey(config.getSubtitleLanguage()))) {
fileInfo.setMatchedConfig(config);
break;
}
// TODO: forced if OFF
} }
if (fileInfo.getMatchedConfig() == null) return; private void removeExistingDefaults(FileInfo fileInfo) {
fileInfo.getTracks().stream()
applyDefaultChanges(fileInfo, FileInfo::getAudioTracks, fileInfo.getMatchedConfig().getAudioLanguage(),
() -> audiosByLanguage.get(fileInfo.getMatchedConfig().getAudioLanguage()).get(0));
applyDefaultChanges(fileInfo, FileInfo::getSubtitleTracks, fileInfo.getMatchedConfig().getSubtitleLanguage(),
() -> subsByLanguage.get(fileInfo.getMatchedConfig().getSubtitleLanguage()).stream().max(subtitleTrackComparator).get());
}
private void applyDefaultChanges(FileInfo fileInfo, Function<FileInfo, List<TrackAttributes>> tracks, String language, Supplier<TrackAttributes> targetDefaultSupplier) {
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));
if (!"OFF".equals(language)) {
TrackAttributes targetDefault = targetDefaultSupplier.get();
if (fileInfo.getChanges().getDefaultTrack().containsKey(targetDefault)) {
fileInfo.getChanges().getDefaultTrack().remove(targetDefault);
} else {
fileInfo.getChanges().getDefaultTrack().put(targetDefault, true);
} }
private void applyNewDefault(FileInfo fileInfo, TrackAttributes targetDefault) {
Map<TrackAttributes, Boolean> changes = fileInfo.getChanges().getDefaultTrack();
if (changes.containsKey(targetDefault)) {
changes.remove(targetDefault);
} else {
changes.put(targetDefault, true);
} }
} }
public void findForcedTracksAndApplyChanges(FileInfo fileInfo, boolean overwrite) { public void findAndApplyForcedTracks(FileInfo fileInfo, boolean overwrite) {
Stream<TrackAttributes> forcedTracks = fileInfo.getTracks().stream() Stream<TrackAttributes> forcedTracks = getForcedTracks(fileInfo);
.filter(track -> track.trackName() != null)
.filter(track -> forcedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))));
if (overwrite) { if (overwrite) {
fileInfo.getTracks().stream().filter(TrackAttributes::forced).forEach(attr -> { fileInfo.getTracks().stream().filter(TrackAttributes::forced).forEach(attr -> {
@@ -97,7 +110,19 @@ public class AttributeChangeProcessor {
}); });
} }
public void findCommentaryTracksAndApplyChanges(FileInfo fileInfo) { private Stream<TrackAttributes> getForcedTracks(FileInfo fileInfo) {
return fileInfo.getTracks().stream()
.filter(track -> {
if (fileInfo.getChanges().getForcedTrack().containsKey(track)) return fileInfo.getChanges().getForcedTrack().get(track);
return matchesForcedKeywords(track) || track.forced();
});
}
private boolean matchesForcedKeywords(TrackAttributes track) {
return track.trackName() != null && forcedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT)));
}
public void findAndApplyCommentaryTracks(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)
@@ -107,7 +132,7 @@ public class AttributeChangeProcessor {
}); });
} }
public void findHearingImpairedTracksAndApplyChanges(FileInfo fileInfo) { public void findAndApplyHearingImpairedTracks(FileInfo fileInfo) {
fileInfo.getTracks().stream() fileInfo.getTracks().stream()
.filter(track -> !track.hearingImpaired()) .filter(track -> !track.hearingImpaired())
.filter(track -> track.trackName() != null) .filter(track -> track.trackName() != null)

View File

@@ -49,9 +49,10 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
log.info("Found coherent match {} for {}", matchedConfig.toStringShort(), rootDir.getPath()); log.info("Found coherent match {} for {}", matchedConfig.toStringShort(), rootDir.getPath());
matchedFiles.forEach(fileInfo -> { matchedFiles.forEach(fileInfo -> {
attributeChangeProcessor.findForcedTracksAndApplyChanges(fileInfo, this.config.isOverwriteForced()); attributeChangeProcessor.findAndApplyForcedTracks(fileInfo, this.config.isOverwriteForced());
attributeChangeProcessor.findCommentaryTracksAndApplyChanges(fileInfo); attributeChangeProcessor.applyForcedAsDefault(fileInfo);
attributeChangeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyCommentaryTracks(fileInfo);
attributeChangeProcessor.findAndApplyHearingImpairedTracks(fileInfo);
checkStatusAndUpdate(fileInfo); checkStatusAndUpdate(fileInfo);
}); });
@@ -89,7 +90,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
break; break;
} }
attributeChangeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config); attributeChangeProcessor.findAndApplyDefaultMatch(fileInfo, config);
if (matchedConfig == null) matchedConfig = fileInfo.getMatchedConfig(); if (matchedConfig == null) matchedConfig = fileInfo.getMatchedConfig();
if (matchedConfig == null || matchedConfig != fileInfo.getMatchedConfig()) { if (matchedConfig == null || matchedConfig != fileInfo.getMatchedConfig()) {

View File

@@ -36,10 +36,11 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
return; return;
} }
attributeChangeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config.getAttributeConfig()); attributeChangeProcessor.findAndApplyDefaultMatch(fileInfo, config.getAttributeConfig());
attributeChangeProcessor.findForcedTracksAndApplyChanges(fileInfo, config.isOverwriteForced()); attributeChangeProcessor.findAndApplyForcedTracks(fileInfo, config.isOverwriteForced());
attributeChangeProcessor.findCommentaryTracksAndApplyChanges(fileInfo); attributeChangeProcessor.applyForcedAsDefault(fileInfo);
attributeChangeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyCommentaryTracks(fileInfo);
attributeChangeProcessor.findAndApplyHearingImpairedTracks(fileInfo);
checkStatusAndUpdate(fileInfo); checkStatusAndUpdate(fileInfo);
} }

View File

@@ -10,8 +10,8 @@ import java.util.Objects;
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public class AttributeConfig { public class AttributeConfig {
private final String audioLanguage; private final String audioLang;
private final String subtitleLanguage; private final String subLang;
public static AttributeConfig of(String audioLanguage, String subtitleLanguage) { public static AttributeConfig of(String audioLanguage, String subtitleLanguage) {
return new AttributeConfig(audioLanguage, subtitleLanguage); return new AttributeConfig(audioLanguage, subtitleLanguage);
@@ -22,23 +22,23 @@ public class AttributeConfig {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
AttributeConfig that = (AttributeConfig) o; AttributeConfig that = (AttributeConfig) o;
return Objects.equals(audioLanguage, that.audioLanguage) && Objects.equals(subtitleLanguage, that.subtitleLanguage); return Objects.equals(audioLang, that.audioLang) && Objects.equals(subLang, that.subLang);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(audioLanguage, subtitleLanguage); return Objects.hash(audioLang, subLang);
} }
public String toStringShort() { public String toStringShort() {
return audioLanguage + ":" + subtitleLanguage; return audioLang + ":" + subLang;
} }
@Override @Override
public String toString() { public String toString() {
return "AttributeConfig{" return "AttributeConfig{"
+ "audioLanguage='" + audioLanguage + '\'' + "audioLanguage='" + audioLang + '\''
+ ", subtitleLanguage='" + subtitleLanguage + '\'' + + ", subtitleLanguage='" + subLang + '\'' +
'}'; '}';
} }
} }

View File

@@ -18,7 +18,24 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
class AttributeChangeProcessorTest { class AttributeChangeProcessorTest {
private static Stream<Arguments> attributeConfigMatching() { private static AttributeConfig[] arr(AttributeConfig... configs) {
return configs;
}
private static AttributeConfig a(String config) {
String[] split = config.split(":");
return new AttributeConfig(split[0], split[1]);
}
private static Map.Entry<TrackAttributes, Boolean> on(TrackAttributes track) {
return Map.entry(track, true);
}
private static Map.Entry<TrackAttributes, Boolean> off(TrackAttributes track) {
return Map.entry(track, false);
}
private static Stream<Arguments> findAndApplyDefaultMatch() {
return Stream.of( return Stream.of(
Arguments.of( Arguments.of(
List.of(withName(AUDIO_ENG, null), SUB_ENG), List.of(withName(AUDIO_ENG, null), SUB_ENG),
@@ -99,13 +116,14 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("attributeConfigMatching") @MethodSource("findAndApplyDefaultMatch")
void findDefaultMatchAndApplyChanges(List<TrackAttributes> tracks, AttributeConfig[] config, String expectedConfig, Map<TrackAttributes, Boolean> changes) { void findAndApplyDefaultMatch(List<TrackAttributes> tracks, AttributeConfig[] config, String expectedConfig, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH")); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findDefaultMatchAndApplyChanges(fileInfo, config);
attributeChangeProcessor.findAndApplyDefaultMatch(fileInfo, config);
assertEquals(expectedConfig, fileInfo.getMatchedConfig() != null ? fileInfo.getMatchedConfig().toStringShort() : fileInfo.getMatchedConfig()); assertEquals(expectedConfig, fileInfo.getMatchedConfig() != null ? fileInfo.getMatchedConfig().toStringShort() : fileInfo.getMatchedConfig());
assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {
@@ -114,24 +132,54 @@ class AttributeChangeProcessorTest {
}); });
} }
private static AttributeConfig[] arr(AttributeConfig... configs) { private static Stream<Arguments> applyForcedAsDefault() {
return configs; return Stream.of(
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED),
a("ger:OFF"),
Map.ofEntries(on(SUB_GER_FORCED))
),
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED, SUB_GER),
a("ger:OFF"),
Map.ofEntries(on(SUB_GER_FORCED))
),
Arguments.of(
List.of(AUDIO_GER, withName(SUB_GER, "forced")),
a("ger:OFF"),
Map.ofEntries(on(withName(SUB_GER, "forced")))
),
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED, SUB_ENG),
a("ger:eng"),
Map.ofEntries()
),
Arguments.of(
List.of(AUDIO_GER, SUB_GER_FORCED, SUB_ENG),
null,
Map.ofEntries()
)
);
} }
private static AttributeConfig a(String config) { @ParameterizedTest
String[] split = config.split(":"); @MethodSource("applyForcedAsDefault")
return new AttributeConfig(split[0], split[1]); void applyForcedAsDefault(List<TrackAttributes> tracks, AttributeConfig config, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of(""), Set.of(""));
FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks);
fileInfo.setMatchedConfig(config);
attributeChangeProcessor.applyForcedAsDefault(fileInfo);
assertEquals(changes.size(), fileInfo.getChanges().getDefaultTrack().size());
changes.forEach((key, value) -> {
assertTrue(fileInfo.getChanges().getDefaultTrack().containsKey(key));
assertEquals(value, fileInfo.getChanges().getDefaultTrack().get(key));
});
} }
private static Map.Entry<TrackAttributes, Boolean> on(TrackAttributes track) { private static Stream<Arguments> getPossibleDefaults() {
return Map.entry(track, true);
}
private static Map.Entry<TrackAttributes, Boolean> off(TrackAttributes track) {
return Map.entry(track, false);
}
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, 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, "forced"), SUB_GER), Set.of(AUDIO_GER, AUDIO_ENG, SUB_GER)),
@@ -145,24 +193,55 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("filterForPossibleDefaults") @MethodSource("getPossibleDefaults")
void filterForPossibleDefaults(List<TrackAttributes> tracks, Set<TrackAttributes> expected) throws InvocationTargetException, IllegalAccessException { void getPossibleDefaults(List<TrackAttributes> tracks, Set<TrackAttributes> expected) throws InvocationTargetException, IllegalAccessException {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH")); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of("commentary"), Set.of("SDH"));
Optional<Method> method = Arrays.stream(AttributeChangeProcessor.class.getDeclaredMethods()) Optional<Method> method = Arrays.stream(AttributeChangeProcessor.class.getDeclaredMethods())
.filter(m -> m.getName().equals("filterForPossibleDefaults")) .filter(m -> m.getName().equals("getPossibleDefaults"))
.findFirst(); .findFirst();
assertTrue(method.isPresent()); assertTrue(method.isPresent());
Method underTest = method.get(); Method underTest = method.get();
underTest.setAccessible(true); underTest.setAccessible(true);
List<TrackAttributes> result = (List<TrackAttributes>) underTest.invoke(attributeChangeProcessor, tracks); List<TrackAttributes> result = ((Stream<TrackAttributes>) underTest.invoke(attributeChangeProcessor, tracks)).toList();
assertEquals(expected.size(), result.size()); assertEquals(expected.size(), result.size());
for (TrackAttributes track : result) { for (TrackAttributes track : result) {
assertTrue(expected.contains(track)); assertTrue(expected.contains(track));
} }
} }
private static Stream<Arguments> findForcedTracksAndApplyChanges() { private static Stream<Arguments> getForcedTracks() {
return Stream.of(
Arguments.of(List.of(withName(SUB_GER, "forced")), Map.of(), Set.of(withName(SUB_GER, "forced"))),
Arguments.of(List.of(SUB_GER_FORCED), Map.of(), Set.of(SUB_GER_FORCED)),
Arguments.of(List.of(SUB_GER_FORCED, withName(SUB_GER, "forced")), Map.of(), Set.of(SUB_GER_FORCED, withName(SUB_GER, "forced"))),
Arguments.of(List.of(SUB_GER_FORCED, withName(SUB_GER, "forced")), Map.of(SUB_GER_FORCED, false), Set.of(withName(SUB_GER, "forced"))),
Arguments.of(List.of(SUB_GER, withName(SUB_GER, "forced")), Map.of(SUB_GER, true), Set.of(SUB_GER, withName(SUB_GER, "forced")))
);
}
@ParameterizedTest
@MethodSource("getForcedTracks")
void getForcedTracks(List<TrackAttributes> tracks, Map<TrackAttributes, Boolean> changes, Set<TrackAttributes> expected) throws InvocationTargetException, IllegalAccessException {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of("forced"), Set.of(), Set.of());
FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks);
changes.forEach((key, val) -> fileInfo.getChanges().getForcedTrack().put(key, val));
Optional<Method> method = Arrays.stream(AttributeChangeProcessor.class.getDeclaredMethods())
.filter(m -> m.getName().equals("getForcedTracks"))
.findFirst();
assertTrue(method.isPresent());
Method underTest = method.get();
underTest.setAccessible(true);
List<TrackAttributes> result = ((Stream<TrackAttributes>) underTest.invoke(attributeChangeProcessor, fileInfo)).toList();
assertEquals(expected.size(), result.size());
for (TrackAttributes track : result) {
assertTrue(expected.contains(track));
}
}
private static Stream<Arguments> findAndApplyForcedTracks() {
return Stream.of( return Stream.of(
Arguments.of(List.of(), Arguments.of(List.of(),
Set.of("song & signs"), false, Set.of("song & signs"), false,
@@ -196,13 +275,13 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("findForcedTracksAndApplyChanges") @MethodSource("findAndApplyForcedTracks")
void findForcedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, boolean overwrite, Map<TrackAttributes, Boolean> changes) { void findAndApplyForcedTracks(List<TrackAttributes> tracks, Set<String> keywords, boolean overwrite, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, keywords, Set.of(), Set.of()); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, keywords, Set.of(), Set.of());
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findForcedTracksAndApplyChanges(fileInfo, overwrite); attributeChangeProcessor.findAndApplyForcedTracks(fileInfo, overwrite);
assertEquals(changes.size(), fileInfo.getChanges().getForcedTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getForcedTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {
@@ -211,7 +290,7 @@ class AttributeChangeProcessorTest {
}); });
} }
private static Stream<Arguments> findCommentaryTracksAndApplyChanges() { private static Stream<Arguments> findAndApplyCommentaryTracks() {
return Stream.of( return Stream.of(
Arguments.of(List.of(withName(SUB_GER, "commentary"), withName(SUB_GER, null)), Arguments.of(List.of(withName(SUB_GER, "commentary"), withName(SUB_GER, null)),
Set.of("commentary"), Set.of("commentary"),
@@ -233,13 +312,13 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("findCommentaryTracksAndApplyChanges") @MethodSource("findAndApplyCommentaryTracks")
void findCommentaryTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) { void findAndApplyCommentaryTracks(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), keywords, Set.of()); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), keywords, Set.of());
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findCommentaryTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyCommentaryTracks(fileInfo);
assertEquals(changes.size(), fileInfo.getChanges().getCommentaryTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getCommentaryTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {
@@ -248,7 +327,7 @@ class AttributeChangeProcessorTest {
}); });
} }
private static Stream<Arguments> findHearingImpairedTracksAndApplyChanges() { private static Stream<Arguments> findAndApplyHearingImpairedTracks() {
return Stream.of( return Stream.of(
Arguments.of(List.of(withName(SUB_GER, "SDH"), withName(SUB_GER, null)), Arguments.of(List.of(withName(SUB_GER, "SDH"), withName(SUB_GER, null)),
Set.of("SDH"), Set.of("SDH"),
@@ -270,13 +349,13 @@ class AttributeChangeProcessorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("findHearingImpairedTracksAndApplyChanges") @MethodSource("findAndApplyHearingImpairedTracks")
void findHearingImpairedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) { void findAndApplyHearingImpairedTracks(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), Set.of(), keywords); AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), Set.of(), keywords);
FileInfo fileInfo = new FileInfo(null); FileInfo fileInfo = new FileInfo(null);
fileInfo.addTracks(tracks); fileInfo.addTracks(tracks);
attributeChangeProcessor.findHearingImpairedTracksAndApplyChanges(fileInfo); attributeChangeProcessor.findAndApplyHearingImpairedTracks(fileInfo);
assertEquals(changes.size(), fileInfo.getChanges().getHearingImpairedTrack().size()); assertEquals(changes.size(), fileInfo.getChanges().getHearingImpairedTrack().size());
changes.forEach((key, value) -> { changes.forEach((key, value) -> {