mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-10 17:55:57 +01:00
Expand date filter by reading from last-execution.yml
This commit is contained in:
10
pom.xml
10
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>MKVAudioSubtileChanger</groupId>
|
<groupId>at.pcgamingfreaks</groupId>
|
||||||
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
<artifactId>MKVAudioSubtitleChanger</artifactId>
|
||||||
<version>3.0</version>
|
<version>3.0</version>
|
||||||
|
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<directory>./</directory>
|
<directory>./</directory>
|
||||||
<includes>
|
<includes>
|
||||||
<include>language-codes</include>
|
<include>language-codes</include>
|
||||||
<include>version.properties</include>
|
<include>project.properties</include>
|
||||||
</includes>
|
</includes>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
</resource>
|
</resource>
|
||||||
@@ -194,6 +194,12 @@
|
|||||||
<artifactId>YAML-Parser</artifactId>
|
<artifactId>YAML-Parser</artifactId>
|
||||||
<version>2.0-SNAPSHOT</version>
|
<version>2.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/net.harawata/appdirs -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.harawata</groupId>
|
||||||
|
<artifactId>appdirs</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
2
project.properties
Normal file
2
project.properties
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
version=${project.version}
|
||||||
|
project_name=${project.artifactId}
|
||||||
@@ -2,7 +2,7 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
|
|||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator.*;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator.*;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.VersionUtil;
|
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 org.apache.commons.cli.*;
|
import org.apache.commons.cli.*;
|
||||||
@@ -11,14 +11,17 @@ import java.io.IOException;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty.*;
|
||||||
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
import static at.pcgamingfreaks.mkvaudiosubtitlechanger.util.CommandLineOptionsUtil.optionOf;
|
||||||
|
|
||||||
public class ConfigLoader {
|
public class ConfigLoader {
|
||||||
private static final List<ConfigValidator<?>> VALIDATORS = List.of(
|
private static final List<ConfigValidator<?>> VALIDATORS = Stream.of(
|
||||||
new ConfigPathValidator(CONFIG_PATH, false),
|
new ConfigPathValidator(CONFIG_PATH, false),
|
||||||
new PathValidator(LIBRARY, true, null),
|
new PathValidator(LIBRARY, true, null),
|
||||||
new ThreadValidator(THREADS, false, 2),
|
new ThreadValidator(THREADS, false, 2),
|
||||||
@@ -34,7 +37,7 @@ public class ConfigLoader {
|
|||||||
new AttributeConfigValidator(),
|
new AttributeConfigValidator(),
|
||||||
new CoherentConfigValidator(COHERENT, false),
|
new CoherentConfigValidator(COHERENT, false),
|
||||||
new BooleanValidator(FORCE_COHERENT, false)
|
new BooleanValidator(FORCE_COHERENT, false)
|
||||||
);
|
).sorted(Comparator.comparing((ConfigValidator<?> validator) -> validator.getWeight()).reversed()).collect(Collectors.toList());
|
||||||
|
|
||||||
public static void initConfig(String[] args) {
|
public static void initConfig(String[] args) {
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
@@ -100,7 +103,7 @@ public class ConfigLoader {
|
|||||||
|
|
||||||
private static void exitIfVersion(CommandLine cmd) {
|
private static void exitIfVersion(CommandLine cmd) {
|
||||||
if (cmd.hasOption(VERSION.prop())) {
|
if (cmd.hasOption(VERSION.prop())) {
|
||||||
System.out.printf("MKV Audio Subtitle Changer Version %s%n", VersionUtil.getVersion());
|
System.out.printf("MKV Audio Subtitle Changer Version %s%n", ProjectUtil.getVersion());
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,9 @@ public class ConfigPathValidator extends PathValidator {
|
|||||||
protected boolean isValid(File result) {
|
protected boolean isValid(File result) {
|
||||||
return super.isValid(result) && (result.getAbsolutePath().endsWith(".yml") || result.getAbsolutePath().endsWith(".yaml"));
|
return super.isValid(result) && (result.getAbsolutePath().endsWith(".yml") || result.getAbsolutePath().endsWith(".yaml"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getWeight() {
|
||||||
|
return 100;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -154,11 +154,7 @@ public abstract class ConfigValidator<FieldType> {
|
|||||||
&& StringUtils.equalsIgnoreCase(method.getName().replace("get", ""), property.prop().replace("-", ""));
|
&& StringUtils.equalsIgnoreCase(method.getName().replace("get", ""), property.prop().replace("-", ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Set<Integer> getDependentValidators() {
|
public int getWeight() {
|
||||||
return Set.of();
|
return 50;
|
||||||
}
|
|
||||||
|
|
||||||
public static int getWeight() {
|
|
||||||
return getDependentValidators().stream().sorted().findFirst().orElse(100) - 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,21 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.config.validator;
|
|||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.Config;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.ConfigProperty;
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.DateUtils;
|
||||||
|
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
||||||
|
import at.pcgamingfreaks.yaml.YAML;
|
||||||
|
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.harawata.appdirs.AppDirsFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class DateValidator extends ConfigValidator<Date> {
|
public class DateValidator extends ConfigValidator<Date> {
|
||||||
private static final Date DEFAULT_DATE = new Date(0);
|
private static final Date INVALID_DATE = new Date(0);
|
||||||
|
private static final Date DEFAULT_DATE = new Date(1);
|
||||||
|
|
||||||
public DateValidator(ConfigProperty property, boolean required) {
|
public DateValidator(ConfigProperty property, boolean required) {
|
||||||
super(property, required, null);
|
super(property, required, null);
|
||||||
@@ -25,27 +30,32 @@ public class DateValidator extends ConfigValidator<Date> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Date overwriteValue() {
|
protected Date overwriteValue() {
|
||||||
Properties prop = new Properties();
|
|
||||||
try {
|
try {
|
||||||
prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/last-execution.properties"));
|
String filePath = AppDirsFactory.getInstance().getUserConfigDir(ProjectUtil.getProjectName(), null, null);
|
||||||
return parse(prop.getProperty(Config.getInstance().getLibraryPath().getAbsolutePath()));
|
File lastExecutionFile = Path.of(filePath + "/last-execution.yml").toFile();
|
||||||
} catch (IOException e) {
|
if (!lastExecutionFile.exists()) {
|
||||||
|
return DEFAULT_DATE;
|
||||||
|
}
|
||||||
|
YAML yaml = new YAML(lastExecutionFile);
|
||||||
|
return parse(yaml.getString(Config.getInstance().getLibraryPath().getAbsolutePath(), DateUtils.convert(DEFAULT_DATE)));
|
||||||
|
} catch (YamlInvalidContentException | IOException e) {
|
||||||
log.error("Couldn't open last-execution.properties");
|
log.error("Couldn't open last-execution.properties");
|
||||||
return DEFAULT_DATE;
|
return INVALID_DATE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Date parse(String value) {
|
Date parse(String value) {
|
||||||
return DateUtils.convert(value, DEFAULT_DATE);
|
return DateUtils.convert(value, INVALID_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
boolean isValid(Date result) {
|
boolean isValid(Date result) {
|
||||||
return !result.equals(DEFAULT_DATE);
|
return !result.equals(INVALID_DATE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Set<Integer> getDependentValidators() {
|
@Override
|
||||||
return Set.of(PathValidator.getWeight(), BooleanValidator.getWeight());
|
public int getWeight() {
|
||||||
|
return 40;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,4 +22,8 @@ public class DateUtils {
|
|||||||
return defaultDate;
|
return defaultDate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String convert(Date date) {
|
||||||
|
return dateFormat.format(date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class ProjectUtil {
|
||||||
|
private static final Properties PROJECT_PROPERTIES = new Properties();
|
||||||
|
|
||||||
|
static {
|
||||||
|
try (InputStream propertiesStream = ProjectUtil.class.getClassLoader().getResourceAsStream("project.properties")) {
|
||||||
|
PROJECT_PROPERTIES.load(propertiesStream);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return PROJECT_PROPERTIES.getProperty("version");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getProjectName() {
|
||||||
|
return PROJECT_PROPERTIES.getProperty("project_name");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger.util;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
public class VersionUtil {
|
|
||||||
public static String getVersion() {
|
|
||||||
try (InputStream propertiesStream = VersionUtil.class.getClassLoader().getResourceAsStream("version.properties")) {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
properties.load(propertiesStream);
|
|
||||||
|
|
||||||
return properties.getProperty("version");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new RuntimeException(e.getMessage());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
version=${project.version}
|
|
||||||
Reference in New Issue
Block a user