diff --git a/config.yaml b/config.yaml
index 9809263..8638af4 100644
--- a/config.yaml
+++ b/config.yaml
@@ -1,4 +1,6 @@
-mkvtoolnixPath: /usr/bin
+mkvtoolnixPath: C:\Program Files\MKVToolNix
+# Only edit this value if you know what you are doing, otherwise it may impact your performance negatively
+threadCount: 2
config:
1:
audio:
diff --git a/pom.xml b/pom.xml
index aaa762f..747b179 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
MKVAudioSubtilesChanger
MKVAudioSubtitlesChanger
- 1.0
+ 1.2
clean package
diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java
index 95a04c3..b030b48 100644
--- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java
+++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java
@@ -5,41 +5,57 @@ import at.pcgamingfreaks.mkvaudiosubtitlechanger.config.ConfigProcessor;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.intimpl.MkvFileCollector;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.util.ConfigUtil;
+import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import java.io.File;
-import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.*;
@Log4j2
public class AttributeUpdaterKernel {
MkvFileCollector collector = new MkvFileCollector();
+ int filesChangedAmount = 0;
+ int filesNotChangedAmount = 0;
+ long runtime = 0;
+ @SneakyThrows
public void execute(String path) {
List configPattern = ConfigUtil.loadConfig();
List allValidPaths = collector.loadFiles(path);
+ ExecutorService executor = Executors.newFixedThreadPool(ConfigUtil.getThreadCount());
+
+ long beforeTimer = System.currentTimeMillis();
if(allValidPaths != null && configPattern != null){
- for(File file : allValidPaths){
- List attributes = collector.loadAttributes(file);
- if (attributes.isEmpty()) {
- continue;
- }
- boolean fileHasChanged = false;
- for(AttributeConfig config : configPattern){
- /*
- * Creating new ArrayList, because the method removes elements from the list by reference
- */
- fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
- if(fileHasChanged){
- break;
- }
- }
- if(! fileHasChanged){
- log.info(file.getName() + " didn't change!");
- }
- }
+ System.out.print("Running");
+ allValidPaths.forEach(file -> executor.submit(() -> process(configPattern, file)));
}else{
log.error("Path is not valid or config has errors!");
}
+ executor.shutdown();
+ executor.awaitTermination(1, TimeUnit.DAYS);
+ runtime = System.currentTimeMillis() - beforeTimer;
+
+ System.out.printf("%nFiles changed: %s%n", filesChangedAmount);
+ System.out.printf("Files not changed: %s%n", filesNotChangedAmount);
+ System.out.printf("Runtime: %ss%n", runtime / 1000);
+ }
+
+ private void process(List configPattern, File file) {
+ List attributes = collector.loadAttributes(file);
+ boolean fileHasChanged = false;
+
+ if (attributes.isEmpty()) return;
+ for(AttributeConfig config : configPattern){
+ fileHasChanged = new ConfigProcessor(config).processConfig(file, attributes);
+ if(fileHasChanged) break;
+ }
+ if(!fileHasChanged){
+ log.info("File didn't change: {}", file.getName());
+ filesNotChangedAmount++;
+ } else {
+ filesChangedAmount++;
+ }
+ System.out.print(".");
}
}
diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/config/ConfigProcessor.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/config/ConfigProcessor.java
index 9e226bc..137adf2 100644
--- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/config/ConfigProcessor.java
+++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/config/ConfigProcessor.java
@@ -8,6 +8,7 @@ import lombok.extern.log4j.Log4j2;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -31,10 +32,11 @@ public class ConfigProcessor {
public boolean processConfig(File file, List attributes) {
// check if size is bigger or equal 2 to make sure that there is at least one audio and subtitle line
// TODO: implement empty audio or subtitle line
- if(attributes.size() >= 2){
- TransferObject transfer = filterAttributes(attributes);
- if(! attributes.isEmpty()){
- return updateFile(file, attributes, transfer);
+ List attributesCopy = new ArrayList<>(attributes);
+ if(attributesCopy.size() >= 2){
+ TransferObject transfer = filterAttributes(attributesCopy);
+ if(! attributesCopy.isEmpty()){
+ return updateFile(file, attributesCopy, transfer);
}
}
return false;
@@ -112,7 +114,7 @@ public class ConfigProcessor {
* In this case the file would be change to the exact same audio and subtitle lines and we want to
* avoid unnecessary changes to the file
*/
- log.info(file.getName() + " already fits config!");
+ log.info("File already fits config: {}", file.getName());
return true;
}
try{
@@ -124,7 +126,7 @@ public class ConfigProcessor {
* We return true even if there was an error. If there was an error, the chances that this file is still
* busy later.
*/
- log.info(file.getName() + " was updated");
+ log.info("Updated {}", file.getName());
return true;
}else{
return false;
diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/ConfigUtil.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/ConfigUtil.java
index d2192bd..6aa7956 100644
--- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/ConfigUtil.java
+++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/util/ConfigUtil.java
@@ -37,4 +37,15 @@ public class ConfigUtil {
return null;
}
}
+
+ public static int getThreadCount() {
+ try {
+ return Integer.parseInt(new YAML(new File("config.yaml")).getString("threadCount"));
+ } catch (YamlInvalidContentException | IOException e) {
+ e.printStackTrace();
+ } catch (YamlKeyNotFoundException e) {
+ throw new RuntimeException(e);
+ }
+ return 1;
+ }
}
diff --git a/src/main/resources/log4j2.yaml b/src/main/resources/log4j2.yaml
index 6355c6c..14026cc 100644
--- a/src/main/resources/log4j2.yaml
+++ b/src/main/resources/log4j2.yaml
@@ -1,12 +1,6 @@
Configuration:
name: DefaultLogger
Appenders:
- Console:
- name: Console_Out
- PatternLayout:
- Pattern: "%d{DEFAULT} | %-5level | %thread | %msg %n %throwable"
- ThresholdFilter:
- level: debug
File:
name: FileAppender
fileName: default.log
@@ -18,11 +12,9 @@ Configuration:
Root:
level: debug
AppenderRef:
- - ref: Console_Out
- ref: FileAppender
Logger:
name: "com.zaxxer.hikari.HikariConfig"
level: info
AppenderRef:
- - ref: Console_Out
- ref: FileAppender
\ No newline at end of file