mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-10 06:20:27 -04:00
Refactor ImageMetadata API
This commit is contained in:
parent
8b79c595f3
commit
c16dbc3741
@ -207,14 +207,17 @@ public class MediaBindingBean {
|
|||||||
if (infoObject instanceof File) {
|
if (infoObject instanceof File) {
|
||||||
File f = (File) infoObject;
|
File f = (File) infoObject;
|
||||||
|
|
||||||
return new ImageMetadata(f).getDateTaken().map(SimpleDate::new).orElseGet(() -> {
|
try {
|
||||||
try {
|
return new ImageMetadata(f).getDateTaken().map(SimpleDate::new).get();
|
||||||
return new SimpleDate(getCreationDate(f));
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
// ignore and default to file creation date
|
||||||
debug.warning(e::toString);
|
}
|
||||||
}
|
|
||||||
return null;
|
try {
|
||||||
});
|
return new SimpleDate(getCreationDate(f));
|
||||||
|
} catch (Exception e) {
|
||||||
|
debug.warning(e::toString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -32,28 +32,24 @@ import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
|||||||
|
|
||||||
public class ImageMetadata {
|
public class ImageMetadata {
|
||||||
|
|
||||||
private File file;
|
private final Metadata metadata;
|
||||||
private Metadata metadata;
|
|
||||||
|
|
||||||
public ImageMetadata(File file) {
|
public ImageMetadata(File file) throws ImageProcessingException, IOException {
|
||||||
this.file = file;
|
if (SUPPORTED_FILE_TYPES.accept(file)) {
|
||||||
}
|
throw new IllegalArgumentException("Image type not supported: " + file);
|
||||||
|
|
||||||
protected synchronized Metadata getMetadata() throws ImageProcessingException, IOException {
|
|
||||||
if (metadata == null) {
|
|
||||||
metadata = ImageMetadataReader.readMetadata(file);
|
|
||||||
}
|
}
|
||||||
return metadata;
|
|
||||||
|
metadata = ImageMetadataReader.readMetadata(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean accept(Directory directory) {
|
protected boolean accept(Directory directory) {
|
||||||
return !directory.getName().matches("JPEG|JFIF|Interoperability|Huffman|File");
|
return !directory.getName().matches("JPEG|JFIF|Interoperability|Huffman|File");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> snapshot(Function<Tag, String> key) throws ImageProcessingException, IOException {
|
public Map<String, String> snapshot(Function<Tag, String> key) {
|
||||||
Map<String, String> values = new LinkedHashMap<String, String>();
|
Map<String, String> values = new LinkedHashMap<String, String>();
|
||||||
|
|
||||||
for (Directory directory : getMetadata().getDirectories()) {
|
for (Directory directory : metadata.getDirectories()) {
|
||||||
if (accept(directory)) {
|
if (accept(directory)) {
|
||||||
for (Tag tag : directory.getTags()) {
|
for (Tag tag : directory.getTags()) {
|
||||||
String v = tag.getDescription();
|
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;
|
country, administrative_area_level_1, administrative_area_level_2, administrative_area_level_3, administrative_area_level_4, sublocality, neighborhood, route;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> Optional<T> extract(Function<Metadata, T> extract) {
|
public <T> Optional<T> extract(Function<Metadata, T> extract) {
|
||||||
if (SUPPORTED_FILE_TYPES.accept(file)) {
|
try {
|
||||||
try {
|
return Optional.ofNullable(extract.apply(metadata));
|
||||||
return Optional.ofNullable(extract.apply(getMetadata()));
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
debug.warning(e::toString);
|
||||||
debug.warning(e::toString);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user