Update dependencies & fix null pointer exception when file has missing properties or none at all

This commit is contained in:
2022-02-23 00:16:14 +01:00
parent 097499a916
commit bba612476b
3 changed files with 25 additions and 18 deletions

10
pom.xml
View File

@@ -106,17 +106,17 @@
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId> <artifactId>log4j-api</artifactId>
<version>2.15.0</version> <version>2.17.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId> <artifactId>log4j-core</artifactId>
<version>2.15.0</version> <version>2.17.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.apache.logging.log4j</groupId> <groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId> <artifactId>log4j-slf4j-impl</artifactId>
<version>2.12.0</version> <version>2.17.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
@@ -137,12 +137,12 @@
<dependency> <dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId> <groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId> <artifactId>jackson-dataformat-yaml</artifactId>
<version>2.9.9</version> <version>2.13.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId> <groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId> <artifactId>jackson-databind</artifactId>
<version>2.10.0.pr1</version> <version>2.13.1</version>
</dependency> </dependency>
<!-- endregion --> <!-- endregion -->
<!-- region unit-tests --> <!-- region unit-tests -->

View File

@@ -21,6 +21,9 @@ public class AttributeUpdaterKernel {
if(allValidPaths != null && 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);
if (attributes.isEmpty()) {
continue;
}
boolean fileHasChanged = false; boolean fileHasChanged = false;
for(AttributeConfig config : configPattern){ for(AttributeConfig config : configPattern){
/* /*

View File

@@ -28,22 +28,22 @@ public class MkvFileCollector implements FileCollector {
@Override @Override
public List<File> loadFiles(String path) { public List<File> loadFiles(String path) {
File file = new File(path); File file = new File(path);
if(file.isFile() && file.getAbsolutePath().endsWith(".mkv")){ if (file.isFile() && file.getAbsolutePath().endsWith(".mkv")) {
return new ArrayList<File>() {{ return new ArrayList<File>() {{
add(file); add(file);
}}; }};
}else if(file.isDirectory()){ } else if (file.isDirectory()) {
try(Stream<Path> paths = Files.walk(Paths.get(path))){ try (Stream<Path> paths = Files.walk(Paths.get(path))) {
return paths return paths
.filter(Files::isRegularFile) .filter(Files::isRegularFile)
.map(Path::toFile) .map(Path::toFile)
.filter(f -> f.getAbsolutePath().endsWith(".mkv")) .filter(f -> f.getAbsolutePath().endsWith(".mkv"))
.collect(Collectors.toList()); .collect(Collectors.toList());
}catch(IOException e){ } catch (IOException e) {
log.error("Couldn't find file or directory!", e); log.error("Couldn't find file or directory!", e);
return null; return null;
} }
}else{ } else {
return null; return null;
} }
} }
@@ -56,11 +56,11 @@ 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<>();
try{ try {
String command = ""; String command = "";
if(System.getProperty("os.name").toLowerCase().contains("windows")){ if (System.getProperty("os.name").toLowerCase().contains("windows")) {
command = "\"" + MKVToolProperties.getInstance().getMkvmergePath() + "\""; command = "\"" + MKVToolProperties.getInstance().getMkvmergePath() + "\"";
}else{ } else {
command = MKVToolProperties.getInstance().getMkvmergePath(); command = MKVToolProperties.getInstance().getMkvmergePath();
} }
String[] array = new String[]{ String[] array = new String[]{
@@ -74,19 +74,23 @@ public class MkvFileCollector implements FileCollector {
InputStream inputStream = Runtime.getRuntime().exec(array).getInputStream(); 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){ if (tracks == null) {
if(! "video".equals(attribute.get("type"))){ log.warn("Couldn't retrieve information of {}", file.getAbsoluteFile().toString());
return new ArrayList<>();
}
for (Map<String, Object> attribute : tracks) {
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");
fileAttributes.add(new FileAttribute( fileAttributes.add(new FileAttribute(
(int) properties.get("number"), (int) properties.get("number"),
(String) properties.get("language"), (String) properties.get("language"),
(String) properties.get("track_name"), (String) properties.get("track_name"),
(Boolean) properties.get("default_track"), (Boolean) properties.getOrDefault("default_track", false),
(Boolean) properties.get("forced_track"), (Boolean) properties.getOrDefault("forced_track", false),
(String) attribute.get("type"))); (String) attribute.get("type")));
} }
} }
}catch(IOException e){ } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
log.error("File could not be found or loaded!"); log.error("File could not be found or loaded!");
} }