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:05:07 +08:00
parent 0a92f100ae
commit f2b29f108c
5 changed files with 57 additions and 0 deletions

View File

@ -35,5 +35,7 @@
<classpathentry kind="lib" path="lib/jars/AppleJavaExtensions.jar"/> <classpathentry kind="lib" path="lib/jars/AppleJavaExtensions.jar"/>
<classpathentry kind="lib" path="lib/ivy/jar/controlsfx.jar" sourcepath="lib/ivy/source/controlsfx.jar"/> <classpathentry kind="lib" path="lib/ivy/jar/controlsfx.jar" sourcepath="lib/ivy/source/controlsfx.jar"/>
<classpathentry kind="lib" path="lib/ivy/jar/lanterna.jar" sourcepath="lib/ivy/source/lanterna.jar"/> <classpathentry kind="lib" path="lib/ivy/jar/lanterna.jar" sourcepath="lib/ivy/source/lanterna.jar"/>
<classpathentry kind="lib" path="lib/ivy/jar/metadata-extractor.jar"/>
<classpathentry kind="lib" path="lib/ivy/jar/xmpcore.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -235,6 +235,12 @@
<include name="com/optimaize/langdetect/**" /> <include name="com/optimaize/langdetect/**" />
<include name="languages/**" /> <include name="languages/**" />
</zipfileset> </zipfileset>
<zipfileset src="${dir.lib}/ivy/jar/metadata-extractor.jar">
<include name="com/drew/**" />
</zipfileset>
<zipfileset src="${dir.lib}/ivy/jar/xmpcore.jar">
<include name="com/adobe/xmp/**" />
</zipfileset>
<zipfileset src="${dir.lib}/jars/jacksum.jar"> <zipfileset src="${dir.lib}/jars/jacksum.jar">
<include name="jonelo/jacksum/adapt/**" /> <include name="jonelo/jacksum/adapt/**" />
<include name="jonelo/jacksum/algorithm/**" /> <include name="jonelo/jacksum/algorithm/**" />

View File

@ -26,6 +26,7 @@
<dependency rev="0.6.4" org="one.util" name="streamex" /> <dependency rev="0.6.4" org="one.util" name="streamex" />
<dependency rev="8.40.12" org="org.controlsfx" name="controlsfx" /> <dependency rev="8.40.12" org="org.controlsfx" name="controlsfx" />
<dependency rev="3.0.0-beta3" org="com.googlecode.lanterna" name="lanterna" /> <dependency rev="3.0.0-beta3" org="com.googlecode.lanterna" name="lanterna" />
<dependency rev="2.10.1" org="com.drewnoakes" name="metadata-extractor" />
<!-- FileBot Scripting --> <!-- FileBot Scripting -->
<dependency rev="1.10.1" org="org.apache.ant" name="ant" /> <dependency rev="1.10.1" org="org.apache.ant" name="ant" />

View File

@ -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<String, String> {
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);
}
}
}
}
}

View File

@ -1,6 +1,8 @@
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;
@ -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; return streamInfo;
} }