mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
[IMPL] config file implemented
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -85,68 +85,70 @@ public class QueryBuilder {
|
||||
List<String> 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ audio:
|
||||
- ger
|
||||
- eng
|
||||
subtitle:
|
||||
- ger
|
||||
- eng
|
||||
- eng
|
||||
- ger
|
||||
Reference in New Issue
Block a user