From 5c37fc6842f04cbc419f3509a1604e8cc1fbb66d Mon Sep 17 00:00:00 2001 From: RatzzFatzz Date: Tue, 11 Feb 2020 19:58:27 +0100 Subject: [PATCH 1/5] [IMPL] path supports dir and files now --- src/main/java/GUI.java | 15 +++++++++----- src/main/java/config/CustomOutputStream.java | 21 ++++++++++++++++++++ src/main/java/query/QueryBuilder.java | 5 +++-- 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 src/main/java/config/CustomOutputStream.java diff --git a/src/main/java/GUI.java b/src/main/java/GUI.java index 92caeee..f8b61f7 100644 --- a/src/main/java/GUI.java +++ b/src/main/java/GUI.java @@ -1,3 +1,4 @@ +import config.CustomOutputStream; import lombok.extern.log4j.Log4j2; import model.FileAttribute; import query.QueryBuilder; @@ -17,7 +18,7 @@ public class GUI { private JButton openFileBrowser; private JButton startOperation; private JButton openProperties; - private JTextPane outputArea; + private JTextArea outputArea; public GUI() { JFrame frame = new JFrame(); @@ -28,7 +29,10 @@ public class GUI { JPanel top = new JPanel(new GridLayout(1, 3, 20, 20)); - outputArea = new JTextPane(); + outputArea = new JTextArea(); + PrintStream printStream = new PrintStream(new CustomOutputStream(outputArea)); + System.setOut(printStream); + System.setErr(printStream); outputArea.setEditable(false); openFileBrowser = new JButton("Browse directory"); @@ -38,7 +42,7 @@ public class GUI { JFileChooser fileChooser = new JFileChooser(); try{ if(! readFile("lastDir", Charset.defaultCharset()).isEmpty()){ - String temp = readFile("dir.txt", Charset.defaultCharset()); + String temp = readFile("lastDir", Charset.defaultCharset()); fileChooser.setCurrentDirectory(new File(temp)); } }catch(IOException ie){ @@ -61,7 +65,7 @@ public class GUI { startOperation.setEnabled(true); } }catch(NullPointerException ne){ - outputArea.setText("File or directory not found!\n" + (outputArea.getText() == null ? "" : outputArea.getText())); + System.out.println("File or directory not found!"); log.error("File or directory not found!", ne); } } @@ -76,7 +80,8 @@ public class GUI { public void actionPerformed(ActionEvent e) { QueryBuilder queryBuilder = new QueryBuilder(); if(queryBuilder.executeUpdateOnAllFiles(path, outputArea)){ - outputArea.setText("All files updated!\n" + (outputArea.getText() == null ? "" : outputArea.getText())); + log.info("All files updated!"); + System.out.println("All files updated!"); } } }); diff --git a/src/main/java/config/CustomOutputStream.java b/src/main/java/config/CustomOutputStream.java new file mode 100644 index 0000000..f6d5db2 --- /dev/null +++ b/src/main/java/config/CustomOutputStream.java @@ -0,0 +1,21 @@ +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 index a0d1521..33c66c1 100644 --- a/src/main/java/query/QueryBuilder.java +++ b/src/main/java/query/QueryBuilder.java @@ -24,7 +24,7 @@ public class QueryBuilder { public QueryBuilder() { } - public boolean executeUpdateOnAllFiles(String path, JTextPane outputArea) { + public boolean executeUpdateOnAllFiles(String path, JTextArea outputArea) { List allFilePaths = getAllFilesFromDirectory(path); if(allFilePaths == null){ log.error("Couldn't process path!"); @@ -32,7 +32,8 @@ public class QueryBuilder { } for(String filePath : allFilePaths){ updateAttributes(filePath, queryAttributes(filePath)); - outputArea.setText("Success: " + filePath + "\n" + outputArea.getPage()); + log.info("Success: " + filePath); + System.out.println("Success: " + filePath); } return true; } From 3ac30e06837ffc98ff8ece265e62ba92c60ae106 Mon Sep 17 00:00:00 2001 From: RatzzFatzz Date: Wed, 12 Feb 2020 22:34:51 +0100 Subject: [PATCH 2/5] [IMPL] config file implemented --- pom.xml | 11 ++++ src/main/java/query/QueryBuilder.java | 75 ++++++++++++++++++++------- src/main/resources/config.yaml | 7 +++ 3 files changed, 74 insertions(+), 19 deletions(-) create mode 100644 src/main/resources/config.yaml diff --git a/pom.xml b/pom.xml index 09e2baa..2250ae8 100644 --- a/pom.xml +++ b/pom.xml @@ -93,6 +93,12 @@ + + + pcgf-repo + https://repo.pcgamingfreaks.at/repository/maven-everything/ + + @@ -170,6 +176,11 @@ test + + at.pcgamingfreaks + YAML-Parser + 2.0-SNAPSHOT + \ No newline at end of file diff --git a/src/main/java/query/QueryBuilder.java b/src/main/java/query/QueryBuilder.java index 33c66c1..6e340f6 100644 --- a/src/main/java/query/QueryBuilder.java +++ b/src/main/java/query/QueryBuilder.java @@ -1,11 +1,14 @@ package query; +import at.pcgamingfreaks.yaml.YAML; +import at.pcgamingfreaks.yaml.YamlInvalidContentException; import com.fasterxml.jackson.databind.ObjectMapper; import config.MKVToolProperties; import lombok.extern.log4j.Log4j2; import model.FileAttribute; import javax.swing.*; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; @@ -76,32 +79,66 @@ public class QueryBuilder { } private void updateAttributes(String path, List fileAttributes) { - if(fileAttributes.size() > 2){ - StringBuffer stringBuffer = new StringBuffer("\""); - stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath()); - stringBuffer.append("\" \""); - stringBuffer.append(path); - stringBuffer.append("\" "); - int c = 0; - int d = 0; + YAML yaml; + List subtitles = null; + List audios = null; - for(FileAttribute attributes : fileAttributes){ - if(attributes.isDefaultTrack() && "audio".equals(attributes.getType())){ - stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=0 "); + try{ + yaml = new YAML(new File("src/main/resources/config.yaml")); + subtitles = yaml.getStringList("subtitle", null); + audios = yaml.getStringList("audio", null); + }catch(YamlInvalidContentException | IOException e){ + log.error(e.getMessage()); + } + + if(fileAttributes.size() > 2 && subtitles != null && audios != null){ + + + int oldAudioDefault = - 1; + int oldSubtitleDefault = - 1; + int audioDefault = - 1; + int subtitleDefault = - 1; + int subtitleIndex = - 1; + int audioIndex = - 1; + + for(FileAttribute attribute : fileAttributes){ + if(subtitles.contains(attribute.getLanguage()) && "subtitles".equals(attribute.getType())){ + for(int i = 0; i < subtitles.size(); i++){ + if(subtitles.get(i).equals(attribute.getLanguage())){ + if(subtitleIndex == - 1 || i < subtitleIndex){ + subtitleIndex = i; + subtitleDefault = attribute.getId(); + } + } + } } - if(attributes.isDefaultTrack() && "subtitles".equals(attributes.getType())){ - stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=0 "); + if(audios.contains(attribute.getLanguage()) && "audio".equals(attribute.getType())){ + for(int i = 0; i < audios.size(); i++){ + if(audios.get(i).equals(attribute.getLanguage())){ + if(audioIndex == - 1 || i < audioIndex){ + audioIndex = i; + audioDefault = attribute.getId(); + } + } + } } - if("jpn".equals(attributes.getLanguage()) && "audio".equals(attributes.getType()) && c == 0){ - c++; - stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=1 "); + + if(attribute.isDefaultTrack() && "audio".equals(attribute.getType())){ + oldAudioDefault = attribute.getId(); } - if("eng".equals(attributes.getLanguage()) && "subtitles".equals(attributes.getType()) && d == 0){ - d++; - stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=1 "); + if(attribute.isDefaultTrack() && "subtitles".equals(attribute.getType())){ + oldSubtitleDefault = attribute.getId(); } } + StringBuilder stringBuffer = new StringBuilder("\""); + stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath()); + stringBuffer.append("\" \"").append(path).append("\" "); + stringBuffer.append("--edit track:").append(oldSubtitleDefault).append(" --set flag-default=0 "); + stringBuffer.append("--edit track:").append(oldAudioDefault).append(" --set flag-default=0 "); + stringBuffer.append("--edit track:").append(subtitleDefault).append(" --set flag-default=1 "); + stringBuffer.append("--edit track:").append(audioDefault).append(" --set flag-default=1 "); + try{ Runtime.getRuntime().exec(stringBuffer.toString()); }catch(IOException e){ diff --git a/src/main/resources/config.yaml b/src/main/resources/config.yaml new file mode 100644 index 0000000..341f395 --- /dev/null +++ b/src/main/resources/config.yaml @@ -0,0 +1,7 @@ +audio: + - jpn + - ger + - eng +subtitle: + - ger + - eng \ No newline at end of file From 4dff50f13a9bed8cb681ab664274db0e243126b6 Mon Sep 17 00:00:00 2001 From: RatzzFatzz Date: Fri, 14 Feb 2020 21:41:49 +0100 Subject: [PATCH 3/5] [IMPL] config file implemented --- src/main/java/GUI.java | 3 + src/main/java/query/QueryBuilder.java | 118 +++++++++++++------------- src/main/resources/config.yaml | 4 +- 3 files changed, 65 insertions(+), 60 deletions(-) diff --git a/src/main/java/GUI.java b/src/main/java/GUI.java index f8b61f7..d4b7c15 100644 --- a/src/main/java/GUI.java +++ b/src/main/java/GUI.java @@ -4,6 +4,7 @@ import model.FileAttribute; import query.QueryBuilder; import javax.swing.*; +import javax.swing.text.DefaultCaret; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -30,6 +31,8 @@ public class GUI { JPanel top = new JPanel(new GridLayout(1, 3, 20, 20)); outputArea = new JTextArea(); + DefaultCaret caret = (DefaultCaret) outputArea.getCaret(); + caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); PrintStream printStream = new PrintStream(new CustomOutputStream(outputArea)); System.setOut(printStream); System.setErr(printStream); diff --git a/src/main/java/query/QueryBuilder.java b/src/main/java/query/QueryBuilder.java index 6e340f6..c10cea0 100644 --- a/src/main/java/query/QueryBuilder.java +++ b/src/main/java/query/QueryBuilder.java @@ -85,68 +85,70 @@ public class QueryBuilder { List audios = null; try{ - yaml = new YAML(new File("src/main/resources/config.yaml")); + yaml = new YAML(new File("config.yaml")); subtitles = yaml.getStringList("subtitle", null); audios = yaml.getStringList("audio", null); + + + if(fileAttributes.size() > 2 && subtitles != null && audios != null){ + + + int oldAudioDefault = - 1; + int oldSubtitleDefault = - 1; + int audioDefault = - 1; + int subtitleDefault = - 1; + int subtitleIndex = - 1; + int audioIndex = - 1; + + for(FileAttribute attribute : fileAttributes){ + if(subtitles.contains(attribute.getLanguage()) && "subtitles".equals(attribute.getType())){ + for(int i = 0; i < subtitles.size(); i++){ + if(subtitles.get(i).equals(attribute.getLanguage())){ + if(subtitleIndex == - 1 || i < subtitleIndex){ + subtitleIndex = i; + subtitleDefault = attribute.getId(); + } + } + } + } + if(audios.contains(attribute.getLanguage()) && "audio".equals(attribute.getType())){ + for(int i = 0; i < audios.size(); i++){ + if(audios.get(i).equals(attribute.getLanguage())){ + if(audioIndex == - 1 || i < audioIndex){ + audioIndex = i; + audioDefault = attribute.getId(); + } + } + } + } + + if(attribute.isDefaultTrack() && "audio".equals(attribute.getType())){ + oldAudioDefault = attribute.getId(); + } + if(attribute.isDefaultTrack() && "subtitles".equals(attribute.getType())){ + oldSubtitleDefault = attribute.getId(); + } + } + StringBuilder stringBuffer = new StringBuilder("\""); + stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath()); + stringBuffer.append("\" \"").append(path).append("\" "); + stringBuffer.append("--edit track:").append(oldSubtitleDefault).append(" --set flag-default=0 "); + stringBuffer.append("--edit track:").append(oldAudioDefault).append(" --set flag-default=0 "); + stringBuffer.append("--edit track:").append(subtitleDefault).append(" --set flag-default=1 "); + stringBuffer.append("--edit track:").append(audioDefault).append(" --set flag-default=1 "); + + try{ + Runtime.getRuntime().exec(stringBuffer.toString()); + }catch(IOException e){ + log.error("Couldn't make changes to file"); + + } + + }else{ + log.info("There were not enough lines provided to make any changes to the file"); + } }catch(YamlInvalidContentException | IOException e){ log.error(e.getMessage()); } - - if(fileAttributes.size() > 2 && subtitles != null && audios != null){ - - - int oldAudioDefault = - 1; - int oldSubtitleDefault = - 1; - int audioDefault = - 1; - int subtitleDefault = - 1; - int subtitleIndex = - 1; - int audioIndex = - 1; - - for(FileAttribute attribute : fileAttributes){ - if(subtitles.contains(attribute.getLanguage()) && "subtitles".equals(attribute.getType())){ - for(int i = 0; i < subtitles.size(); i++){ - if(subtitles.get(i).equals(attribute.getLanguage())){ - if(subtitleIndex == - 1 || i < subtitleIndex){ - subtitleIndex = i; - subtitleDefault = attribute.getId(); - } - } - } - } - if(audios.contains(attribute.getLanguage()) && "audio".equals(attribute.getType())){ - for(int i = 0; i < audios.size(); i++){ - if(audios.get(i).equals(attribute.getLanguage())){ - if(audioIndex == - 1 || i < audioIndex){ - audioIndex = i; - audioDefault = attribute.getId(); - } - } - } - } - - if(attribute.isDefaultTrack() && "audio".equals(attribute.getType())){ - oldAudioDefault = attribute.getId(); - } - if(attribute.isDefaultTrack() && "subtitles".equals(attribute.getType())){ - oldSubtitleDefault = attribute.getId(); - } - } - StringBuilder stringBuffer = new StringBuilder("\""); - stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath()); - stringBuffer.append("\" \"").append(path).append("\" "); - stringBuffer.append("--edit track:").append(oldSubtitleDefault).append(" --set flag-default=0 "); - stringBuffer.append("--edit track:").append(oldAudioDefault).append(" --set flag-default=0 "); - stringBuffer.append("--edit track:").append(subtitleDefault).append(" --set flag-default=1 "); - stringBuffer.append("--edit track:").append(audioDefault).append(" --set flag-default=1 "); - - try{ - Runtime.getRuntime().exec(stringBuffer.toString()); - }catch(IOException e){ - log.error("Couldn't make changes to file"); - - } - }else{ - log.info("There were not enough lines provided to make any changes to the file"); - } } } diff --git a/src/main/resources/config.yaml b/src/main/resources/config.yaml index 341f395..c709d2b 100644 --- a/src/main/resources/config.yaml +++ b/src/main/resources/config.yaml @@ -3,5 +3,5 @@ audio: - ger - eng subtitle: - - ger - - eng \ No newline at end of file + - eng + - ger \ No newline at end of file From 7639cb8b077d985b73f524062f8ccf5630f0200e Mon Sep 17 00:00:00 2001 From: RatzzFatzz Date: Fri, 14 Feb 2020 22:37:54 +0100 Subject: [PATCH 4/5] [IMPROVE] querying --- pom.xml | 18 ------------------ src/main/java/GUI.java | 23 +++-------------------- src/main/java/query/QueryBuilder.java | 16 +++++++++++----- src/main/resources/config.yaml | 4 ++-- 4 files changed, 16 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 2250ae8..1644228 100644 --- a/pom.xml +++ b/pom.xml @@ -72,24 +72,6 @@ maven-surefire-plugin 2.22.2 - - org.codehaus.mojo - ideauidesigner-maven-plugin - 1.0-beta-1 - - - - javac2 - - - - - - true - true - true - - diff --git a/src/main/java/GUI.java b/src/main/java/GUI.java index d4b7c15..de27d21 100644 --- a/src/main/java/GUI.java +++ b/src/main/java/GUI.java @@ -1,10 +1,8 @@ -import config.CustomOutputStream; import lombok.extern.log4j.Log4j2; import model.FileAttribute; import query.QueryBuilder; import javax.swing.*; -import javax.swing.text.DefaultCaret; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; @@ -18,25 +16,15 @@ public class GUI { private String path; private JButton openFileBrowser; private JButton startOperation; - private JButton openProperties; - private JTextArea outputArea; public GUI() { JFrame frame = new JFrame(); frame.setLayout(new BorderLayout()); frame.setTitle("MKV Audio and Subtitle Changer"); - frame.setSize(500, 300); + frame.setSize(500, 75); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); - JPanel top = new JPanel(new GridLayout(1, 3, 20, 20)); - - outputArea = new JTextArea(); - DefaultCaret caret = (DefaultCaret) outputArea.getCaret(); - caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); - PrintStream printStream = new PrintStream(new CustomOutputStream(outputArea)); - System.setOut(printStream); - System.setErr(printStream); - outputArea.setEditable(false); + JPanel top = new JPanel(new GridLayout(1, 2, 20, 20)); openFileBrowser = new JButton("Browse directory"); openFileBrowser.addActionListener(new ActionListener() { @@ -74,15 +62,12 @@ public class GUI { } }); - openProperties = new JButton("Open properties"); - openProperties.setEnabled(false); - startOperation = new JButton("Start updating"); startOperation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { QueryBuilder queryBuilder = new QueryBuilder(); - if(queryBuilder.executeUpdateOnAllFiles(path, outputArea)){ + if(queryBuilder.executeUpdateOnAllFiles(path)){ log.info("All files updated!"); System.out.println("All files updated!"); } @@ -92,10 +77,8 @@ public class GUI { top.add(openFileBrowser); top.add(startOperation); - top.add(openProperties); frame.add(top, BorderLayout.NORTH); - frame.add(outputArea); frame.setVisible(true); } diff --git a/src/main/java/query/QueryBuilder.java b/src/main/java/query/QueryBuilder.java index c10cea0..0bf5996 100644 --- a/src/main/java/query/QueryBuilder.java +++ b/src/main/java/query/QueryBuilder.java @@ -7,7 +7,6 @@ import config.MKVToolProperties; import lombok.extern.log4j.Log4j2; import model.FileAttribute; -import javax.swing.*; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -27,7 +26,7 @@ public class QueryBuilder { public QueryBuilder() { } - public boolean executeUpdateOnAllFiles(String path, JTextArea outputArea) { + public boolean executeUpdateOnAllFiles(String path) { List allFilePaths = getAllFilesFromDirectory(path); if(allFilePaths == null){ log.error("Couldn't process path!"); @@ -35,8 +34,6 @@ public class QueryBuilder { } for(String filePath : allFilePaths){ updateAttributes(filePath, queryAttributes(filePath)); - log.info("Success: " + filePath); - System.out.println("Success: " + filePath); } return true; } @@ -85,7 +82,7 @@ public class QueryBuilder { List audios = null; try{ - yaml = new YAML(new File("config.yaml")); + yaml = new YAML(new File("./src/main/resources/config.yaml")); subtitles = yaml.getStringList("subtitle", null); audios = yaml.getStringList("audio", null); @@ -129,6 +126,13 @@ public class QueryBuilder { oldSubtitleDefault = attribute.getId(); } } + if(oldAudioDefault == audioDefault && oldSubtitleDefault == subtitleDefault){ + return; + } + if(audioIndex != 0){ + subtitleDefault = oldSubtitleDefault; + } + StringBuilder stringBuffer = new StringBuilder("\""); stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath()); stringBuffer.append("\" \"").append(path).append("\" "); @@ -143,11 +147,13 @@ public class QueryBuilder { log.error("Couldn't make changes to file"); } + log.info("Success: " + path); }else{ log.info("There were not enough lines provided to make any changes to the file"); } }catch(YamlInvalidContentException | IOException e){ + log.error("Failure: " + path); log.error(e.getMessage()); } } diff --git a/src/main/resources/config.yaml b/src/main/resources/config.yaml index c709d2b..341f395 100644 --- a/src/main/resources/config.yaml +++ b/src/main/resources/config.yaml @@ -3,5 +3,5 @@ audio: - ger - eng subtitle: - - eng - - ger \ No newline at end of file + - ger + - eng \ No newline at end of file From 4fbd281cdee7cb668fb90bcbdb47b3ef0a529bd5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 4 Mar 2020 23:56:39 +0000 Subject: [PATCH 5/5] Bump jackson-databind from 2.9.10.1 to 2.9.10.3 Bumps [jackson-databind](https://github.com/FasterXML/jackson) from 2.9.10.1 to 2.9.10.3. - [Release notes](https://github.com/FasterXML/jackson/releases) - [Commits](https://github.com/FasterXML/jackson/commits) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1644228..c080342 100644 --- a/pom.xml +++ b/pom.xml @@ -134,7 +134,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.10.1 + 2.9.10.3