mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 02:05:56 +01:00
[IMPL] Changed to CLI tool
This commit is contained in:
@@ -10,36 +10,29 @@ import lombok.extern.log4j.Log4j2;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
|
||||
@Log4j2
|
||||
public class AttributeUpdaterKernel {
|
||||
MkvFileCollector collector = new MkvFileCollector();
|
||||
|
||||
public void execute() {
|
||||
public void execute(String path) {
|
||||
List<AttributeConfig> configPattern = ConfigUtil.loadConfig();
|
||||
List<File> allValidPaths = null;
|
||||
try(Scanner scanner = new Scanner(System.in)){
|
||||
System.out.println("Please enter the path to the files which should be updated: ");
|
||||
do{
|
||||
allValidPaths = collector.loadFiles(scanner.nextLine());
|
||||
if(allValidPaths == null){
|
||||
System.out.println("Please enter a valid path: ");
|
||||
}
|
||||
}while(allValidPaths == null);
|
||||
log.info(allValidPaths.size() + " files where found and will now be processed!");
|
||||
}
|
||||
for(File file : allValidPaths){
|
||||
List<FileAttribute> attributes = collector.loadAttributes(file);
|
||||
for(AttributeConfig config : configPattern){
|
||||
/*
|
||||
* Creating new ArrayList, because the method removes elements from the list by reference
|
||||
*/
|
||||
boolean fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
|
||||
if(fileHasChanged){
|
||||
break;
|
||||
List<File> allValidPaths = collector.loadFiles(path);
|
||||
if(! allValidPaths.isEmpty()){
|
||||
for(File file : allValidPaths){
|
||||
List<FileAttribute> attributes = collector.loadAttributes(file);
|
||||
for(AttributeConfig config : configPattern){
|
||||
/*
|
||||
* Creating new ArrayList, because the method removes elements from the list by reference
|
||||
*/
|
||||
boolean fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
|
||||
if(fileHasChanged){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
log.error("Path is not valid!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,13 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
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
|
||||
@Setter
|
||||
public class MKVToolProperties {
|
||||
private String directoryPath;
|
||||
private String mkvmergePath;
|
||||
private String mkvpropeditPath;
|
||||
|
||||
@@ -28,67 +22,4 @@ public class 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,32 @@
|
||||
package at.pcgamingfreaks.mkvaudiosubtitlechanger;
|
||||
|
||||
import at.pcgamingfreaks.yaml.YAML;
|
||||
import at.pcgamingfreaks.yaml.YamlInvalidContentException;
|
||||
import at.pcgamingfreaks.yaml.YamlKeyNotFoundException;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@Log4j2
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
MKVToolProperties.getInstance().defineMKVToolNixPath();
|
||||
AttributeUpdaterKernel kernel = new AttributeUpdaterKernel();
|
||||
kernel.execute();
|
||||
if(checkIfMKVToolNixIsValid()){
|
||||
AttributeUpdaterKernel kernel = new AttributeUpdaterKernel();
|
||||
kernel.execute(args[0]);
|
||||
}else{
|
||||
log.error("MKVToolNix was not found! Please recheck path");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkIfMKVToolNixIsValid() {
|
||||
try{
|
||||
String path = new YAML(new File("config.yml")).getString("mkvtoolnixPath");
|
||||
MKVToolProperties.getInstance().setMkvmergePath(path + "mkvmerge");
|
||||
MKVToolProperties.getInstance().setMkvpropeditPath(path + "mkvproperties");
|
||||
}catch(YamlKeyNotFoundException | IOException | YamlInvalidContentException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new File(MKVToolProperties.getInstance().getMkvmergePath()).isFile() && new File(MKVToolProperties.getInstance().getMkvpropeditPath()).isFile();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user