[FIX] jar

This commit is contained in:
RatzzFatzz
2020-05-10 19:36:21 +02:00
parent 0da07297ea
commit 401840e554
10 changed files with 18 additions and 29 deletions

View File

@@ -0,0 +1,94 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Log4j2
@Getter
public class MKVToolProperties {
private String directoryPath;
private String mkvmergePath;
private String mkvpropeditPath;
private static MKVToolProperties instance = null;
private MKVToolProperties() {
}
public static MKVToolProperties getInstance() {
if(instance == null){
instance = new MKVToolProperties();
}
return instance;
}
public void defineMKVToolNixPath() {
if(searchWithFilePath() && pathIsValid()){
log.info("MKVToolNix found!");
return;
}
log.debug("MKVToolNix not found in file!");
searchInDefaultPath();
if(pathIsValid()){
log.info("MKVToolNix found!");
return;
}
log.debug("MKVToolNix not found in default path!");
Scanner input = new Scanner(System.in);
while(true){
searchWithUserPath(input);
if(pathIsValid()){
break;
}
}
try(PrintWriter writer = new PrintWriter("mkvDirectoryPath", "UTF-8")){
writer.println(directoryPath);
}catch(UnsupportedEncodingException | FileNotFoundException e){
log.error("File counldn't be written!");
}
log.info("MKVToolNix found!");
}
private boolean pathIsValid() {
checkForSeparator();
setMKVmergeAndPropEditPath();
return new File(mkvmergePath).exists() && new File(mkvpropeditPath).exists();
}
private void checkForSeparator() {
if(! (directoryPath.endsWith("/") || (directoryPath.endsWith("\\") && System.getProperty("os.name").toLowerCase().contains("windows")))){
directoryPath += File.separator;
}
}
private void setMKVmergeAndPropEditPath() {
mkvmergePath = directoryPath + "mkvmerge.exe";
mkvpropeditPath = directoryPath + "mkvpropedit.exe";
}
private boolean searchWithFilePath() {
try(Stream<String> stream = Files.lines(Paths.get("mkvDirectoryPath"))){
directoryPath = stream.collect(Collectors.joining("\n"));
}catch(IOException e){
log.fatal(e.getMessage());
return false;
}
return true;
}
private void searchInDefaultPath() {
directoryPath = "C:\\Program Files\\MKVToolNix";
}
private void searchWithUserPath(Scanner input) {
log.info("Please enter the path to the directory of MKVToolNix:");
directoryPath = input.nextLine();
}
}

View File

@@ -1,7 +1,5 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
import config.MKVToolProperties;
public class Main {
public static void main(String[] args) {
MKVToolProperties.getInstance().defineMKVToolNixPath();

View File

@@ -1,7 +1,7 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.config;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.MKVToolProperties;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import config.MKVToolProperties;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
@@ -13,8 +13,8 @@ import java.util.List;
@Log4j2
public class ConfigProcessor {
private int audioDefault = 0;
private int subtitleDefault = 0;
private int audioDefault = - 1;
private int subtitleDefault = - 1;
private final AttributeConfig config;
public ConfigProcessor(AttributeConfig config) {
@@ -87,8 +87,12 @@ public class ConfigProcessor {
StringBuilder stringBuffer = new StringBuilder("\"");
stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath());
stringBuffer.append("\" \"").append(file.getAbsolutePath()).append("\" ");
stringBuffer.append("--edit track:=").append(subtitleDefault).append(" --set flag-default=0 ");
stringBuffer.append("--edit track:=").append(audioDefault).append(" --set flag-default=0 ");
if(audioDefault != - 1){
stringBuffer.append("--edit track:=").append(audioDefault).append(" --set flag-default=0 ");
}
if(subtitleDefault != - 1){
stringBuffer.append("--edit track:=").append(subtitleDefault).append(" --set flag-default=0 ");
}
collectLines(attributes, transfer);
if(transfer.isValid){
if(transfer.isAudioOn){

View File

@@ -1,8 +1,8 @@
package at.pcgamingfreaks.mkvaudiosubtitlechanger.intimpl;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.MKVToolProperties;
import at.pcgamingfreaks.mkvaudiosubtitlechanger.model.FileAttribute;
import com.fasterxml.jackson.databind.ObjectMapper;
import config.MKVToolProperties;
import lombok.extern.log4j.Log4j2;
import java.io.File;
@@ -56,6 +56,8 @@ public class MkvFileCollector implements FileCollector {
public List<FileAttribute> loadAttributes(File file) {
Map<String, Object> jsonMap;
List<FileAttribute> fileAttributes = new ArrayList<>();
System.out.println("\"" + MKVToolProperties.getInstance().getMkvmergePath()
+ "\" --identify --identification-format json \"" + file.getAbsolutePath() + "\"");
try(InputStream inputStream =
Runtime.getRuntime().exec("\"" + MKVToolProperties.getInstance().getMkvmergePath()
+ "\" --identify --identification-format json \"" + file.getAbsolutePath() + "\"").getInputStream()){

View File

@@ -14,7 +14,7 @@ import java.util.stream.Collectors;
@Log4j2
public class ConfigUtil {
public static List<AttributeConfig> loadConfig() {
try(YAML yaml = new YAML(new File("./src/main/resources/config.yaml"))){
try(YAML yaml = new YAML(new File("config.yaml"))){
return yaml.getKeysFiltered(".*audio.*").stream()
.sorted()
.map(elem -> elem.replace(".audio", ""))