From d2df8d892382890b79a169710817aef64302480d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 25 Feb 2017 04:38:16 +0800 Subject: [PATCH] MediaInfo does not support EXIF image metadata natively so we use the metadata-extractor library and implicitly merge that information in --- .../net/filebot/mediainfo/ImageMetadata.java | 33 ++++++++++--------- source/net/filebot/mediainfo/MediaInfo.java | 10 ++---- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/source/net/filebot/mediainfo/ImageMetadata.java b/source/net/filebot/mediainfo/ImageMetadata.java index 5d93b1a8..94844cdb 100644 --- a/source/net/filebot/mediainfo/ImageMetadata.java +++ b/source/net/filebot/mediainfo/ImageMetadata.java @@ -1,35 +1,38 @@ package net.filebot.mediainfo; import static net.filebot.Logging.*; +import static net.filebot.similarity.Normalization.*; 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); + public ImageMetadata(File file) { + try { + 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); + for (Directory directory : metadata.getDirectories()) { + for (Tag tag : directory.getTags()) { + String v = tag.getDescription(); + if (v != null && v.length() > 0) { + putIfAbsent(normalizeSpace(normalizePunctuation(tag.getTagName()), "_"), v); + } + } + + if (directory.hasErrors()) { + for (String error : directory.getErrors()) { + debug.warning(error); + } } } + } catch (Throwable e) { + debug.warning(e::toString); } } diff --git a/source/net/filebot/mediainfo/MediaInfo.java b/source/net/filebot/mediainfo/MediaInfo.java index f08e0cc2..8476ed1c 100644 --- a/source/net/filebot/mediainfo/MediaInfo.java +++ b/source/net/filebot/mediainfo/MediaInfo.java @@ -1,8 +1,6 @@ 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; @@ -153,12 +151,8 @@ 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); - } + ImageMetadata exif = new ImageMetadata(new File(get(StreamKind.General, 0, "CompleteName"))); + exif.forEach(streamInfo::putIfAbsent); } return streamInfo;