[IMPROVE] querying

This commit is contained in:
RatzzFatzz
2020-02-14 22:37:54 +01:00
parent 4dff50f13a
commit 7639cb8b07
4 changed files with 16 additions and 45 deletions

View File

@@ -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);
}

View File

@@ -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<String> 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<String> 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());
}
}