1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-16 14:25:02 -05:00

Added {exif} binding

This commit is contained in:
Reinhard Pointner 2017-02-25 17:31:49 +08:00
parent 24e53a2426
commit 86b7c4e4fd
3 changed files with 30 additions and 20 deletions

View File

@ -51,6 +51,7 @@ import net.filebot.Settings;
import net.filebot.hash.HashType; import net.filebot.hash.HashType;
import net.filebot.media.MetaAttributes; import net.filebot.media.MetaAttributes;
import net.filebot.media.NamingStandard; import net.filebot.media.NamingStandard;
import net.filebot.mediainfo.ImageMetadata;
import net.filebot.mediainfo.MediaInfo; import net.filebot.mediainfo.MediaInfo;
import net.filebot.mediainfo.MediaInfo.StreamKind; import net.filebot.mediainfo.MediaInfo.StreamKind;
import net.filebot.mediainfo.MediaInfoException; import net.filebot.mediainfo.MediaInfoException;
@ -465,7 +466,7 @@ public class MediaBindingBean {
// calculate checksum from file // calculate checksum from file
Cache cache = Cache.getCache("crc32", CacheType.Ephemeral); Cache cache = Cache.getCache("crc32", CacheType.Ephemeral);
return (String) cache.computeIfAbsent(inferredMediaFile.getCanonicalPath(), it -> crc32(inferredMediaFile)); return (String) cache.computeIfAbsent(inferredMediaFile, it -> crc32(inferredMediaFile));
} }
@Define("fn") @Define("fn")
@ -828,6 +829,11 @@ public class MediaBindingBean {
return createMediaInfoBindings(StreamKind.Chapters); return createMediaInfoBindings(StreamKind.Chapters);
} }
@Define("exif")
public AssociativeScriptObject getImageMetadata() throws Exception {
return new AssociativeScriptObject(new ImageMetadata(getMediaFile()));
}
@Define("artist") @Define("artist")
public String getArtist() { public String getArtist() {
return getMusic().getArtist(); return getMusic().getArtist();

View File

@ -4,17 +4,18 @@ import static net.filebot.Logging.*;
import static net.filebot.similarity.Normalization.*; 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) { public ImageMetadata(File file) throws ImageProcessingException, IOException {
try {
Metadata metadata = ImageMetadataReader.readMetadata(file); Metadata metadata = ImageMetadataReader.readMetadata(file);
for (Directory directory : metadata.getDirectories()) { for (Directory directory : metadata.getDirectories()) {
@ -31,9 +32,6 @@ public class ImageMetadata extends LinkedHashMap<String, String> {
} }
} }
} }
} catch (Throwable e) {
debug.warning(e::toString);
}
} }
} }

View File

@ -1,6 +1,7 @@
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 java.io.Closeable; import java.io.Closeable;
import java.io.File; import java.io.File;
@ -151,8 +152,13 @@ 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) {
ImageMetadata exif = new ImageMetadata(new File(get(StreamKind.General, 0, "CompleteName"))); String path = get(StreamKind.General, 0, "CompleteName");
try {
ImageMetadata exif = new ImageMetadata(new File(path));
exif.forEach(streamInfo::putIfAbsent); exif.forEach(streamInfo::putIfAbsent);
} catch (Throwable e) {
debug.warning(format("%s: %s", e, path));
}
} }
return streamInfo; return streamInfo;