mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
Merge remote-tracking branch 'origin/master'
# Conflicts: # src/main/java/query/QueryBuilder.java
This commit is contained in:
31
pom.xml
31
pom.xml
@@ -72,27 +72,15 @@
|
|||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>2.22.2</version>
|
<version>2.22.2</version>
|
||||||
</plugin>
|
</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>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>pcgf-repo</id>
|
||||||
|
<url>https://repo.pcgamingfreaks.at/repository/maven-everything/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -146,7 +134,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>2.9.10.1</version>
|
<version>2.9.10.3</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- endregion -->
|
<!-- endregion -->
|
||||||
<!-- region unit-tests -->
|
<!-- region unit-tests -->
|
||||||
@@ -170,6 +158,11 @@
|
|||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- endregion -->
|
<!-- endregion -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>at.pcgamingfreaks</groupId>
|
||||||
|
<artifactId>YAML-Parser</artifactId>
|
||||||
|
<version>2.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -16,20 +16,15 @@ public class GUI {
|
|||||||
private String path;
|
private String path;
|
||||||
private JButton openFileBrowser;
|
private JButton openFileBrowser;
|
||||||
private JButton startOperation;
|
private JButton startOperation;
|
||||||
private JButton openProperties;
|
|
||||||
private JTextPane outputArea;
|
|
||||||
|
|
||||||
public GUI() {
|
public GUI() {
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
frame.setLayout(new BorderLayout());
|
frame.setLayout(new BorderLayout());
|
||||||
frame.setTitle("MKV Audio and Subtitle Changer");
|
frame.setTitle("MKV Audio and Subtitle Changer");
|
||||||
frame.setSize(500, 300);
|
frame.setSize(500, 75);
|
||||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
JPanel top = new JPanel(new GridLayout(1, 3, 20, 20));
|
JPanel top = new JPanel(new GridLayout(1, 2, 20, 20));
|
||||||
|
|
||||||
outputArea = new JTextPane();
|
|
||||||
outputArea.setEditable(false);
|
|
||||||
|
|
||||||
openFileBrowser = new JButton("Browse directory");
|
openFileBrowser = new JButton("Browse directory");
|
||||||
openFileBrowser.addActionListener(new ActionListener() {
|
openFileBrowser.addActionListener(new ActionListener() {
|
||||||
@@ -38,7 +33,7 @@ public class GUI {
|
|||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
try{
|
try{
|
||||||
if(! readFile("lastDir", Charset.defaultCharset()).isEmpty()){
|
if(! readFile("lastDir", Charset.defaultCharset()).isEmpty()){
|
||||||
String temp = readFile("dir.txt", Charset.defaultCharset());
|
String temp = readFile("lastDir", Charset.defaultCharset());
|
||||||
fileChooser.setCurrentDirectory(new File(temp));
|
fileChooser.setCurrentDirectory(new File(temp));
|
||||||
}
|
}
|
||||||
}catch(IOException ie){
|
}catch(IOException ie){
|
||||||
@@ -61,22 +56,20 @@ public class GUI {
|
|||||||
startOperation.setEnabled(true);
|
startOperation.setEnabled(true);
|
||||||
}
|
}
|
||||||
}catch(NullPointerException ne){
|
}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);
|
log.error("File or directory not found!", ne);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
openProperties = new JButton("Open properties");
|
|
||||||
openProperties.setEnabled(false);
|
|
||||||
|
|
||||||
startOperation = new JButton("Start updating");
|
startOperation = new JButton("Start updating");
|
||||||
startOperation.addActionListener(new ActionListener() {
|
startOperation.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
QueryBuilder queryBuilder = new QueryBuilder();
|
QueryBuilder queryBuilder = new QueryBuilder();
|
||||||
if(queryBuilder.executeUpdateOnAllFiles(path, outputArea)){
|
if(queryBuilder.executeUpdateOnAllFiles(path)){
|
||||||
outputArea.setText("All files updated!\n" + (outputArea.getText() == null ? "" : outputArea.getText()));
|
log.info("All files updated!");
|
||||||
|
System.out.println("All files updated!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -84,10 +77,8 @@ public class GUI {
|
|||||||
|
|
||||||
top.add(openFileBrowser);
|
top.add(openFileBrowser);
|
||||||
top.add(startOperation);
|
top.add(startOperation);
|
||||||
top.add(openProperties);
|
|
||||||
|
|
||||||
frame.add(top, BorderLayout.NORTH);
|
frame.add(top, BorderLayout.NORTH);
|
||||||
frame.add(outputArea);
|
|
||||||
|
|
||||||
frame.setVisible(true);
|
frame.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|||||||
21
src/main/java/config/CustomOutputStream.java
Normal file
21
src/main/java/config/CustomOutputStream.java
Normal file
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package query;
|
package query;
|
||||||
|
|
||||||
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
|
import at.pcgamingfreaks.yaml.YAML;
|
||||||
|
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import config.MKVToolProperties;
|
import config.MKVToolProperties;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
|
import model.FileAttribute;
|
||||||
|
|
||||||
import javax.swing.*;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -24,7 +26,7 @@ public class QueryBuilder {
|
|||||||
public QueryBuilder() {
|
public QueryBuilder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean executeUpdateOnAllFiles(String path, JTextPane outputArea) {
|
public boolean executeUpdateOnAllFiles(String path) {
|
||||||
List<String> allFilePaths = getAllFilesFromDirectory(path);
|
List<String> allFilePaths = getAllFilesFromDirectory(path);
|
||||||
if(allFilePaths == null){
|
if(allFilePaths == null){
|
||||||
log.error("Couldn't process path!");
|
log.error("Couldn't process path!");
|
||||||
@@ -32,7 +34,6 @@ public class QueryBuilder {
|
|||||||
}
|
}
|
||||||
for(String filePath : allFilePaths){
|
for(String filePath : allFilePaths){
|
||||||
updateAttributes(filePath, queryAttributes(filePath));
|
updateAttributes(filePath, queryAttributes(filePath));
|
||||||
outputArea.setText("Success: " + filePath + "\n" + outputArea.getPage());
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -75,40 +76,85 @@ public class QueryBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateAttributes(String path, List<FileAttribute> fileAttributes) {
|
private void updateAttributes(String path, List<FileAttribute> fileAttributes) {
|
||||||
if(fileAttributes.size() > 2){
|
|
||||||
StringBuffer stringBuffer = new StringBuffer("\"");
|
YAML yaml;
|
||||||
|
List<String> subtitles = null;
|
||||||
|
List<String> audios = null;
|
||||||
|
|
||||||
|
try{
|
||||||
|
yaml = new YAML(new File("./src/main/resources/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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(oldAudioDefault == audioDefault && oldSubtitleDefault == subtitleDefault){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(audioIndex != 0){
|
||||||
|
subtitleDefault = oldSubtitleDefault;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder stringBuffer = new StringBuilder("\"");
|
||||||
stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath());
|
stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath());
|
||||||
stringBuffer.append("\" \"");
|
stringBuffer.append("\" \"").append(path).append("\" ");
|
||||||
stringBuffer.append(path);
|
stringBuffer.append("--edit track:").append(oldSubtitleDefault).append(" --set flag-default=0 ");
|
||||||
stringBuffer.append("\" ");
|
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 ");
|
||||||
|
|
||||||
int c = 0;
|
|
||||||
int d = 0;
|
|
||||||
|
|
||||||
for(FileAttribute attributes : fileAttributes){
|
|
||||||
if(attributes.isDefaultTrack() && "audio".equals(attributes.getType())){
|
|
||||||
stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=0 ");
|
|
||||||
}
|
|
||||||
if(attributes.isDefaultTrack() && "subtitles".equals(attributes.getType())){
|
|
||||||
stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=0 ");
|
|
||||||
}
|
|
||||||
if("jpn".equals(attributes.getLanguage()) && "audio".equals(attributes.getType()) && c == 0){
|
|
||||||
c++;
|
|
||||||
stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=1 ");
|
|
||||||
}
|
|
||||||
if("eng".equals(attributes.getLanguage()) && "subtitles".equals(attributes.getType()) && d == 0){
|
|
||||||
d++;
|
|
||||||
stringBuffer.append("--edit track:" + attributes.getId() + " --set flag-default=1 ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
try{
|
try{
|
||||||
Runtime.getRuntime().exec(stringBuffer.toString());
|
Runtime.getRuntime().exec(stringBuffer.toString());
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
log.error("Couldn't make changes to file");
|
log.error("Couldn't make changes to file");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
log.info("Success: " + path);
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
log.info("There were not enough lines provided to make any changes to the file");
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/main/resources/config.yaml
Normal file
7
src/main/resources/config.yaml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
audio:
|
||||||
|
- jpn
|
||||||
|
- ger
|
||||||
|
- eng
|
||||||
|
subtitle:
|
||||||
|
- ger
|
||||||
|
- eng
|
||||||
Reference in New Issue
Block a user