1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 08:18:52 -05:00

MediaInfo does not support EXIF image metadata natively so we use the metadata-extractor library and implicitly merge that information in

This commit is contained in:
Reinhard Pointner 2017-02-25 04:38:16 +08:00
parent f2b29f108c
commit d2df8d8923
2 changed files with 20 additions and 23 deletions

View File

@ -1,35 +1,38 @@
package net.filebot.mediainfo; package net.filebot.mediainfo;
import static net.filebot.Logging.*; import static net.filebot.Logging.*;
import static net.filebot.similarity.Normalization.*;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import com.drew.imaging.ImageMetadataReader; import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Directory; import com.drew.metadata.Directory;
import com.drew.metadata.Metadata; import com.drew.metadata.Metadata;
import com.drew.metadata.Tag; import com.drew.metadata.Tag;
public class ImageMetadata extends LinkedHashMap<String, String> { public class ImageMetadata extends LinkedHashMap<String, String> {
public ImageMetadata(File file) throws ImageProcessingException, IOException { public ImageMetadata(File file) {
Metadata metadata = ImageMetadataReader.readMetadata(file); try {
Metadata metadata = ImageMetadataReader.readMetadata(file);
for (Directory directory : metadata.getDirectories()) { for (Directory directory : metadata.getDirectories()) {
for (Tag tag : directory.getTags()) { for (Tag tag : directory.getTags()) {
String value = tag.getDescription(); String v = tag.getDescription();
if (value != null && value.length() > 0) { if (v != null && v.length() > 0) {
putIfAbsent(tag.getTagName(), tag.getDescription()); putIfAbsent(normalizeSpace(normalizePunctuation(tag.getTagName()), "_"), v);
} }
} }
if (directory.hasErrors()) { if (directory.hasErrors()) {
for (String error : directory.getErrors()) { for (String error : directory.getErrors()) {
debug.warning(error); debug.warning(error);
}
} }
} }
} catch (Throwable e) {
debug.warning(e::toString);
} }
} }

View File

@ -1,8 +1,6 @@
package net.filebot.mediainfo; package net.filebot.mediainfo;
import static java.nio.charset.StandardCharsets.*; import static java.nio.charset.StandardCharsets.*;
import static net.filebot.Logging.*;
import static net.filebot.similarity.Normalization.*;
import java.io.Closeable; import java.io.Closeable;
import java.io.File; 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 // 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) { if (streamKind == StreamKind.Image && streamNumber == 0) {
try { ImageMetadata exif = new ImageMetadata(new File(get(StreamKind.General, 0, "CompleteName")));
ImageMetadata exif = new ImageMetadata(new File(get(StreamKind.General, 0, "CompleteName"))); exif.forEach(streamInfo::putIfAbsent);
exif.forEach((k, v) -> streamInfo.putIfAbsent(normalizeSpace(normalizePunctuation(k), "_"), v));
} catch (Throwable e) {
debug.warning(e::toString);
}
} }
return streamInfo; return streamInfo;