mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
[IMPROVE] querying
This commit is contained in:
18
pom.xml
18
pom.xml
@@ -72,24 +72,6 @@
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.22.2</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>ideauidesigner-maven-plugin</artifactId>
|
||||
<version>1.0-beta-1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>javac2</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
|
||||
<configuration>
|
||||
<fork>true</fork>
|
||||
<debug>true</debug>
|
||||
<failOnError>true</failOnError>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ audio:
|
||||
- ger
|
||||
- eng
|
||||
subtitle:
|
||||
- eng
|
||||
- ger
|
||||
- ger
|
||||
- eng
|
||||
Reference in New Issue
Block a user