Added {exif} binding
This commit is contained in:
parent
24e53a2426
commit
86b7c4e4fd
|
@ -51,6 +51,7 @@ import net.filebot.Settings;
|
|||
import net.filebot.hash.HashType;
|
||||
import net.filebot.media.MetaAttributes;
|
||||
import net.filebot.media.NamingStandard;
|
||||
import net.filebot.mediainfo.ImageMetadata;
|
||||
import net.filebot.mediainfo.MediaInfo;
|
||||
import net.filebot.mediainfo.MediaInfo.StreamKind;
|
||||
import net.filebot.mediainfo.MediaInfoException;
|
||||
|
@ -465,7 +466,7 @@ public class MediaBindingBean {
|
|||
|
||||
// calculate checksum from file
|
||||
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")
|
||||
|
@ -828,6 +829,11 @@ public class MediaBindingBean {
|
|||
return createMediaInfoBindings(StreamKind.Chapters);
|
||||
}
|
||||
|
||||
@Define("exif")
|
||||
public AssociativeScriptObject getImageMetadata() throws Exception {
|
||||
return new AssociativeScriptObject(new ImageMetadata(getMediaFile()));
|
||||
}
|
||||
|
||||
@Define("artist")
|
||||
public String getArtist() {
|
||||
return getMusic().getArtist();
|
||||
|
|
|
@ -4,35 +4,33 @@ 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<String, String> {
|
||||
|
||||
public ImageMetadata(File file) {
|
||||
try {
|
||||
Metadata metadata = ImageMetadataReader.readMetadata(file);
|
||||
public ImageMetadata(File file) throws ImageProcessingException, IOException {
|
||||
Metadata metadata = ImageMetadataReader.readMetadata(file);
|
||||
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package net.filebot.mediainfo;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.*;
|
||||
import static net.filebot.Logging.*;
|
||||
|
||||
import java.io.Closeable;
|
||||
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
|
||||
if (streamKind == StreamKind.Image && streamNumber == 0) {
|
||||
ImageMetadata exif = new ImageMetadata(new File(get(StreamKind.General, 0, "CompleteName")));
|
||||
exif.forEach(streamInfo::putIfAbsent);
|
||||
String path = get(StreamKind.General, 0, "CompleteName");
|
||||
try {
|
||||
ImageMetadata exif = new ImageMetadata(new File(path));
|
||||
exif.forEach(streamInfo::putIfAbsent);
|
||||
} catch (Throwable e) {
|
||||
debug.warning(format("%s: %s", e, path));
|
||||
}
|
||||
}
|
||||
|
||||
return streamInfo;
|
||||
|
|
Loading…
Reference in New Issue