mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e80331beef | ||
|
|
a5fce22b95 | ||
|
|
a97ed89d08 | ||
|
|
cce84f5c15 | ||
|
|
ff38457af1 |
26
pom.xml
26
pom.xml
@@ -29,7 +29,7 @@
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>log4j2.yaml</include>
|
||||
<include>log4j2.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
@@ -64,7 +64,7 @@
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>log4j2-windows.yaml</include>
|
||||
<include>log4j2-windows.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
@@ -138,7 +138,7 @@
|
||||
<winShortcut>false</winShortcut>
|
||||
<winMenu>false</winMenu>
|
||||
<javaOptions>
|
||||
<javaOption>-Dlog4j2.configurationFile=log4j2-windows.yaml</javaOption>
|
||||
<javaOption>-Dlog4j2.configurationFile=log4j2-windows.yml</javaOption>
|
||||
</javaOptions>
|
||||
</configuration>
|
||||
<executions>
|
||||
@@ -161,7 +161,7 @@
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<includes>
|
||||
<include>log4j2-debian.yaml</include>
|
||||
<include>log4j2-debian.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
@@ -381,33 +381,33 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>3.0.0-beta2</version>
|
||||
<version>2.25.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>3.0.0-beta2</version>
|
||||
<version>2.25.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-slf4j2-impl -->
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j2-impl</artifactId>
|
||||
<version>3.0.0-beta2</version>
|
||||
<version>2.25.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/tools.jackson.dataformat/jackson-dataformat-yaml -->
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.dataformat/jackson-dataformat-yaml -->
|
||||
<dependency>
|
||||
<groupId>tools.jackson.dataformat</groupId>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/tools.jackson.core/jackson-databind -->
|
||||
<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind -->
|
||||
<dependency>
|
||||
<groupId>tools.jackson.core</groupId>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>3.0.3</version>
|
||||
<version>2.20.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-cli/commons-cli -->
|
||||
<dependency>
|
||||
|
||||
@@ -1 +1 @@
|
||||
java -Dlog4j2.configurationFile=log4j2-debian.yaml -jar /usr/lib/${project.artifactId}/${project.artifactId}-${project.version}.jar "$@"
|
||||
java -Dlog4j2.configurationFile=log4j2-debian.yml -jar /usr/lib/${project.artifactId}/${project.artifactId}-${project.version}.jar "$@"
|
||||
@@ -6,6 +6,10 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ProjectUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.core.LoggerContext;
|
||||
import org.apache.logging.log4j.core.appender.RollingFileAppender;
|
||||
import org.apache.logging.log4j.core.config.Configuration;
|
||||
import org.apache.logging.log4j.core.config.Configurator;
|
||||
import picocli.CommandLine;
|
||||
|
||||
@@ -39,7 +43,7 @@ public class CommandRunner implements Runnable {
|
||||
System.out.println("Safemode active. No files will be changed!");
|
||||
}
|
||||
|
||||
LastExecutionHandler lastExecutionHandler = config.isOnlyNewFiles() ? new LastExecutionHandler("./last-executions.yml") : null;
|
||||
LastExecutionHandler lastExecutionHandler = config.isOnlyNewFiles() ? new LastExecutionHandler(getApplicationHome()) : null;
|
||||
FileFilter fileFilter = new FileFilter(config.getExcluded(), config.getIncludePattern(), config.getFilterDate(), lastExecutionHandler);
|
||||
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());
|
||||
@@ -49,4 +53,21 @@ public class CommandRunner implements Runnable {
|
||||
: new SingleFileAttributeUpdater(config, fileProcessor, attributeChangeProcessor, lastExecutionHandler);
|
||||
kernel.execute();
|
||||
}
|
||||
|
||||
public String getApplicationHome() {
|
||||
LoggerContext context = (LoggerContext) LogManager.getContext(false);
|
||||
Configuration config = context.getConfiguration();
|
||||
|
||||
for (org.apache.logging.log4j.core.Appender appender : config.getAppenders().values()) {
|
||||
if (appender instanceof RollingFileAppender rollingFileAppender) {
|
||||
String fileName = rollingFileAppender.getFileName();
|
||||
return new java.io.File(fileName).getParentFile().getParent();
|
||||
}
|
||||
}
|
||||
|
||||
log.error("Could not load log4j2 path info");
|
||||
System.out.println("Could not load log4j2 path info");
|
||||
System.exit(1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@ import java.util.Properties;
|
||||
|
||||
@Slf4j
|
||||
public class LastExecutionHandler {
|
||||
private static final String FILE_NAME = "last-execution.properties";
|
||||
private final File file;
|
||||
private final Properties lastFileExecution;
|
||||
|
||||
public LastExecutionHandler(String path) {
|
||||
file = new File(path);
|
||||
file = new File(path + "/" + FILE_NAME);
|
||||
lastFileExecution = loadLastFileExecution(file);
|
||||
}
|
||||
|
||||
@@ -24,7 +25,7 @@ public class LastExecutionHandler {
|
||||
try (FileInputStream in = new FileInputStream(file)) {
|
||||
properties.load(in);
|
||||
} catch (IOException e) {
|
||||
log.warn("Couldn't find or read {}", file.getPath(), e);
|
||||
log.info("Couldn't find or read {}", file.getPath(), e);
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class AttributeUpdater {
|
||||
executor.awaitTermination(1, TimeUnit.DAYS);
|
||||
}
|
||||
|
||||
lastExecutionHandler.persist();
|
||||
if (lastExecutionHandler != null) lastExecutionHandler.persist();
|
||||
|
||||
statistic.stopTimer();
|
||||
statistic.print();
|
||||
|
||||
@@ -3,10 +3,10 @@ package at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.processors;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.exceptions.MkvToolNixException;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.impl.FileFilter;
|
||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.*;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
Configuration:
|
||||
name: DefaultLogger
|
||||
name: MainConfig
|
||||
|
||||
Properties:
|
||||
Property:
|
||||
- name: logDir
|
||||
value: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs
|
||||
- name: logPattern
|
||||
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
|
||||
Appenders:
|
||||
RollingFile:
|
||||
name: FileAppender
|
||||
fileName: logs/application.log
|
||||
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
fileName: ${logDir}/application.log
|
||||
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
PatternLayout:
|
||||
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
Pattern: logPattern
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
Policies:
|
||||
@@ -1,18 +1,25 @@
|
||||
Configuration:
|
||||
name: DefaultLogger
|
||||
|
||||
Properties:
|
||||
Property:
|
||||
- name: logDir
|
||||
value: "./logs"
|
||||
- name: log_pattern
|
||||
value: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||
|
||||
Appenders:
|
||||
Console:
|
||||
name: Console_Out
|
||||
PatternLayout:
|
||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||
Pattern: ${log_pattern}
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
RollingFile:
|
||||
name: FileAppender
|
||||
fileName: logs/application.log
|
||||
filePattern: logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
fileName: ${logDir}/application.log
|
||||
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
PatternLayout:
|
||||
Pattern: "%d{DEFAULT} | %-5level | %thread | %C{1} | %msg %n %throwable"
|
||||
Pattern: logPattern
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
Policies:
|
||||
@@ -1,12 +1,20 @@
|
||||
Configuration:
|
||||
name: DefaultLogger
|
||||
name: WindowsConfig
|
||||
|
||||
Properties:
|
||||
Property:
|
||||
- name: logDir
|
||||
value: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs
|
||||
- name: logPattern
|
||||
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
|
||||
Appenders:
|
||||
RollingFile:
|
||||
name: FileAppender
|
||||
fileName: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/application.log
|
||||
filePattern: ${sys:user.home}/.local/mkvaudiosubtitlechanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
fileName: ${logDir}/application.log
|
||||
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
PatternLayout:
|
||||
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
Pattern: logPattern
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
Policies:
|
||||
@@ -15,7 +23,7 @@ Configuration:
|
||||
DefaultRolloverStrategy:
|
||||
max: 30
|
||||
Delete:
|
||||
basePath: archive
|
||||
basePath: logs/archive
|
||||
maxDepth: 1
|
||||
IfLastModified:
|
||||
age: 30d
|
||||
@@ -1,12 +1,20 @@
|
||||
Configuration:
|
||||
name: DefaultLogger
|
||||
name: MainConfig
|
||||
|
||||
Properties:
|
||||
Property:
|
||||
- name: logDir
|
||||
value: ./logs
|
||||
- name: logPattern
|
||||
value: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
|
||||
Appenders:
|
||||
RollingFile:
|
||||
name: FileAppender
|
||||
fileName: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/application.log
|
||||
filePattern: ${sys:user.home}/AppData/Local/MKVAudioSubtitleChanger/logs/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
fileName: ${logDir}/application.log
|
||||
filePattern: ${logDir}/archive/application-%d{yyyy-MM-dd}-%i.log.gz
|
||||
PatternLayout:
|
||||
Pattern: "%d{DEFAULT} | %-5level | %msg %n %throwable"
|
||||
Pattern: logPattern
|
||||
ThresholdFilter:
|
||||
level: debug
|
||||
Policies:
|
||||
@@ -11,62 +11,63 @@ import java.time.Instant;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class LastExecutionHandlerTest {
|
||||
private static final String LAST_EXECUTION_YML = "./last-execution.properties";
|
||||
private static final String LAST_EXECUTION_PATH = ".";
|
||||
private static final String LAST_EXECUTION_FILE = "./last-execution.properties";
|
||||
private static final String TEST_MKV_FILE = "/arst/file.mkv";
|
||||
|
||||
@AfterEach
|
||||
void destruct() {
|
||||
File file = new File(LAST_EXECUTION_YML);
|
||||
File file = new File(LAST_EXECUTION_FILE);
|
||||
if (file.exists()) file.delete();
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingFile() throws IOException {
|
||||
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_YML);
|
||||
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_PATH);
|
||||
assertNull(underTest.get(TEST_MKV_FILE));
|
||||
underTest.update(TEST_MKV_FILE);
|
||||
assertNotNull(underTest.get(TEST_MKV_FILE));
|
||||
underTest.persist();
|
||||
File file = new File(LAST_EXECUTION_YML);
|
||||
File file = new File(LAST_EXECUTION_FILE);
|
||||
assertTrue(file.exists());
|
||||
assertTrue(Files.readString(file.toPath()).contains(TEST_MKV_FILE + "="));
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyFile() throws IOException {
|
||||
File file = new File(LAST_EXECUTION_YML);
|
||||
File file = new File(LAST_EXECUTION_FILE);
|
||||
file.createNewFile();
|
||||
missingFile(); // does the checks needed for empty file case
|
||||
}
|
||||
|
||||
@Test
|
||||
void existingFileNoChanges() throws IOException {
|
||||
File file = new File(LAST_EXECUTION_YML);
|
||||
File file = new File(LAST_EXECUTION_FILE);
|
||||
file.createNewFile();
|
||||
Files.writeString(file.toPath(), TEST_MKV_FILE + "=" + Instant.now());
|
||||
String expected = Files.readString(file.toPath()).replace(":", "\\:");
|
||||
|
||||
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_YML);
|
||||
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_PATH);
|
||||
assertNotNull(underTest.get(TEST_MKV_FILE));
|
||||
underTest.persist();
|
||||
File file1 = new File(LAST_EXECUTION_YML);
|
||||
File file1 = new File(LAST_EXECUTION_FILE);
|
||||
assertTrue(file1.exists());
|
||||
assertTrue(Files.readString(file.toPath()).contains(expected), "File contains expected value");
|
||||
}
|
||||
|
||||
@Test
|
||||
void existingFileWithChanges() throws IOException {
|
||||
File file = new File(LAST_EXECUTION_YML);
|
||||
File file = new File(LAST_EXECUTION_FILE);
|
||||
file.createNewFile();
|
||||
Files.writeString(file.toPath(), TEST_MKV_FILE + "=" + Instant.now());
|
||||
String expected = Files.readString(file.toPath());
|
||||
|
||||
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_YML);
|
||||
LastExecutionHandler underTest = new LastExecutionHandler(LAST_EXECUTION_PATH);
|
||||
assertNotNull(underTest.get(TEST_MKV_FILE));
|
||||
underTest.update(TEST_MKV_FILE);
|
||||
assertNotNull(underTest.get(TEST_MKV_FILE));
|
||||
underTest.persist();
|
||||
File file1 = new File(LAST_EXECUTION_YML);
|
||||
File file1 = new File(LAST_EXECUTION_FILE);
|
||||
assertTrue(file1.exists());
|
||||
assertNotEquals(expected, Files.readString(file.toPath()));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user