mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Make InputConfig no longer be a singleton
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
||||||
|
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileFilter;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.MkvFileProcessor;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidationExecutionStrategy;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidationExecutionStrategy;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CachedMkvFileProcessor;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.CachedMkvFileProcessor;
|
||||||
@@ -50,10 +52,12 @@ public class Main implements Runnable {
|
|||||||
Configurator.setRootLevel(Level.DEBUG);
|
Configurator.setRootLevel(Level.DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputConfig.setInstance(config);
|
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate());
|
||||||
AttributeUpdaterKernel kernel = InputConfig.getInstance().getCoherent() != null
|
MkvFileProcessor fileProcessor = new CachedMkvFileProcessor(config.getMkvToolNix(), fileFilter);
|
||||||
? new CoherentAttributeUpdaterKernel(config, new CachedMkvFileProcessor())
|
|
||||||
: new DefaultAttributeUpdaterKernel(config, new CachedMkvFileProcessor());
|
AttributeUpdaterKernel kernel = config.getCoherent() != null
|
||||||
|
? new CoherentAttributeUpdaterKernel(config, fileProcessor)
|
||||||
|
: new DefaultAttributeUpdaterKernel(config, fileProcessor);
|
||||||
kernel.execute();
|
kernel.execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ResultStatistic;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -16,11 +16,16 @@ import java.util.regex.Matcher;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class FileFilter {
|
public class FileFilter {
|
||||||
private static final String EXTENSION_GROUP = "extension";
|
private final Set<String> excluded;
|
||||||
private static final Pattern extensionPattern = Pattern.compile(String.format(".*(?<%s>\\..*)", EXTENSION_GROUP));
|
private final Pattern includePattern;
|
||||||
|
private final Date filterDate;
|
||||||
|
|
||||||
public static boolean accept(File pathName, Set<String> fileExtensions) {
|
private final String EXTENSION_GROUP = "extension";
|
||||||
|
private final Pattern extensionPattern = Pattern.compile(String.format(".*(?<%s>\\..*)", EXTENSION_GROUP));
|
||||||
|
|
||||||
|
public boolean accept(File pathName, Set<String> fileExtensions) {
|
||||||
// Ignore files irrelevant for statistics
|
// Ignore files irrelevant for statistics
|
||||||
if (!hasProperFileExtension(pathName, new HashSet<>(fileExtensions))) {
|
if (!hasProperFileExtension(pathName, new HashSet<>(fileExtensions))) {
|
||||||
return false;
|
return false;
|
||||||
@@ -29,7 +34,7 @@ public class FileFilter {
|
|||||||
ResultStatistic.getInstance().total();
|
ResultStatistic.getInstance().total();
|
||||||
if (!hasMatchingPattern(pathName)
|
if (!hasMatchingPattern(pathName)
|
||||||
|| !isNewer(pathName)
|
|| !isNewer(pathName)
|
||||||
|| isExcluded(pathName, new HashSet<>(InputConfig.getInstance().getExcluded()))) {
|
|| isExcluded(pathName, new HashSet<>(excluded))) {
|
||||||
ResultStatistic.getInstance().excluded();
|
ResultStatistic.getInstance().excluded();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -37,18 +42,17 @@ public class FileFilter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasProperFileExtension(File pathName, Set<String> fileExtensions) {
|
private boolean hasProperFileExtension(File pathName, Set<String> fileExtensions) {
|
||||||
Matcher matcher = extensionPattern.matcher(pathName.getName());
|
Matcher matcher = extensionPattern.matcher(pathName.getName());
|
||||||
return matcher.find() && fileExtensions.contains(matcher.group(EXTENSION_GROUP));
|
return matcher.find() && fileExtensions.contains(matcher.group(EXTENSION_GROUP));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean hasMatchingPattern(File pathName) {
|
private boolean hasMatchingPattern(File pathName) {
|
||||||
return InputConfig.getInstance().getIncludePattern().matcher(pathName.getName()).matches();
|
return includePattern.matcher(pathName.getName()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNewer(File pathName) {
|
private boolean isNewer(File pathName) {
|
||||||
InputConfig config = InputConfig.getInstance();
|
if (filterDate == null) return true;
|
||||||
if (config.getFilterDate() == null) return true;
|
|
||||||
try {
|
try {
|
||||||
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
|
BasicFileAttributes attributes = Files.readAttributes(pathName.toPath(), BasicFileAttributes.class);
|
||||||
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
|
return isNewer(DateUtils.convert(attributes.creationTime().toMillis()));
|
||||||
@@ -58,11 +62,11 @@ public class FileFilter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isNewer(Date creationDate) {
|
private boolean isNewer(Date creationDate) {
|
||||||
return creationDate.toInstant().isAfter(InputConfig.getInstance().getFilterDate().toInstant());
|
return creationDate.toInstant().isAfter(filterDate.toInstant());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isExcluded(File pathName, Set<String> excludedDirs) {
|
private boolean isExcluded(File pathName, Set<String> excludedDirs) {
|
||||||
if (excludedDirs.contains(pathName.getPath())) return true;
|
if (excludedDirs.contains(pathName.getPath())) return true;
|
||||||
|
|
||||||
// TODO improve partial matches and wildcard?
|
// TODO improve partial matches and wildcard?
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
||||||
import at.pcgamingfreaks.yaml.YAML;
|
import at.pcgamingfreaks.yaml.YAML;
|
||||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import me.tongfei.progressbar.ProgressBar;
|
import me.tongfei.progressbar.ProgressBar;
|
||||||
@@ -54,7 +53,7 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
statistic.startTimer();
|
statistic.startTimer();
|
||||||
|
|
||||||
try (ProgressBar progressBar = pbBuilder().build()) {
|
try (ProgressBar progressBar = pbBuilder().build()) {
|
||||||
List<File> files = processor.loadFiles(InputConfig.getInstance().getLibraryPath().getAbsolutePath());
|
List<File> files = processor.loadFiles(config.getLibraryPath().getAbsolutePath());
|
||||||
|
|
||||||
progressBar.maxHint(files.size());
|
progressBar.maxHint(files.size());
|
||||||
progressBar.refresh();
|
progressBar.refresh();
|
||||||
@@ -122,7 +121,7 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void commitChange(FileInfo fileInfo) {
|
private void commitChange(FileInfo fileInfo) {
|
||||||
if (InputConfig.getInstance().isSafeMode()) return;
|
if (config.isSafeMode()) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
processor.update(fileInfo);
|
processor.update(fileInfo);
|
||||||
@@ -136,7 +135,7 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
|
|
||||||
// should this be here?
|
// should this be here?
|
||||||
protected void writeLastExecutionDate() {
|
protected void writeLastExecutionDate() {
|
||||||
if (InputConfig.getInstance().isSafeMode()) {
|
if (config.isSafeMode()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +149,7 @@ public abstract class AttributeUpdaterKernel {
|
|||||||
if (!lastExecutionFile.exists()) lastExecutionFile.createNewFile();
|
if (!lastExecutionFile.exists()) lastExecutionFile.createNewFile();
|
||||||
|
|
||||||
YAML yaml = new YAML(lastExecutionFile);
|
YAML yaml = new YAML(lastExecutionFile);
|
||||||
yaml.set(InputConfig.getInstance().getNormalizedLibraryPath(), DateUtils.convert(new Date()));
|
yaml.set(config.getNormalizedLibraryPath(), DateUtils.convert(new Date()));
|
||||||
yaml.save(lastExecutionFile);
|
yaml.save(lastExecutionFile);
|
||||||
} catch (IOException | YamlInvalidContentException e) {
|
} catch (IOException | YamlInvalidContentException e) {
|
||||||
log.error("last-execution.yml could not be created or read.", e);
|
log.error("last-execution.yml could not be created or read.", e);
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
void process(File file) {
|
void process(File file) {
|
||||||
process(file, InputConfig.getInstance().getCoherent());
|
process(file, config.getCoherent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void process(File file, int depth) {
|
void process(File file, int depth) {
|
||||||
@@ -60,7 +60,7 @@ public class CoherentAttributeUpdaterKernel extends AttributeUpdaterKernel {
|
|||||||
// .map(FileInfoOld::new)
|
// .map(FileInfoOld::new)
|
||||||
// .collect(Collectors.toList());
|
// .collect(Collectors.toList());
|
||||||
|
|
||||||
for (AttributeConfig config : InputConfig.getInstance().getAttributeConfig()) {
|
for (AttributeConfig config : config.getAttributeConfig()) {
|
||||||
|
|
||||||
// for (FileInfoOld fileInfoOld : fileInfoOlds) {
|
// for (FileInfoOld fileInfoOld : fileInfoOlds) {
|
||||||
// List<TrackAttributes> attributes = processor.readAttributes(fileInfoOld.getFile());
|
// List<TrackAttributes> attributes = processor.readAttributes(fileInfoOld.getFile());
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.Cache;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.Cache;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileFilter;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -8,6 +9,10 @@ import java.io.File;
|
|||||||
public class CachedMkvFileProcessor extends MkvFileProcessor {
|
public class CachedMkvFileProcessor extends MkvFileProcessor {
|
||||||
Cache<File, FileInfo> cache = new Cache<>();
|
Cache<File, FileInfo> cache = new Cache<>();
|
||||||
|
|
||||||
|
public CachedMkvFileProcessor(File mkvToolNixInstallation, FileFilter fileFilter) {
|
||||||
|
super(mkvToolNixInstallation, fileFilter);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FileInfo readAttributes(File file) {
|
public FileInfo readAttributes(File file) {
|
||||||
return cache.retrieve(file, super::readAttributes);
|
return cache.retrieve(file, super::readAttributes);
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileFilter;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileFilter;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.SubtitleTrackComparator;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.SetUtils;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.apache.logging.log4j.core.util.IOUtils;
|
import org.apache.logging.log4j.core.util.IOUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -22,12 +19,14 @@ import java.util.*;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType.AUDIO;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileUtils.getPathFor;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackType.SUBTITLES;
|
|
||||||
import static java.lang.String.format;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
public class MkvFileProcessor implements FileProcessor {
|
public class MkvFileProcessor implements FileProcessor {
|
||||||
|
protected final File mkvToolNixInstallation;
|
||||||
|
protected final FileFilter fileFilter;
|
||||||
|
|
||||||
private final ObjectMapper mapper = new ObjectMapper();
|
private final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
private static final Set<String> fileExtensions = new HashSet<>(Set.of(".mkv", ".mka", ".mks", ".mk3d"));
|
private static final Set<String> fileExtensions = new HashSet<>(Set.of(".mkv", ".mka", ".mks", ".mk3d"));
|
||||||
@@ -46,7 +45,7 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
return paths
|
return paths
|
||||||
.filter(Files::isRegularFile)
|
.filter(Files::isRegularFile)
|
||||||
.map(Path::toFile)
|
.map(Path::toFile)
|
||||||
.filter(file -> FileFilter.accept(file, fileExtensions))
|
.filter(file -> fileFilter.accept(file, fileExtensions))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("Couldn't find file or directory!", e);
|
log.error("Couldn't find file or directory!", e);
|
||||||
@@ -76,7 +75,7 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
FileInfo fileInfo = new FileInfo(file);
|
FileInfo fileInfo = new FileInfo(file);
|
||||||
try {
|
try {
|
||||||
String[] command = new String[]{
|
String[] command = new String[]{
|
||||||
InputConfig.getInstance().getPathFor(MkvToolNix.MKV_MERGE),
|
getPathFor(mkvToolNixInstallation, MkvToolNix.MKV_MERGE).getAbsolutePath(),
|
||||||
"--identify",
|
"--identify",
|
||||||
"--identification-format",
|
"--identification-format",
|
||||||
"json",
|
"json",
|
||||||
@@ -121,7 +120,7 @@ public class MkvFileProcessor implements FileProcessor {
|
|||||||
@Override
|
@Override
|
||||||
public void update(FileInfo fileInfo) throws IOException, MkvToolNixException {
|
public void update(FileInfo fileInfo) throws IOException, MkvToolNixException {
|
||||||
List<String> command = new ArrayList<>();
|
List<String> command = new ArrayList<>();
|
||||||
command.add(InputConfig.getInstance().getPathFor(MkvToolNix.MKV_PROP_EDIT));
|
command.add(getPathFor(mkvToolNixInstallation, MkvToolNix.MKV_PROP_EDIT).getAbsolutePath());
|
||||||
command.add(String.format(fileInfo.getFile().getAbsolutePath()));
|
command.add(String.format(fileInfo.getFile().getAbsolutePath()));
|
||||||
|
|
||||||
PlannedChange changes = fileInfo.getChanges();
|
PlannedChange changes = fileInfo.getChanges();
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidFile;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidMkvToolNix;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.validation.ValidMkvToolNix;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileUtils;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.FileUtils;
|
||||||
import jakarta.validation.constraints.Min;
|
import jakarta.validation.constraints.Min;
|
||||||
import lombok.AccessLevel;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -24,9 +23,6 @@ import picocli.CommandLine.Option;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@CommandLine.Command
|
@CommandLine.Command
|
||||||
public class InputConfig {
|
public class InputConfig {
|
||||||
@Getter(AccessLevel.NONE)
|
|
||||||
@Setter(AccessLevel.NONE)
|
|
||||||
private static InputConfig config = null;
|
|
||||||
|
|
||||||
private File configPath;
|
private File configPath;
|
||||||
|
|
||||||
@@ -89,21 +85,6 @@ public class InputConfig {
|
|||||||
System.setProperty("DEFAULT_MKV_TOOL_NIX", SystemUtils.IS_OS_WINDOWS ? "C:\\Program Files\\MKVToolNix" : "/usr/bin/");
|
System.setProperty("DEFAULT_MKV_TOOL_NIX", SystemUtils.IS_OS_WINDOWS ? "C:\\Program Files\\MKVToolNix" : "/usr/bin/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static InputConfig getInstance() {
|
|
||||||
return getInstance(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InputConfig getInstance(boolean reset) {
|
|
||||||
if (config == null || reset) {
|
|
||||||
config = new InputConfig();
|
|
||||||
}
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setInstance(InputConfig c) {
|
|
||||||
config = c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get path to specific mkvtoolnix application.
|
* Get path to specific mkvtoolnix application.
|
||||||
* @return absolute path to desired application.
|
* @return absolute path to desired application.
|
||||||
|
|||||||
@@ -63,16 +63,15 @@ class FileFilterTest {
|
|||||||
when(file.getName()).thenReturn(List.of(path.split("/")).get(1));
|
when(file.getName()).thenReturn(List.of(path.split("/")).get(1));
|
||||||
when(file.toPath()).thenReturn(Path.of(TEST_FILE));
|
when(file.toPath()).thenReturn(Path.of(TEST_FILE));
|
||||||
|
|
||||||
InputConfig.getInstance(true).setIncludePattern(Pattern.compile(pattern));
|
|
||||||
long currentTime = System.currentTimeMillis();
|
long currentTime = System.currentTimeMillis();
|
||||||
InputConfig.getInstance().setFilterDate(new Date(currentTime + filterDateOffset));
|
FileFilter fileFilter = new FileFilter(Set.of(), Pattern.compile(pattern), new Date(currentTime + filterDateOffset));
|
||||||
|
|
||||||
try (MockedStatic<DateUtils> mockedFiles = Mockito.mockStatic(DateUtils.class)) {
|
try (MockedStatic<DateUtils> mockedFiles = Mockito.mockStatic(DateUtils.class)) {
|
||||||
mockedFiles
|
mockedFiles
|
||||||
.when(() -> DateUtils.convert(anyLong()))
|
.when(() -> DateUtils.convert(anyLong()))
|
||||||
.thenReturn(new Date(currentTime));
|
.thenReturn(new Date(currentTime));
|
||||||
|
|
||||||
assertEquals(expectedHit, FileFilter.accept(file, new HashSet<>(args)), "File is accepted");
|
assertEquals(expectedHit, fileFilter.accept(file, new HashSet<>(args)), "File is accepted");
|
||||||
assertEquals(total, ResultStatistic.getInstance().getTotal(), "Total files");
|
assertEquals(total, ResultStatistic.getInstance().getTotal(), "Total files");
|
||||||
assertEquals(excluded, ResultStatistic.getInstance().getExcluded(), "Excluded files");
|
assertEquals(excluded, ResultStatistic.getInstance().getExcluded(), "Excluded files");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors.MkvFileProcessor;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileInfo;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.InputConfig;
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.AttributeConfig;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.TrackAttributes;
|
||||||
import org.junit.jupiter.api.Disabled;
|
import org.junit.jupiter.api.Disabled;
|
||||||
@@ -11,7 +9,6 @@ import org.junit.jupiter.params.provider.Arguments;
|
|||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
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.*;
|
||||||
@@ -33,9 +30,8 @@ class MkvFileProcessorTest {
|
|||||||
@MethodSource
|
@MethodSource
|
||||||
@Disabled
|
@Disabled
|
||||||
void detectDesiredTracks(AttributeConfig expectedMatch, List<TrackAttributes> tracks, AttributeConfig... configs) {
|
void detectDesiredTracks(AttributeConfig expectedMatch, List<TrackAttributes> tracks, AttributeConfig... configs) {
|
||||||
InputConfig.getInstance().setPreferredSubtitles(Set.of());
|
|
||||||
FileInfo info = new FileInfo(null);
|
FileInfo info = new FileInfo(null);
|
||||||
MkvFileProcessor processor = new MkvFileProcessor();
|
// MkvFileProcessor processor = new MkvFileProcessor(null, new FileFilter());
|
||||||
// processor.detectDesiredTracks(info, tracks, tracks, configs);
|
// processor.detectDesiredTracks(info, tracks, tracks, configs);
|
||||||
assertEquals(expectedMatch.getAudioLanguage(), info.getMatchedConfig().getAudioLanguage());
|
assertEquals(expectedMatch.getAudioLanguage(), info.getMatchedConfig().getAudioLanguage());
|
||||||
assertEquals(expectedMatch.getSubtitleLanguage(), info.getMatchedConfig().getSubtitleLanguage());
|
assertEquals(expectedMatch.getSubtitleLanguage(), info.getMatchedConfig().getSubtitleLanguage());
|
||||||
|
|||||||
@@ -31,25 +31,25 @@ class InputConfigTest {
|
|||||||
"--commentary-keywords", "testCommentary",
|
"--commentary-keywords", "testCommentary",
|
||||||
"--preferred-subtitles", "testPreferred"
|
"--preferred-subtitles", "testPreferred"
|
||||||
};
|
};
|
||||||
CommandLine.populateCommand(InputConfig.getInstance(true), sut);
|
InputConfig config = CommandLine.populateCommand(new InputConfig(), sut);
|
||||||
|
|
||||||
assertTrue(InputConfig.getInstance().getLibraryPath().exists());
|
assertTrue(config.getLibraryPath().exists());
|
||||||
assertEquals(List.of(new AttributeConfig("ger", "ger"), new AttributeConfig("eng", "eng")),
|
assertEquals(List.of(new AttributeConfig("ger", "ger"), new AttributeConfig("eng", "eng")),
|
||||||
InputConfig.getInstance().getAttributeConfig());
|
config.getAttributeConfig());
|
||||||
|
|
||||||
assertTrue(InputConfig.getInstance().isSafeMode());
|
assertTrue(config.isSafeMode());
|
||||||
assertTrue(InputConfig.getInstance().isForceCoherent());
|
assertTrue(config.isForceCoherent());
|
||||||
assertTrue(InputConfig.getInstance().isOnlyNewFiles());
|
assertTrue(config.isOnlyNewFiles());
|
||||||
assertNull(InputConfig.getInstance().getFilterDate());
|
assertNull(config.getFilterDate());
|
||||||
|
|
||||||
assertEquals(2, InputConfig.getInstance().getCoherent());
|
assertEquals(2, config.getCoherent());
|
||||||
assertEquals(4, InputConfig.getInstance().getThreads());
|
assertEquals(4, config.getThreads());
|
||||||
assertEquals(".*[abc].*", InputConfig.getInstance().getIncludePattern().pattern());
|
assertEquals(".*[abc].*", config.getIncludePattern().pattern());
|
||||||
assertTrue(InputConfig.getInstance().getForcedKeywords().contains("testForced"));
|
assertTrue(config.getForcedKeywords().contains("testForced"));
|
||||||
assertTrue(InputConfig.getInstance().getCommentaryKeywords().contains("testCommentary"));
|
assertTrue(config.getCommentaryKeywords().contains("testCommentary"));
|
||||||
assertTrue(InputConfig.getInstance().getPreferredSubtitles().contains("testPreferred"));
|
assertTrue(config.getPreferredSubtitles().contains("testPreferred"));
|
||||||
|
|
||||||
assertNull(InputConfig.getInstance().getConfigPath());
|
assertNull(config.getConfigPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +66,6 @@ class InputConfigTest {
|
|||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("jakartaValidationData")
|
@MethodSource("jakartaValidationData")
|
||||||
void testJakartaValidation(String[] args, String expectedMessage) {
|
void testJakartaValidation(String[] args, String expectedMessage) {
|
||||||
InputConfig.getInstance(true);
|
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
PrintWriter printWriter = new PrintWriter(writer);
|
PrintWriter printWriter = new PrintWriter(writer);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user