mirror of
https://github.com/RatzzFatzz/MKVAudioSubtitleChanger.git
synced 2026-02-11 10:05:58 +01:00
[FIX] Linux compatibility
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
mkvtoolnixPath: /usr/bin
|
||||||
config:
|
config:
|
||||||
1:
|
1:
|
||||||
audio:
|
audio:
|
||||||
|
|||||||
8
pom.xml
8
pom.xml
@@ -72,6 +72,14 @@
|
|||||||
<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.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>9</source>
|
||||||
|
<target>9</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|||||||
@@ -18,18 +18,22 @@ public class AttributeUpdaterKernel {
|
|||||||
public void execute(String path) {
|
public void execute(String path) {
|
||||||
List<AttributeConfig> configPattern = ConfigUtil.loadConfig();
|
List<AttributeConfig> configPattern = ConfigUtil.loadConfig();
|
||||||
List<File> allValidPaths = collector.loadFiles(path);
|
List<File> allValidPaths = collector.loadFiles(path);
|
||||||
if(! allValidPaths.isEmpty() && configPattern != null){
|
if(allValidPaths != null && configPattern != null){
|
||||||
for(File file : allValidPaths){
|
for(File file : allValidPaths){
|
||||||
List<FileAttribute> attributes = collector.loadAttributes(file);
|
List<FileAttribute> attributes = collector.loadAttributes(file);
|
||||||
|
boolean fileHasChanged = false;
|
||||||
for(AttributeConfig config : configPattern){
|
for(AttributeConfig config : configPattern){
|
||||||
/*
|
/*
|
||||||
* Creating new ArrayList, because the method removes elements from the list by reference
|
* Creating new ArrayList, because the method removes elements from the list by reference
|
||||||
*/
|
*/
|
||||||
boolean fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
|
fileHasChanged = new ConfigProcessor(config).processConfig(file, new ArrayList<>(attributes));
|
||||||
if(fileHasChanged){
|
if(fileHasChanged){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(! fileHasChanged){
|
||||||
|
log.info(file.getName() + " didn't change!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
log.error("Path is not valid or config has errors!");
|
log.error("Path is not valid or config has errors!");
|
||||||
|
|||||||
@@ -21,12 +21,17 @@ public class Main {
|
|||||||
|
|
||||||
private static boolean checkIfMKVToolNixIsValid() {
|
private static boolean checkIfMKVToolNixIsValid() {
|
||||||
try{
|
try{
|
||||||
String path = new YAML(new File("config.yml")).getString("mkvtoolnixPath");
|
String path = new YAML(new File("config.yaml")).getString("mkvtoolnixPath");
|
||||||
if(! path.endsWith(File.separator)){
|
if(! path.endsWith(File.separator)){
|
||||||
path += File.separator;
|
path += File.separator;
|
||||||
}
|
}
|
||||||
|
if(System.getProperty("os.name").toLowerCase().contains("windows")){
|
||||||
|
MKVToolProperties.getInstance().setMkvmergePath(path + "mkvmerge.exe");
|
||||||
|
MKVToolProperties.getInstance().setMkvpropeditPath(path + "mkvpropedit.exe");
|
||||||
|
}else{
|
||||||
MKVToolProperties.getInstance().setMkvmergePath(path + "mkvmerge");
|
MKVToolProperties.getInstance().setMkvmergePath(path + "mkvmerge");
|
||||||
MKVToolProperties.getInstance().setMkvpropeditPath(path + "mkvproperties");
|
MKVToolProperties.getInstance().setMkvpropeditPath(path + "mkvpropedit");
|
||||||
|
}
|
||||||
}catch(YamlKeyNotFoundException | IOException | YamlInvalidContentException e){
|
}catch(YamlKeyNotFoundException | IOException | YamlInvalidContentException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,9 +84,15 @@ public class ConfigProcessor {
|
|||||||
* @return if the the current file was updated or not. Returns true if the file already has the correct metadata set
|
* @return if the the current file was updated or not. Returns true if the file already has the correct metadata set
|
||||||
*/
|
*/
|
||||||
private boolean updateFile(File file, List<FileAttribute> attributes, TransferObject transfer) {
|
private boolean updateFile(File file, List<FileAttribute> attributes, TransferObject transfer) {
|
||||||
StringBuilder stringBuffer = new StringBuilder("\"");
|
StringBuilder stringBuffer = new StringBuilder();
|
||||||
|
if(System.getProperty("os.name").toLowerCase().contains("windows")){
|
||||||
|
stringBuffer.append("\"");
|
||||||
stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath());
|
stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath());
|
||||||
stringBuffer.append("\" \"").append(file.getAbsolutePath()).append("\" ");
|
stringBuffer.append("\" \"").append(file.getAbsolutePath()).append("\" ");
|
||||||
|
}else{
|
||||||
|
stringBuffer.append(MKVToolProperties.getInstance().getMkvpropeditPath());
|
||||||
|
stringBuffer.append(" ").append(file.getAbsolutePath()).append(" ");
|
||||||
|
}
|
||||||
if(audioDefault != - 1){
|
if(audioDefault != - 1){
|
||||||
stringBuffer.append("--edit track:=").append(audioDefault).append(" --set flag-default=0 ");
|
stringBuffer.append("--edit track:=").append(audioDefault).append(" --set flag-default=0 ");
|
||||||
}
|
}
|
||||||
@@ -106,18 +112,19 @@ public class ConfigProcessor {
|
|||||||
* In this case the file would be change to the exact same audio and subtitle lines and we want to
|
* In this case the file would be change to the exact same audio and subtitle lines and we want to
|
||||||
* avoid unnecessary changes to the file
|
* avoid unnecessary changes to the file
|
||||||
*/
|
*/
|
||||||
|
log.info(file.getName() + " already fits config!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
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");
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* We return true even if there was an error. If there was an error, the chances that this file is still
|
* We return true even if there was an error. If there was an error, the chances that this file is still
|
||||||
* busy later.
|
* busy later.
|
||||||
*/
|
*/
|
||||||
|
log.info(file.getName() + " was updated");
|
||||||
return true;
|
return true;
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -56,14 +56,24 @@ public class MkvFileCollector implements FileCollector {
|
|||||||
public List<FileAttribute> loadAttributes(File file) {
|
public List<FileAttribute> loadAttributes(File file) {
|
||||||
Map<String, Object> jsonMap;
|
Map<String, Object> jsonMap;
|
||||||
List<FileAttribute> fileAttributes = new ArrayList<>();
|
List<FileAttribute> fileAttributes = new ArrayList<>();
|
||||||
System.out.println("\"" + MKVToolProperties.getInstance().getMkvmergePath()
|
try{
|
||||||
+ "\" --identify --identification-format json \"" + file.getAbsolutePath() + "\"");
|
String command = "";
|
||||||
try(InputStream inputStream =
|
if(System.getProperty("os.name").toLowerCase().contains("windows")){
|
||||||
Runtime.getRuntime().exec("\"" + MKVToolProperties.getInstance().getMkvmergePath()
|
command = "\"" + MKVToolProperties.getInstance().getMkvmergePath() + "\"";
|
||||||
+ "\" --identify --identification-format json \"" + file.getAbsolutePath() + "\"").getInputStream()){
|
}else{
|
||||||
|
command = MKVToolProperties.getInstance().getMkvmergePath();
|
||||||
|
}
|
||||||
|
String[] array = new String[]{
|
||||||
|
command,
|
||||||
|
"--identify",
|
||||||
|
"--identification-format",
|
||||||
|
"json",
|
||||||
|
file.getAbsoluteFile().toString()
|
||||||
|
};
|
||||||
|
|
||||||
|
InputStream inputStream = Runtime.getRuntime().exec(array).getInputStream();
|
||||||
jsonMap = mapper.readValue(inputStream, Map.class);
|
jsonMap = mapper.readValue(inputStream, Map.class);
|
||||||
List<Map<String, Object>> tracks = (List<Map<String, Object>>) jsonMap.get("tracks");
|
List<Map<String, Object>> tracks = (List<Map<String, Object>>) jsonMap.get("tracks");
|
||||||
|
|
||||||
for(Map<String, Object> attribute : tracks){
|
for(Map<String, Object> attribute : tracks){
|
||||||
if(! "video".equals(attribute.get("type"))){
|
if(! "video".equals(attribute.get("type"))){
|
||||||
Map<String, Object> properties = (Map<String, Object>) attribute.get("properties");
|
Map<String, Object> properties = (Map<String, Object>) attribute.get("properties");
|
||||||
@@ -77,6 +87,7 @@ public class MkvFileCollector implements FileCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}catch(IOException e){
|
}catch(IOException e){
|
||||||
|
e.printStackTrace();
|
||||||
log.error("File could not be found or loaded!");
|
log.error("File could not be found or loaded!");
|
||||||
}
|
}
|
||||||
return fileAttributes;
|
return fileAttributes;
|
||||||
|
|||||||
Reference in New Issue
Block a user