diff --git a/pom.xml b/pom.xml index 2785ca1..aaa762f 100644 --- a/pom.xml +++ b/pom.xml @@ -106,17 +106,17 @@ org.apache.logging.log4j log4j-api - 2.15.0 + 2.17.1 org.apache.logging.log4j log4j-core - 2.15.0 + 2.17.1 org.apache.logging.log4j log4j-slf4j-impl - 2.12.0 + 2.17.1 org.slf4j @@ -137,12 +137,12 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml - 2.9.9 + 2.13.1 com.fasterxml.jackson.core jackson-databind - 2.10.0.pr1 + 2.13.1 diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java index 4a0e9e4..95a04c3 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/AttributeUpdaterKernel.java @@ -21,6 +21,9 @@ public class AttributeUpdaterKernel { if(allValidPaths != null && configPattern != null){ for(File file : allValidPaths){ List attributes = collector.loadAttributes(file); + if (attributes.isEmpty()) { + continue; + } boolean fileHasChanged = false; for(AttributeConfig config : configPattern){ /* diff --git a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/intimpl/MkvFileCollector.java b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/intimpl/MkvFileCollector.java index 8e56e10..52e86be 100644 --- a/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/intimpl/MkvFileCollector.java +++ b/src/main/java/at/pcgamingfreaks/mkvaudiosubtitlechanger/intimpl/MkvFileCollector.java @@ -28,22 +28,22 @@ public class MkvFileCollector implements FileCollector { @Override public List loadFiles(String path) { File file = new File(path); - if(file.isFile() && file.getAbsolutePath().endsWith(".mkv")){ + if (file.isFile() && file.getAbsolutePath().endsWith(".mkv")) { return new ArrayList() {{ add(file); }}; - }else if(file.isDirectory()){ - try(Stream paths = Files.walk(Paths.get(path))){ + } else if (file.isDirectory()) { + try (Stream paths = Files.walk(Paths.get(path))) { return paths .filter(Files::isRegularFile) .map(Path::toFile) .filter(f -> f.getAbsolutePath().endsWith(".mkv")) .collect(Collectors.toList()); - }catch(IOException e){ + } catch (IOException e) { log.error("Couldn't find file or directory!", e); return null; } - }else{ + } else { return null; } } @@ -56,11 +56,11 @@ public class MkvFileCollector implements FileCollector { public List loadAttributes(File file) { Map jsonMap; List fileAttributes = new ArrayList<>(); - try{ + try { String command = ""; - if(System.getProperty("os.name").toLowerCase().contains("windows")){ + if (System.getProperty("os.name").toLowerCase().contains("windows")) { command = "\"" + MKVToolProperties.getInstance().getMkvmergePath() + "\""; - }else{ + } else { command = MKVToolProperties.getInstance().getMkvmergePath(); } String[] array = new String[]{ @@ -74,19 +74,23 @@ public class MkvFileCollector implements FileCollector { InputStream inputStream = Runtime.getRuntime().exec(array).getInputStream(); jsonMap = mapper.readValue(inputStream, Map.class); List> tracks = (List>) jsonMap.get("tracks"); - for(Map attribute : tracks){ - if(! "video".equals(attribute.get("type"))){ + if (tracks == null) { + log.warn("Couldn't retrieve information of {}", file.getAbsoluteFile().toString()); + return new ArrayList<>(); + } + for (Map attribute : tracks) { + if (!"video".equals(attribute.get("type"))) { Map properties = (Map) attribute.get("properties"); fileAttributes.add(new FileAttribute( (int) properties.get("number"), (String) properties.get("language"), (String) properties.get("track_name"), - (Boolean) properties.get("default_track"), - (Boolean) properties.get("forced_track"), + (Boolean) properties.getOrDefault("default_track", false), + (Boolean) properties.getOrDefault("forced_track", false), (String) attribute.get("type"))); } } - }catch(IOException e){ + } catch (IOException e) { e.printStackTrace(); log.error("File could not be found or loaded!"); }