mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Finalize coherent feature
This commit is contained in:
@@ -37,6 +37,7 @@ public class Config {
|
|||||||
private boolean safeMode;
|
private boolean safeMode;
|
||||||
|
|
||||||
private Integer coherent;
|
private Integer coherent;
|
||||||
|
private boolean forceCoherent;
|
||||||
|
|
||||||
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
|
private Set<String> forcedKeywords = new HashSet<>(Arrays.asList("forced", "signs", "songs"));
|
||||||
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));
|
private Set<String> commentaryKeywords = new HashSet<>(Arrays.asList("commentary", "director"));
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ public class ConfigLoader {
|
|||||||
new SetValidator(COMMENTARY_KEYWORDS, false, true),
|
new SetValidator(COMMENTARY_KEYWORDS, false, true),
|
||||||
new SetValidator(EXCLUDED_DIRECTORY, false, true),
|
new SetValidator(EXCLUDED_DIRECTORY, false, true),
|
||||||
new AttributeConfigValidator(),
|
new AttributeConfigValidator(),
|
||||||
new CoherentConfigValidator(COHERENT, false)
|
new CoherentConfigValidator(COHERENT, false),
|
||||||
|
new BooleanValidator(FORCE_COHERENT, false)
|
||||||
);
|
);
|
||||||
|
|
||||||
public static void initConfig(String[] args) {
|
public static void initConfig(String[] args) {
|
||||||
|
|||||||
@@ -121,27 +121,27 @@ public abstract class ConfigValidator<FieldType> {
|
|||||||
* @return false if method invocation failed
|
* @return false if method invocation failed
|
||||||
*/
|
*/
|
||||||
protected boolean setValue(FieldType result) {
|
protected boolean setValue(FieldType result) {
|
||||||
List<Method> methods = Arrays.stream(Config.getInstance().getClass().getDeclaredMethods())
|
for (Method method: Config.getInstance().getClass().getDeclaredMethods()) {
|
||||||
.filter(containsSetterOf(property))
|
if(containsSetterOf(property).test(method)) {
|
||||||
.collect(Collectors.toList());
|
|
||||||
if (methods.size() != 1) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
methods.get(0).invoke(Config.getInstance(), result);
|
method.invoke(Config.getInstance(), result);
|
||||||
|
return true;
|
||||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return true;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Predicate<Method> containsSetterOf(ConfigProperty property) {
|
protected Predicate<Method> containsSetterOf(ConfigProperty property) {
|
||||||
return method -> StringUtils.containsIgnoreCase(method.getName(), "set")
|
return method -> StringUtils.startsWith(method.getName(), "set")
|
||||||
&& StringUtils.containsIgnoreCase(method.getName(), property.prop().replace("-", ""));
|
&& StringUtils.equalsIgnoreCase(method.getName().replace("set", ""), property.prop().replace("-", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Predicate<Method> containsGetterOf(ConfigProperty property) {
|
protected Predicate<Method> containsGetterOf(ConfigProperty property) {
|
||||||
return method -> StringUtils.containsIgnoreCase(method.getName(), "get")
|
return method -> StringUtils.startsWith(method.getName(), "get")
|
||||||
&& StringUtils.containsIgnoreCase(method.getName(), property.prop().replace("-", ""));
|
&& StringUtils.containsIgnoreCase(method.getName(), property.prop().replace("-", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@@ -84,7 +85,18 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
*
|
*
|
||||||
* @param file file or directory to update
|
* @param file file or directory to update
|
||||||
*/
|
*/
|
||||||
abstract void process(File file);
|
void process(File file) {
|
||||||
|
FileInfoDto fileInfo = new FileInfoDto(file);
|
||||||
|
List<FileAttribute> attributes = processor.loadAttributes(file);
|
||||||
|
|
||||||
|
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
|
||||||
|
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
|
||||||
|
|
||||||
|
processor.detectDefaultTracks(fileInfo, attributes, nonForcedTracks);
|
||||||
|
processor.detectDesiredTracks(fileInfo, nonForcedTracks, nonCommentaryTracks);
|
||||||
|
|
||||||
|
updateFile(fileInfo);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persist file changes.
|
* Persist file changes.
|
||||||
@@ -92,7 +104,6 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
* @param fileInfoDto contains information about file and desired configuration.
|
* @param fileInfoDto contains information about file and desired configuration.
|
||||||
*/
|
*/
|
||||||
protected void updateFile(FileInfoDto fileInfoDto) {
|
protected void updateFile(FileInfoDto fileInfoDto) {
|
||||||
statistic.total();
|
|
||||||
switch (fileInfoDto.getStatus()) {
|
switch (fileInfoDto.getStatus()) {
|
||||||
case CHANGE_NECESSARY:
|
case CHANGE_NECESSARY:
|
||||||
statistic.shouldChange();
|
statistic.shouldChange();
|
||||||
@@ -117,6 +128,7 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
statistic.total();
|
||||||
processor.update(fileInfo.getFile(), fileInfo);
|
processor.update(fileInfo.getFile(), fileInfo);
|
||||||
statistic.success();
|
statistic.success();
|
||||||
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
|
log.info("Updated {}", fileInfo.getFile().getAbsolutePath());
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (AttributeConfig config : Config.getInstance().getAttributeConfig()) {
|
for (AttributeConfig config : Config.getInstance().getAttributeConfig()) {
|
||||||
|
|
||||||
for (FileInfoDto fileInfo : fileInfos) {
|
for (FileInfoDto fileInfo : fileInfos) {
|
||||||
List<FileAttribute> attributes = fileAttributeCache.get(fileInfo);
|
List<FileAttribute> attributes = fileAttributeCache.get(fileInfo);
|
||||||
|
|
||||||
@@ -72,8 +73,10 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (fileInfos.stream().allMatch(elem -> elem.getDesiredSubtitleLane() != null && elem.getDesiredAudioLane() != null)) {
|
if (fileInfos.stream().allMatch(elem -> elem.getDesiredSubtitleLane() != null && elem.getDesiredAudioLane() != null)) {
|
||||||
log.debug("Found {}/{} match for {}", config.getAudioLanguage(), config.getSubtitleLanguage(), file.getAbsolutePath());
|
log.info("Found {}/{} match for {}", config.getAudioLanguage(), config.getSubtitleLanguage(), file.getAbsolutePath());
|
||||||
break;
|
statistic.increaseTotalBy(fileInfos.size());
|
||||||
|
fileInfos.forEach(this::updateFile);
|
||||||
|
return; // match found, end process here
|
||||||
}
|
}
|
||||||
|
|
||||||
fileInfos.forEach(f -> {
|
fileInfos.forEach(f -> {
|
||||||
@@ -82,8 +85,13 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply config
|
for(FileInfoDto fileInfo: fileInfos) {
|
||||||
|
statistic.total();
|
||||||
// apply default process if nothing was found (if parameter is set)
|
if (Config.getInstance().isForceCoherent()) {
|
||||||
|
super.process(fileInfo.getFile());
|
||||||
|
} else {
|
||||||
|
statistic.excluded();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,9 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.kernel;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileCollector;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileProcessor;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfoDto;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -30,21 +26,4 @@ public class DefaultAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
.filter(file -> !excludedFiles.contains(file))
|
.filter(file -> !excludedFiles.contains(file))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
void process(File file) {
|
|
||||||
FileInfoDto fileInfo = new FileInfoDto(file);
|
|
||||||
List<FileAttribute> attributes = processor.loadAttributes(file);
|
|
||||||
|
|
||||||
List<FileAttribute> nonForcedTracks = processor.retrieveNonForcedTracks(attributes);
|
|
||||||
List<FileAttribute> nonCommentaryTracks = processor.retrieveNonCommentaryTracks(attributes);
|
|
||||||
|
|
||||||
processor.detectDefaultTracks(fileInfo, attributes, nonForcedTracks);
|
|
||||||
processor.detectDesiredTracks(fileInfo, nonForcedTracks, nonCommentaryTracks);
|
|
||||||
|
|
||||||
updateFile(fileInfo);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,13 @@ import java.util.stream.Collectors;
|
|||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum ConfigProperty {
|
public enum ConfigProperty {
|
||||||
LIBRARY("library", "Path to library", "l", 1),
|
LIBRARY("library-path", "Path to library", "l", 1),
|
||||||
ATTRIBUTE_CONFIG("attribute-config", "Attribute config to decide which tracks to choose when", "a", Option.UNLIMITED_VALUES),
|
ATTRIBUTE_CONFIG("attribute-config", "Attribute config to decide which tracks to choose when", "a", Option.UNLIMITED_VALUES),
|
||||||
CONFIG_PATH("config-path", "Path to config file", "p", 1),
|
CONFIG_PATH("config-path", "Path to config file", "p", 1),
|
||||||
MKV_TOOL_NIX("mkvtoolnix", "Path to mkv tool nix installation", "m", 1),
|
MKV_TOOL_NIX("mkvtoolnix", "Path to mkv tool nix installation", "m", 1),
|
||||||
SAFE_MODE("safe-mode", "Test run (no files will be changes)", "s", 0),
|
SAFE_MODE("safe-mode", "Test run (no files will be changes)", "s", 0),
|
||||||
COHERENT("coherent", "Try to match whole series with same config", "c", 1),
|
COHERENT("coherent", "Try to match all files in dir of depth with the same config", "c", 1),
|
||||||
|
FORCE_COHERENT("force-coherent", "Force coherent and don't update anything if config fits not whole config (default: false)", "cf", 0),
|
||||||
WINDOWS("windows", "Is operating system windows", null, 0),
|
WINDOWS("windows", "Is operating system windows", null, 0),
|
||||||
THREADS("threads", "Thread count (default: 2)", "t", 1),
|
THREADS("threads", "Thread count (default: 2)", "t", 1),
|
||||||
INCLUDE_PATTERN("include-pattern", "Include files matching pattern (default: \".*\")", "i", 1),
|
INCLUDE_PATTERN("include-pattern", "Include files matching pattern (default: \".*\")", "i", 1),
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ class PathValidatorTest {
|
|||||||
|
|
||||||
private static Stream<Arguments> provideTestCases() {
|
private static Stream<Arguments> provideTestCases() {
|
||||||
return Stream.of(
|
return Stream.of(
|
||||||
argumentsOf(LIBRARY, false, null, "library: " + TEST_DIR, new String[]{}, VALID),
|
argumentsOf(LIBRARY, false, null, "library-path: " + TEST_DIR, new String[]{}, VALID),
|
||||||
argumentsOf(LIBRARY, true, null, "", new String[]{"-l", TEST_FILE}, VALID),
|
argumentsOf(LIBRARY, true, null, "", new String[]{"-l", TEST_FILE}, VALID),
|
||||||
|
|
||||||
argumentsOf(LIBRARY, false, TEST_DIR, "", new String[]{}, DEFAULT),
|
argumentsOf(LIBRARY, false, TEST_DIR, "", new String[]{}, DEFAULT),
|
||||||
@@ -48,7 +48,7 @@ class PathValidatorTest {
|
|||||||
argumentsOf(LIBRARY, false, null, "", new String[]{}, NOT_PRESENT),
|
argumentsOf(LIBRARY, false, null, "", new String[]{}, NOT_PRESENT),
|
||||||
|
|
||||||
argumentsOf(LIBRARY, true, null, "", new String[]{"-l", TEST_DIR + "/invalid"}, INVALID),
|
argumentsOf(LIBRARY, true, null, "", new String[]{"-l", TEST_DIR + "/invalid"}, INVALID),
|
||||||
argumentsOf(LIBRARY, false, null, "library: " + TEST_DIR + "/invalid", new String[]{}, INVALID),
|
argumentsOf(LIBRARY, false, null, "library-path: " + TEST_DIR + "/invalid", new String[]{}, INVALID),
|
||||||
argumentsOf(LIBRARY, true, TEST_DIR, "", new String[]{"-l", TEST_DIR + "/invalid"}, INVALID)
|
argumentsOf(LIBRARY, true, TEST_DIR, "", new String[]{"-l", TEST_DIR + "/invalid"}, INVALID)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user