diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/java/GUI.form b/src/main/java/GUI.form
deleted file mode 100644
index 94c37be..0000000
--- a/src/main/java/GUI.form
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
diff --git a/src/main/java/GUI.java b/src/main/java/GUI.java
deleted file mode 100644
index b544f49..0000000
--- a/src/main/java/GUI.java
+++ /dev/null
@@ -1,90 +0,0 @@
-import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
-import lombok.extern.log4j.Log4j2;
-import query.QueryBuilder;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.io.*;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-@Log4j2
-public class GUI {
- private String path;
- private JButton openFileBrowser;
- private JButton startOperation;
-
- public GUI() {
- JFrame frame = new JFrame();
- frame.setLayout(new BorderLayout());
- frame.setTitle("MKV Audio and Subtitle Changer");
- frame.setSize(500, 75);
- frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
-
- JPanel top = new JPanel(new GridLayout(1, 2, 20, 20));
-
- openFileBrowser = new JButton("Browse directory");
- openFileBrowser.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- JFileChooser fileChooser = new JFileChooser();
- try{
- if(! readFile("lastDir", Charset.defaultCharset()).isEmpty()){
- String temp = readFile("lastDir", Charset.defaultCharset());
- fileChooser.setCurrentDirectory(new File(temp));
- }
- }catch(IOException ie){
- log.info("Couldn't start FileChooser with default path");
- }
- fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
- fileChooser.setMultiSelectionEnabled(false);
- fileChooser.setPreferredSize(new Dimension(600, 500));
- Action details = fileChooser.getActionMap().get("viewTypeDetails");
- details.actionPerformed(null);
- fileChooser.showOpenDialog(null);
- try{
- if(FileAttribute.pathIsValid(fileChooser.getSelectedFile().getAbsolutePath())){
- path = fileChooser.getSelectedFile().getAbsolutePath();
- try(PrintWriter out = new PrintWriter("lastDir", "UTF-8")){
- out.print(fileChooser.getCurrentDirectory());
- }catch(FileNotFoundException | UnsupportedEncodingException fne){
- log.error(fne);
- }
- startOperation.setEnabled(true);
- }
- }catch(NullPointerException ne){
- System.out.println("File or directory not found!");
- log.error("File or directory not found!", ne);
- }
- }
- });
-
- startOperation = new JButton("Start updating");
- startOperation.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- QueryBuilder queryBuilder = new QueryBuilder();
- if(queryBuilder.executeUpdateOnAllFiles(path)){
- log.info("All files updated!");
- System.out.println("All files updated!");
- }
- }
- });
- startOperation.setEnabled(false);
-
- top.add(openFileBrowser);
- top.add(startOperation);
-
- frame.add(top, BorderLayout.NORTH);
-
- frame.setVisible(true);
- }
-
- static String readFile(String path, Charset encoding) throws IOException {
- byte[] encoded = Files.readAllBytes(Paths.get(path));
- return new String(encoded, encoding);
- }
-}
diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java
index 62c44d2..9c1f5ef 100644
--- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java
+++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java
@@ -10,36 +10,29 @@ import lombok.extern.log4j.Log4j2;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
-import java.util.Scanner;
@Log4j2
public class AttributeUpdaterKernel {
MkvFileCollector collector = new MkvFileCollector();
- public void execute() {
+ public void execute(String path) {
List configPattern = ConfigUtil.loadConfig();
- List allValidPaths = null;
- try(Scanner scanner = new Scanner(System.in)){
- System.out.println("Please enter the path to the files which should be updated: ");
- do{
- allValidPaths = collector.loadFiles(scanner.nextLine());
- if(allValidPaths == null){
- System.out.println("Please enter a valid path: ");
- }
- }while(allValidPaths == null);
- log.info(allValidPaths.size() + " files where found and will now be processed!");
- }
- for(File file : allValidPaths){
- List attributes = collector.loadAttributes(file);
- for(AttributeConfig config : configPattern){
- /*
- * Creating new ArrayList, because the method removes elements from the list by reference
- */
- boolean fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
- if(fileHasChanged){
- break;
+ List allValidPaths = collector.loadFiles(path);
+ if(! allValidPaths.isEmpty()){
+ for(File file : allValidPaths){
+ List attributes = collector.loadAttributes(file);
+ for(AttributeConfig config : configPattern){
+ /*
+ * Creating new ArrayList, because the method removes elements from the list by reference
+ */
+ boolean fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
+ if(fileHasChanged){
+ break;
+ }
}
}
+ }else{
+ log.error("Path is not valid!");
}
}
}
diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/MKVToolProperties.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/MKVToolProperties.java
index 4319234..14618ee 100644
--- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/MKVToolProperties.java
+++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/MKVToolProperties.java
@@ -1,19 +1,13 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
import lombok.Getter;
+import lombok.Setter;
import lombok.extern.log4j.Log4j2;
-import java.io.*;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.Scanner;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
@Log4j2
@Getter
+@Setter
public class MKVToolProperties {
- private String directoryPath;
private String mkvmergePath;
private String mkvpropeditPath;
@@ -28,67 +22,4 @@ public class MKVToolProperties {
}
return instance;
}
-
- public void defineMKVToolNixPath() {
- if(searchWithFilePath() && pathIsValid()){
- log.info("MKVToolNix found!");
- return;
- }
- log.debug("MKVToolNix not found in file!");
- searchInDefaultPath();
- if(pathIsValid()){
- log.info("MKVToolNix found!");
- return;
- }
- log.debug("MKVToolNix not found in default path!");
- Scanner input = new Scanner(System.in);
- while(true){
- searchWithUserPath(input);
- if(pathIsValid()){
- break;
- }
- }
- try(PrintWriter writer = new PrintWriter("mkvDirectoryPath", "UTF-8")){
- writer.println(directoryPath);
- }catch(UnsupportedEncodingException | FileNotFoundException e){
- log.error("File counldn't be written!");
- }
- log.info("MKVToolNix found!");
- }
-
- private boolean pathIsValid() {
- checkForSeparator();
- setMKVmergeAndPropEditPath();
- return new File(mkvmergePath).exists() && new File(mkvpropeditPath).exists();
- }
-
- private void checkForSeparator() {
- if(! (directoryPath.endsWith("/") || (directoryPath.endsWith("\\") && System.getProperty("os.name").toLowerCase().contains("windows")))){
- directoryPath += File.separator;
- }
- }
-
- private void setMKVmergeAndPropEditPath() {
- mkvmergePath = directoryPath + "mkvmerge.exe";
- mkvpropeditPath = directoryPath + "mkvpropedit.exe";
- }
-
- private boolean searchWithFilePath() {
- try(Stream stream = Files.lines(Paths.get("mkvDirectoryPath"))){
- directoryPath = stream.collect(Collectors.joining("\n"));
- }catch(IOException e){
- log.fatal(e.getMessage());
- return false;
- }
- return true;
- }
-
- private void searchInDefaultPath() {
- directoryPath = "C:\\Program Files\\MKVToolNix";
- }
-
- private void searchWithUserPath(Scanner input) {
- log.info("Please enter the path to the directory of MKVToolNix:");
- directoryPath = input.nextLine();
- }
}
diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/Main.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/Main.java
index 926d9d3..0509f99 100644
--- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/Main.java
+++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/Main.java
@@ -1,9 +1,32 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
+import at.pcgamingfreaks.yaml.YAML;
+import at.pcgamingfreaks.yaml.YamlInvalidContentException;
+import at.pcgamingfreaks.yaml.YamlKeyNotFoundException;
+import lombok.extern.log4j.Log4j2;
+
+import java.io.File;
+import java.io.IOException;
+
+@Log4j2
public class Main {
public static void main(String[] args) {
- MKVToolProperties.getInstance().defineMKVToolNixPath();
- AttributeUpdaterKernel kernel = new AttributeUpdaterKernel();
- kernel.execute();
+ if(checkIfMKVToolNixIsValid()){
+ AttributeUpdaterKernel kernel = new AttributeUpdaterKernel();
+ kernel.execute(args[0]);
+ }else{
+ log.error("MKVToolNix was not found! Please recheck path");
+ }
+ }
+
+ private static boolean checkIfMKVToolNixIsValid() {
+ try{
+ String path = new YAML(new File("config.yml")).getString("mkvtoolnixPath");
+ MKVToolProperties.getInstance().setMkvmergePath(path + "mkvmerge");
+ MKVToolProperties.getInstance().setMkvpropeditPath(path + "mkvproperties");
+ }catch(YamlKeyNotFoundException | IOException | YamlInvalidContentException e){
+ e.printStackTrace();
+ }
+ return new File(MKVToolProperties.getInstance().getMkvmergePath()).isFile() && new File(MKVToolProperties.getInstance().getMkvpropeditPath()).isFile();
}
}
diff --git a/src/main/java/config/CustomOutputStream.java b/src/main/java/config/CustomOutputStream.java
deleted file mode 100644
index f6d5db2..0000000
--- a/src/main/java/config/CustomOutputStream.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package config;
-
-import javax.swing.*;
-import java.io.IOException;
-import java.io.OutputStream;
-
-public class CustomOutputStream extends OutputStream {
- private JTextArea textArea;
-
- public CustomOutputStream(JTextArea textArea) {
- this.textArea = textArea;
- }
-
- @Override
- public void write(int b) throws IOException {
- // redirects data to the text area
- textArea.append(String.valueOf((char) b));
- // scrolls the text area to the end of data
- textArea.setCaretPosition(textArea.getDocument().getLength());
- }
-}
diff --git a/src/main/java/query/QueryBuilder.java b/src/main/java/query/QueryBuilder.java
deleted file mode 100644
index dd51991..0000000
--- a/src/main/java/query/QueryBuilder.java
+++ /dev/null
@@ -1,160 +0,0 @@
-package query;
-
-import at.pcgamingfreaks.mkvaudiosubtitlechanger.MKVToolProperties;
-import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
-import at.pcgamingfreaks.yaml.YAML;
-import at.pcgamingfreaks.yaml.YamlInvalidContentException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import lombok.extern.log4j.Log4j2;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-@Log4j2
-public class QueryBuilder {
- private final ObjectMapper mapper = new ObjectMapper();
-
- public QueryBuilder() {
- }
-
- public boolean executeUpdateOnAllFiles(String path) {
- List allFilePaths = getAllFilesFromDirectory(path);
- if(allFilePaths == null){
- log.error("Couldn't process path!");
- return false;
- }
- for(String filePath : allFilePaths){
- updateAttributes(filePath, queryAttributes(filePath));
- }
- return true;
- }
-
- private List getAllFilesFromDirectory(String path) {
- try(Stream paths = Files.walk(Paths.get(path))){
- return paths
- .filter(Files::isRegularFile)
- .map(file -> file.toAbsolutePath().toString())
- .collect(Collectors.toList());
- }catch(IOException e){
- log.error("Couldn't find file or directory!", e);
- }
- return null;
- }
-
- private List queryAttributes(String path) {
- Map jsonMap;
- List fileAttributes = new ArrayList<>();
- try(InputStream inputStream = Runtime.getRuntime().exec("\"" + MKVToolProperties.getInstance().getMkvmergePath() + "\" --identify --identification-format json \"" + path + "\"").getInputStream()){
- jsonMap = mapper.readValue(inputStream, Map.class);
- List