diff --git a/.classpath b/.classpath index 6eb7c10f..f64665d9 100644 --- a/.classpath +++ b/.classpath @@ -35,5 +35,7 @@ + + diff --git a/build.xml b/build.xml index 549c9eb1..344e89a5 100644 --- a/build.xml +++ b/build.xml @@ -235,6 +235,12 @@ + + + + + + diff --git a/ivy.xml b/ivy.xml index cbaec9a7..b12567b5 100644 --- a/ivy.xml +++ b/ivy.xml @@ -26,6 +26,7 @@ + diff --git a/source/net/filebot/mediainfo/ImageMetadata.java b/source/net/filebot/mediainfo/ImageMetadata.java new file mode 100644 index 00000000..5d93b1a8 --- /dev/null +++ b/source/net/filebot/mediainfo/ImageMetadata.java @@ -0,0 +1,36 @@ +package net.filebot.mediainfo; + +import static net.filebot.Logging.*; + +import java.io.File; +import java.io.IOException; +import java.util.LinkedHashMap; + +import com.drew.imaging.ImageMetadataReader; +import com.drew.imaging.ImageProcessingException; +import com.drew.metadata.Directory; +import com.drew.metadata.Metadata; +import com.drew.metadata.Tag; + +public class ImageMetadata extends LinkedHashMap { + + public ImageMetadata(File file) throws ImageProcessingException, IOException { + Metadata metadata = ImageMetadataReader.readMetadata(file); + + for (Directory directory : metadata.getDirectories()) { + for (Tag tag : directory.getTags()) { + String value = tag.getDescription(); + if (value != null && value.length() > 0) { + putIfAbsent(tag.getTagName(), tag.getDescription()); + } + } + + if (directory.hasErrors()) { + for (String error : directory.getErrors()) { + debug.warning(error); + } + } + } + } + +} diff --git a/source/net/filebot/mediainfo/MediaInfo.java b/source/net/filebot/mediainfo/MediaInfo.java index 72f7dc25..f08e0cc2 100644 --- a/source/net/filebot/mediainfo/MediaInfo.java +++ b/source/net/filebot/mediainfo/MediaInfo.java @@ -1,6 +1,8 @@ package net.filebot.mediainfo; import static java.nio.charset.StandardCharsets.*; +import static net.filebot.Logging.*; +import static net.filebot.similarity.Normalization.*; import java.io.Closeable; import java.io.File; @@ -149,6 +151,16 @@ public class MediaInfo implements Closeable { } } + // MediaInfo does not support EXIF image metadata natively so we use the metadata-extractor library and implicitly merge that information in + if (streamKind == StreamKind.Image && streamNumber == 0) { + try { + ImageMetadata exif = new ImageMetadata(new File(get(StreamKind.General, 0, "CompleteName"))); + exif.forEach((k, v) -> streamInfo.putIfAbsent(normalizeSpace(normalizePunctuation(k), "_"), v)); + } catch (Throwable e) { + debug.warning(e::toString); + } + } + return streamInfo; }