mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bdd3874e7 | ||
|
|
3e74e23512 | ||
|
|
5f2248653b | ||
|
|
15128583df | ||
|
|
76d25fca1b | ||
|
|
957295127a |
12
pom.xml
12
pom.xml
@@ -69,6 +69,14 @@
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.4.2</version>
|
||||
<configuration>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.3.1</version>
|
||||
@@ -85,7 +93,7 @@
|
||||
<resource>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<includes>
|
||||
<include>${project.artifactId}-${project.version}.jar</include>
|
||||
<include>${project.artifactId}.jar</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
@@ -122,7 +130,7 @@
|
||||
|
||||
<input>target/jpackage-input</input>
|
||||
<mainClass>at.pcgamingfreaks.mkvaudiosubtitlechanger.Main</mainClass>
|
||||
<mainJar>${project.artifactId}-${project.version}.jar</mainJar>
|
||||
<mainJar>${project.artifactId}.jar</mainJar>
|
||||
|
||||
<resourceDir>${project.build.directory}/wix-resources/</resourceDir>
|
||||
<type>EXE</type>
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.AttributeUpdater;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CoherentAttributeUpdater;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.SingleFileAttributeUpdater;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CachedFileProcessor;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.FileProcessor;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.MkvFileProcessor;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.*;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
||||
import lombok.Getter;
|
||||
@@ -19,8 +14,8 @@ import picocli.CommandLine;
|
||||
name = "mkvaudiosubtitlechanger",
|
||||
usageHelpAutoWidth = true,
|
||||
customSynopsis = {
|
||||
"mkvaudiosubtitlechanger -a <attributeConfig> [...<attributeConfig>] -l <libraryPath> [-s]",
|
||||
"Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -l /mnt/media/ -s",
|
||||
"mkvaudiosubtitlechanger [-a <attributeConfig> [...<attributeConfig>]] [-s] <libraryPath>",
|
||||
"Example: mkvaudiosubtitlechanger -a eng:eng eng:ger -s /mnt/media/",
|
||||
""
|
||||
},
|
||||
requiredOptionMarker = '*',
|
||||
@@ -41,10 +36,11 @@ public class CommandRunner implements Runnable {
|
||||
|
||||
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate());
|
||||
FileProcessor fileProcessor = new CachedFileProcessor(new MkvFileProcessor(config.getMkvToolNix(), fileFilter));
|
||||
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
|
||||
|
||||
AttributeUpdater kernel = config.getCoherent() != null
|
||||
? new CoherentAttributeUpdater(config, fileProcessor)
|
||||
: new SingleFileAttributeUpdater(config, fileProcessor);
|
||||
? new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor)
|
||||
: new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor);
|
||||
kernel.execute();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public class AttributeChangeProcessor {
|
||||
|
||||
public void findHearingImpairedTracksAndApplyChanges(FileInfo fileInfo) {
|
||||
fileInfo.getTracks().stream()
|
||||
.filter(track -> !track.commentary())
|
||||
.filter(track -> !track.hearingImpaired())
|
||||
.filter(track -> track.trackName() != null)
|
||||
.filter(track -> hearingImpairedKeywords.stream().anyMatch(keyword -> track.trackName().toLowerCase().contains(keyword.toLowerCase(Locale.ROOT))))
|
||||
.forEach(attr -> {
|
||||
|
||||
@@ -27,10 +27,10 @@ public abstract class AttributeUpdater {
|
||||
|
||||
private final ExecutorService executor;
|
||||
|
||||
public AttributeUpdater(InputConfig config, FileProcessor fileProcessor) {
|
||||
public AttributeUpdater(InputConfig config, FileProcessor fileProcessor, AttributeChangeProcessor attributeChangeProcessor) {
|
||||
this.config = config;
|
||||
this.fileProcessor = fileProcessor;
|
||||
this.attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
|
||||
this.attributeChangeProcessor = attributeChangeProcessor;
|
||||
this.executor = Executors.newFixedThreadPool(config.getThreads());
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public abstract class AttributeUpdater {
|
||||
// writeLastExecutionDate();
|
||||
|
||||
statistic.stopTimer();
|
||||
statistic.printResult();
|
||||
statistic.print();
|
||||
}
|
||||
|
||||
protected abstract List<File> getFiles();
|
||||
@@ -82,35 +82,24 @@ public abstract class AttributeUpdater {
|
||||
* @param fileInfo contains information about file and desired configuration.
|
||||
*/
|
||||
protected void checkStatusAndUpdate(FileInfo fileInfo) {
|
||||
switch (fileInfo.getStatus()) {
|
||||
case CHANGE_NECESSARY:
|
||||
statistic.shouldChange();
|
||||
commitChange(fileInfo);
|
||||
break;
|
||||
case NO_SUITABLE_CONFIG:
|
||||
statistic.noSuitableConfigFound();
|
||||
break;
|
||||
case ALREADY_SUITED:
|
||||
statistic.alreadyFits();
|
||||
break;
|
||||
case UNKNOWN:
|
||||
default:
|
||||
statistic.failure();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!fileInfo.getChanges().isEmpty()) {
|
||||
statistic.changePlanned();
|
||||
|
||||
private void commitChange(FileInfo fileInfo) {
|
||||
if (config.isSafeMode()) return;
|
||||
|
||||
try {
|
||||
fileProcessor.update(fileInfo);
|
||||
statistic.success();
|
||||
statistic.changeSuccessful();
|
||||
log.info("Commited {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath());
|
||||
} catch (IOException | MkvToolNixException e) {
|
||||
statistic.failedChanging();
|
||||
statistic.changeFailed();
|
||||
log.warn("Couldn't commit {} to '{}'", fileInfo.getMatchedConfig().toStringShort(), fileInfo.getFile().getPath(), e);
|
||||
}
|
||||
} else if (fileInfo.getChanges().isEmpty()) {
|
||||
statistic.unchanged();
|
||||
} else {
|
||||
statistic.unknownFailed();
|
||||
}
|
||||
}
|
||||
|
||||
// should this be here?
|
||||
|
||||
@@ -14,8 +14,8 @@ import java.util.Set;
|
||||
@Slf4j
|
||||
public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
||||
|
||||
public CoherentAttributeUpdater(InputConfig config, FileProcessor processor) {
|
||||
super(config, processor);
|
||||
public CoherentAttributeUpdater(InputConfig config, FileProcessor processor, AttributeChangeProcessor attributeChangeProcessor) {
|
||||
super(config, processor, attributeChangeProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -65,7 +65,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
||||
|
||||
if (config.isForceCoherent()) {
|
||||
log.info("No coherent match found, aborting: {}", rootDir.getPath());
|
||||
statistic.increaseNoSuitableConfigFoundBy(files.size());
|
||||
statistic.increaseUnchangedBy(files.size());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class CoherentAttributeUpdater extends SingleFileAttributeUpdater {
|
||||
|
||||
if (fileInfo.getTracks().isEmpty()) {
|
||||
log.warn("No attributes found for file {}", file);
|
||||
statistic.failure();
|
||||
statistic.unknownFailed();
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ public class MkvFileProcessor implements FileProcessor {
|
||||
(Boolean) properties.getOrDefault("default_track", false),
|
||||
(Boolean) properties.getOrDefault("forced_track", false),
|
||||
(Boolean) properties.getOrDefault("commentary_track", false),
|
||||
(Boolean) properties.getOrDefault("hearing_impaired_track", false),
|
||||
(Boolean) properties.getOrDefault("flag_hearing_impaired", false),
|
||||
TrackType.valueOf(((String) attribute.get("type")).toUpperCase(Locale.ENGLISH))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class SingleFileAttributeUpdater extends AttributeUpdater {
|
||||
|
||||
public SingleFileAttributeUpdater(InputConfig config, FileProcessor processor) {
|
||||
super(config, processor);
|
||||
public SingleFileAttributeUpdater(InputConfig config, FileProcessor processor, AttributeChangeProcessor attributeChangeProcessor) {
|
||||
super(config, processor, attributeChangeProcessor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -32,7 +32,7 @@ public class SingleFileAttributeUpdater extends AttributeUpdater {
|
||||
|
||||
if (fileInfo.getTracks().isEmpty()) {
|
||||
log.warn("No attributes found for file {}", file);
|
||||
statistic.failure();
|
||||
statistic.unknownFailed();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -53,11 +53,4 @@ public class FileInfo {
|
||||
public void resetChanges() {
|
||||
changes = new PlannedChange();
|
||||
}
|
||||
|
||||
public FileStatus getStatus() {
|
||||
if (!changes.isEmpty()) return FileStatus.CHANGE_NECESSARY;
|
||||
if (matchedConfig == null) return FileStatus.NO_SUITABLE_CONFIG;
|
||||
if (changes.isEmpty()) return FileStatus.ALREADY_SUITED;
|
||||
return FileStatus.UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
||||
|
||||
public enum FileStatus {
|
||||
CHANGE_NECESSARY,
|
||||
NO_SUITABLE_CONFIG,
|
||||
ALREADY_SUITED,
|
||||
UNKNOWN;
|
||||
}
|
||||
@@ -28,12 +28,13 @@ public class InputConfig implements CommandLine.IVersionProvider {
|
||||
@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")
|
||||
@CommandLine.Parameters(description = "path to library")
|
||||
private File libraryPath;
|
||||
|
||||
@Option(names = {"-a", "--attribute-config"}, 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 = new AttributeConfig[0];
|
||||
@ValidMkvToolNix(message = "does not exist")
|
||||
@Option(names = {"-m", "--mkvtoolnix"}, defaultValue = "${DEFAULT_MKV_TOOL_NIX}", description = "path to mkvtoolnix installation")
|
||||
private File mkvToolNix;
|
||||
@@ -90,8 +91,8 @@ public class InputConfig implements CommandLine.IVersionProvider {
|
||||
return new StringJoiner(", ", InputConfig.class.getSimpleName() + "[", "]")
|
||||
.add("configPath=" + configPath)
|
||||
.add("spec=" + spec)
|
||||
.add("attributeConfig=" + Arrays.toString(attributeConfig))
|
||||
.add("libraryPath=" + libraryPath)
|
||||
.add("attributeConfig=" + Arrays.toString(attributeConfig))
|
||||
.add("mkvToolNix=" + mkvToolNix)
|
||||
.add("safeMode=" + safeMode)
|
||||
.add("threads=" + threads)
|
||||
|
||||
@@ -1,33 +1,21 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Getter
|
||||
@Slf4j
|
||||
public class ResultStatistic {
|
||||
private static final String result = "Total files: %s%n" +
|
||||
"├─ Excluded: %s%n" +
|
||||
"├─ Should change: %s%n" +
|
||||
"│ ├─ Failed changing: %s%n" +
|
||||
"│ └─ Successfully changed: %s%n" +
|
||||
"├─ No suitable config found: %s%n" +
|
||||
"├─ Already fit config: %s%n" +
|
||||
"└─ Failed: %s%n" +
|
||||
"Runtime: %s";
|
||||
private static final String PRINT_TEMPLATE = "Total: %s, Changing: %s (Successful: %s, Failed %s), Unchanged: %s, Excluded: %s, Unknown/Failed: %s\nRuntime: %s";
|
||||
private static ResultStatistic instance;
|
||||
|
||||
private int changePlanned = 0;
|
||||
private int changeFailed = 0;
|
||||
private int changeSuccessful = 0;
|
||||
private int unchanged = 0;
|
||||
private int excluded = 0;
|
||||
private int unknownFailed = 0;
|
||||
|
||||
private int shouldChange = 0;
|
||||
private int failedChanging = 0;
|
||||
private int successfullyChanged = 0;
|
||||
|
||||
private int noSuitableConfigFound = 0;
|
||||
private int alreadyFits = 0;
|
||||
private int failed = 0;
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private long startTime = 0;
|
||||
private long runtime = 0;
|
||||
|
||||
@@ -43,43 +31,35 @@ public class ResultStatistic {
|
||||
}
|
||||
|
||||
public int total() {
|
||||
return shouldChange + noSuitableConfigFound + alreadyFits + failed;
|
||||
return changePlanned + unchanged + excluded + unknownFailed;
|
||||
}
|
||||
|
||||
public void increaseExcludedBy(int amount) {
|
||||
excluded += amount;
|
||||
public synchronized void changePlanned() {
|
||||
changePlanned++;
|
||||
}
|
||||
|
||||
public synchronized void changeSuccessful() {
|
||||
changeSuccessful++;
|
||||
}
|
||||
|
||||
public synchronized void changeFailed() {
|
||||
changeFailed++;
|
||||
}
|
||||
|
||||
public synchronized void unchanged() {
|
||||
unchanged++;
|
||||
}
|
||||
|
||||
public synchronized void increaseUnchangedBy(int amount) {
|
||||
unchanged += amount;
|
||||
}
|
||||
|
||||
public synchronized void excluded() {
|
||||
excluded++;
|
||||
}
|
||||
|
||||
public synchronized void shouldChange() {
|
||||
shouldChange++;
|
||||
}
|
||||
|
||||
public synchronized void success() {
|
||||
successfullyChanged++;
|
||||
}
|
||||
|
||||
public synchronized void failedChanging() {
|
||||
failedChanging++;
|
||||
}
|
||||
|
||||
public synchronized void noSuitableConfigFound() {
|
||||
noSuitableConfigFound++;
|
||||
}
|
||||
|
||||
public synchronized void increaseNoSuitableConfigFoundBy(int amount) {
|
||||
noSuitableConfigFound += amount;
|
||||
}
|
||||
|
||||
public synchronized void alreadyFits() {
|
||||
alreadyFits++;
|
||||
}
|
||||
|
||||
public synchronized void failure() {
|
||||
failed++;
|
||||
public synchronized void unknownFailed() {
|
||||
unknownFailed++;
|
||||
}
|
||||
|
||||
public void startTimer() {
|
||||
@@ -90,11 +70,6 @@ public class ResultStatistic {
|
||||
runtime = System.currentTimeMillis() - startTime;
|
||||
}
|
||||
|
||||
public void printResult() {
|
||||
System.out.println(prettyPrint());
|
||||
log.info(this.toString());
|
||||
}
|
||||
|
||||
private String formatTimer() {
|
||||
int seconds = (int) (runtime / 1000);
|
||||
int minutes = seconds / 60;
|
||||
@@ -112,22 +87,14 @@ public class ResultStatistic {
|
||||
}
|
||||
}
|
||||
|
||||
public String prettyPrint() {
|
||||
return String.format(result, total(), excluded, shouldChange, failedChanging, successfullyChanged,
|
||||
noSuitableConfigFound, alreadyFits, failed, formatTimer());
|
||||
public void print() {
|
||||
String result = this.toString();
|
||||
System.out.println(result);
|
||||
log.info(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ResultStatistic: " + "total=" + total() +
|
||||
", excluded=" + excluded +
|
||||
", shouldChange=" + shouldChange +
|
||||
" (failedChanging=" + failedChanging +
|
||||
", successfullyChanged=" + successfullyChanged +
|
||||
"), noSuitableConfigFound=" + noSuitableConfigFound +
|
||||
", alreadyFits=" + alreadyFits +
|
||||
", failed=" + failed +
|
||||
", runtime=" + formatTimer();
|
||||
return String.format(PRINT_TEMPLATE, total(), changePlanned, changeSuccessful, changeFailed, unchanged, excluded, unknownFailed, formatTimer());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public record TrackAttributes(int id, String language, String trackName,
|
||||
return id == attribute.id
|
||||
&& defaultt == attribute.defaultt
|
||||
&& forced == attribute.forced
|
||||
&& commentary == attribute.commentary
|
||||
&& hearingImpaired == attribute.hearingImpaired
|
||||
&& Objects.equals(language, attribute.language)
|
||||
&& Objects.equals(trackName, attribute.trackName)
|
||||
&& type == attribute.type;
|
||||
@@ -28,6 +30,8 @@ public record TrackAttributes(int id, String language, String trackName,
|
||||
", trackName='" + trackName + '\'' +
|
||||
", defaultt=" + defaultt +
|
||||
", forced=" + forced +
|
||||
", commentary=" + commentary +
|
||||
", hearingImpaired=" + hearingImpaired +
|
||||
", type=" + type +
|
||||
']';
|
||||
}
|
||||
|
||||
@@ -248,7 +248,7 @@ class AttributeChangeProcessorTest {
|
||||
Set.of("SDH"),
|
||||
Map.ofEntries(on(withName(SUB_GER, "SDH")))
|
||||
),
|
||||
Arguments.of(List.of(withName(AUDIO_GER_COMMENTARY, "SDH")),
|
||||
Arguments.of(List.of(withName(AUDIO_GER_HEARING, "SDH")),
|
||||
Set.of("SDH"),
|
||||
Map.ofEntries()
|
||||
),
|
||||
@@ -260,7 +260,7 @@ class AttributeChangeProcessorTest {
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("findCommentaryTracksAndApplyChanges")
|
||||
@MethodSource("findHearingImpairedTracksAndApplyChanges")
|
||||
void findHearingImpairedTracksAndApplyChanges(List<TrackAttributes> tracks, Set<String> keywords, Map<TrackAttributes, Boolean> changes) {
|
||||
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(new String[]{}, Set.of(), Set.of(), keywords);
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
||||
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.AUDIO_GER;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class AttributeUpdaterTest {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
ResultStatistic.getInstance(true);
|
||||
}
|
||||
|
||||
private static Stream<Arguments> checkStatusAndUpdate() {
|
||||
return Stream.of(
|
||||
Arguments.of(info(new AttributeConfig("ger", "ger"), AUDIO_GER), supplier(() -> ResultStatistic.getInstance().getChangePlanned())),
|
||||
Arguments.of(info(new AttributeConfig("ger", "ger"), null), supplier(() -> ResultStatistic.getInstance().getUnchanged())),
|
||||
Arguments.of(info(null, null), supplier(() -> ResultStatistic.getInstance().getUnchanged()))
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("checkStatusAndUpdate")
|
||||
void checkStatusAndUpdate(FileInfo fileInfo, Supplier<Integer> getActual) {
|
||||
InputConfig config = new InputConfig();
|
||||
config.setThreads(1);
|
||||
config.setSafeMode(true);
|
||||
AttributeUpdater underTest = new AttributeUpdater(config, null, null) {
|
||||
@Override
|
||||
protected List<File> getFiles() {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void process(File file) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
underTest.checkStatusAndUpdate(fileInfo);
|
||||
assertEquals(1, getActual.get());
|
||||
}
|
||||
|
||||
private static Supplier<Integer> supplier(Supplier<Integer> supplier) {
|
||||
return supplier;
|
||||
}
|
||||
|
||||
private static FileInfo info(AttributeConfig config, TrackAttributes attr) {
|
||||
FileInfo fileInfo = new FileInfo(null);
|
||||
fileInfo.setMatchedConfig(config);
|
||||
if(attr != null) fileInfo.getChanges().getDefaultTrack().put(attr, true);
|
||||
return fileInfo;
|
||||
}
|
||||
}
|
||||
@@ -65,9 +65,10 @@ class CoherentAttributeUpdaterTest {
|
||||
@MethodSource("findMatch")
|
||||
void findMatch(AttributeConfig attributeConfig, List<Pair<File, FileInfo>> fileInfoMock, boolean expectedMatch, int expectedMatchCount) throws InvocationTargetException, IllegalAccessException {
|
||||
CommandRunner commandRunner = new CommandRunner();
|
||||
new CommandLine(commandRunner).parseArgs("-l", "/arst", "-a", "ger:ger");
|
||||
new CommandLine(commandRunner).parseArgs("-a", "ger:ger", "/arst");
|
||||
InputConfig config = commandRunner.getConfig();
|
||||
CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor);
|
||||
AttributeChangeProcessor attributeChangeProcessor = new AttributeChangeProcessor(config.getPreferredSubtitles().toArray(new String[0]), config.getForcedKeywords(), config.getCommentaryKeywords(), config.getHearingImpaired());
|
||||
CoherentAttributeUpdater updater = new CoherentAttributeUpdater(config, fileProcessor, attributeChangeProcessor);
|
||||
Set<FileInfo> matchedFiles = new HashSet<>(fileInfoMock.size() * 2);
|
||||
|
||||
List<File> files = new ArrayList<>();
|
||||
|
||||
@@ -57,6 +57,8 @@ class MkvFileProcessorTest {
|
||||
"default_track": true,
|
||||
"enabled_track": true,
|
||||
"forced_track": false,
|
||||
"commentary_track": true,
|
||||
"flag_hearing_impaired": true,
|
||||
"language": "eng",
|
||||
"number": 3
|
||||
},
|
||||
@@ -88,8 +90,8 @@ class MkvFileProcessorTest {
|
||||
assertEquals("eng", sub.language());
|
||||
assertTrue(sub.defaultt());
|
||||
assertFalse(sub.forced());
|
||||
assertFalse(sub.hearingImpaired());
|
||||
assertFalse(sub.commentary());
|
||||
assertTrue(sub.hearingImpaired());
|
||||
assertTrue(sub.commentary());
|
||||
assertEquals(TrackType.SUBTITLES, sub.type());
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class ValidationExecutionStrategyTest {
|
||||
CommandRunner underTest = new CommandRunner();
|
||||
new CommandLine(underTest)
|
||||
.setExecutionStrategy(new ValidationExecutionStrategy())
|
||||
.parseArgs("-a", "ger:ger", "-l", TEST_FILE, "-m", TEST_MKVTOOLNIX_DIR);
|
||||
.parseArgs("-a", "ger:ger", "-m", TEST_MKVTOOLNIX_DIR, TEST_FILE);
|
||||
|
||||
assertEquals(TEST_FILE, underTest.getConfig().getLibraryPath().getPath().replace("\\", "/"));
|
||||
assertEquals(TEST_MKVTOOLNIX_DIR, underTest.getConfig().getMkvToolNix().getPath().replace("\\", "/"));
|
||||
@@ -30,17 +30,16 @@ class ValidationExecutionStrategyTest {
|
||||
|
||||
private static Stream<Arguments> validateFailure() {
|
||||
return Stream.of(
|
||||
Arguments.of(new String[]{"-a", "jpn:ger"}, "Error: Missing required argument(s): --library=<libraryPath>"),
|
||||
Arguments.of(new String[]{"-a", "jpn:ger", "-l"}, "Missing required parameter for option '--library' (<libraryPath>)"),
|
||||
Arguments.of(new String[]{"-l", "/arstarstarst"}, "Error: Missing required argument(s): --attribute-config=<attributeConfig>"),
|
||||
Arguments.of(new String[]{"-l", "/arstarstarst", "-a",}, "Missing required parameter for option '--attribute-config' at index 0 (<attributeConfig>)"),
|
||||
Arguments.of(new String[]{"-l", "/arstarstarst", "-a", "jpn:ger"}, "libraryPath does not exist"),
|
||||
Arguments.of(args("-m"), "Missing required parameter for option '--mkvtoolnix' (<mkvToolNix>)"),
|
||||
Arguments.of(args("-m", TEST_INVALID_DIR), "mkvToolNix does not exist"),
|
||||
Arguments.of(args("-t"), "Missing required parameter for option '--threads' (<threads>)"),
|
||||
Arguments.of(args("-t", "0"), "threads must be greater than or equal to 1"),
|
||||
Arguments.of(args("-t", "-1"), "threads must be greater than or equal to 1"),
|
||||
Arguments.of(args("-c", "-1"), "coherent must be greater than or equal to 0")
|
||||
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[]{"/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", "-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>)"),
|
||||
Arguments.of(new String[]{"./", "-t", "0"}, "threads must be greater than or equal to 1"),
|
||||
Arguments.of(new String[]{"./", "-t", "-1"}, "threads must be greater than or equal to 1"),
|
||||
Arguments.of(new String[]{"./", "-c", "-1"}, "coherent must be greater than or equal to 0")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.model;
|
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import java.nio.file.attribute.FileAttribute;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileStatus.*;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileInfoTestUtil.*;
|
||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.TestUtil.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class FileInfoTest {
|
||||
|
||||
private static Stream<Arguments> getStatus() {
|
||||
return Stream.of(
|
||||
Arguments.of(CHANGE_NECESSARY, info(new AttributeConfig("ger", "ger"), AUDIO_GER)),
|
||||
Arguments.of(ALREADY_SUITED, info(new AttributeConfig("ger", "ger"), null)),
|
||||
Arguments.of(NO_SUITABLE_CONFIG, info(null, null))
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void getStatus(FileStatus expected, FileInfo underTest) {
|
||||
FileStatus actual = underTest.getStatus();
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
private static FileInfo info(AttributeConfig config, TrackAttributes attr) {
|
||||
FileInfo fileInfo = new FileInfo(null);
|
||||
fileInfo.setMatchedConfig(config);
|
||||
if(attr != null) fileInfo.getChanges().getDefaultTrack().put(attr, true);
|
||||
return fileInfo;
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||
public class TestUtil {
|
||||
|
||||
public static String[] args(String... args) {
|
||||
String[] staticArray = new String[]{"-l", "/", "-a", "jpn:ger"};
|
||||
String[] staticArray = new String[]{"-a", "jpn:ger", "/"};
|
||||
String[] result = new String[staticArray.length + args.length];
|
||||
System.arraycopy(staticArray, 0, result, 0, staticArray.length);
|
||||
System.arraycopy(args, 0, result, staticArray.length, args.length);
|
||||
System.arraycopy(args, 0, result, 0, args.length);
|
||||
System.arraycopy(staticArray, 0, result, args.length, staticArray.length);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user