This is an automated email from the ASF dual-hosted git repository.
nick pushed a commit to branch branch_1x
in repository https://gitbox.apache.org/repos/asf/tika.git
The following commit(s) were added to refs/heads/branch_1x by this push:
new b0242ee Backport to 1.x - TIKA-3310 Check if MP4 file's compatible
brands match any of the expected values, from Peter Kronenberg
b0242ee is described below
commit b0242ee617857fe85db2ba5ce186f6c9965b67bd
Author: Nick Burch <[email protected]>
AuthorDate: Sun Mar 14 20:53:38 2021 +0000
Backport to 1.x - TIKA-3310 Check if MP4 file's compatible brands match any
of the expected values, from Peter Kronenberg
---
.../java/org/apache/tika/parser/mp4/MP4Parser.java | 26 ++++++++++++++++------
1 file changed, 19 insertions(+), 7 deletions(-)
diff --git
a/tika-parsers/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
b/tika-parsers/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
index 933c53c..f06e556 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/mp4/MP4Parser.java
@@ -70,6 +70,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
/**
@@ -132,14 +133,25 @@ public class MP4Parser extends AbstractParser {
// Grab the file type box
FileTypeBox fileType = getOrNull(isoFile, FileTypeBox.class);
if (fileType != null) {
- // Identify the type
- MediaType type = MediaType.application("mp4");
- for (Map.Entry<MediaType, List<String>> e :
typesMap.entrySet()) {
- if (e.getValue().contains(fileType.getMajorBrand())) {
- type = e.getKey();
- break;
- }
+ // Identify the type based on the major brand
+ Optional<MediaType> typeHolder = typesMap.entrySet()
+ .stream()
+ .filter(e ->
e.getValue().contains(fileType.getMajorBrand()))
+ .findFirst()
+ .map(Map.Entry::getKey);
+
+ if (!typeHolder.isPresent()) {
+ // If no match for major brand, see if any of the
compatible brands match
+ typeHolder = typesMap.entrySet()
+ .stream()
+ .filter(e -> e.getValue()
+ .stream()
+
.anyMatch(fileType.getCompatibleBrands()::contains))
+ .findFirst()
+ .map(Map.Entry::getKey);
}
+
+ MediaType type =
typeHolder.orElse(MediaType.application("mp4"));
metadata.set(Metadata.CONTENT_TYPE, type.toString());
if (type.getType().equals("audio")) {