diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index a319352b..ae4d6885 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -207,14 +207,17 @@ public class MediaBindingBean { if (infoObject instanceof File) { File f = (File) infoObject; - return new ImageMetadata(f).getDateTaken().map(SimpleDate::new).orElseGet(() -> { - try { - return new SimpleDate(getCreationDate(f)); - } catch (Exception e) { - debug.warning(e::toString); - } - return null; - }); + try { + return new ImageMetadata(f).getDateTaken().map(SimpleDate::new).get(); + } catch (Exception e) { + // ignore and default to file creation date + } + + try { + return new SimpleDate(getCreationDate(f)); + } catch (Exception e) { + debug.warning(e::toString); + } } return null; diff --git a/source/net/filebot/mediainfo/ImageMetadata.java b/source/net/filebot/mediainfo/ImageMetadata.java index 3385fb09..9a40f4c6 100644 --- a/source/net/filebot/mediainfo/ImageMetadata.java +++ b/source/net/filebot/mediainfo/ImageMetadata.java @@ -32,28 +32,24 @@ import net.filebot.util.FileUtilities.ExtensionFileFilter; public class ImageMetadata { - private File file; - private Metadata metadata; + private final Metadata metadata; - public ImageMetadata(File file) { - this.file = file; - } - - protected synchronized Metadata getMetadata() throws ImageProcessingException, IOException { - if (metadata == null) { - metadata = ImageMetadataReader.readMetadata(file); + public ImageMetadata(File file) throws ImageProcessingException, IOException { + if (SUPPORTED_FILE_TYPES.accept(file)) { + throw new IllegalArgumentException("Image type not supported: " + file); } - return metadata; + + metadata = ImageMetadataReader.readMetadata(file); } protected boolean accept(Directory directory) { return !directory.getName().matches("JPEG|JFIF|Interoperability|Huffman|File"); } - public Map snapshot(Function key) throws ImageProcessingException, IOException { + public Map snapshot(Function key) { Map values = new LinkedHashMap(); - for (Directory directory : getMetadata().getDirectories()) { + for (Directory directory : metadata.getDirectories()) { if (accept(directory)) { for (Tag tag : directory.getTags()) { String v = tag.getDescription(); @@ -131,17 +127,15 @@ public class ImageMetadata { country, administrative_area_level_1, administrative_area_level_2, administrative_area_level_3, administrative_area_level_4, sublocality, neighborhood, route; } - protected Optional extract(Function extract) { - if (SUPPORTED_FILE_TYPES.accept(file)) { - try { - return Optional.ofNullable(extract.apply(getMetadata())); - } catch (Exception e) { - debug.warning(e::toString); - } + public Optional extract(Function extract) { + try { + return Optional.ofNullable(extract.apply(metadata)); + } catch (Exception e) { + debug.warning(e::toString); } return Optional.empty(); } - public static final FileFilter SUPPORTED_FILE_TYPES = new ExtensionFileFilter("jpg", "jpeg", "png", "webp", "gif", "ico", "bmp", "tiff", "psd", "pcx", "raw", "crw", "cr2", "nef", "orf", "raf", "rw2", "rwl", "srw", "arw", "dng", "x3f", "mov", "mp4", "m4v", "3g2", "3gp", "3gp"); + public static final FileFilter SUPPORTED_FILE_TYPES = new ExtensionFileFilter("jpg", "jpeg", "png", "webp", "gif", "ico", "bmp", "tif", "tiff", "psd", "pcx", "raw", "crw", "cr2", "nef", "orf", "raf", "rw2", "rwl", "srw", "arw", "dng", "x3f", "mov", "mp4", "m4v", "3g2", "3gp", "3gp"); }