1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Refactor local datasources (exif, xattr, file)

This commit is contained in:
Reinhard Pointner 2018-08-04 17:48:41 +07:00
parent b425ab6d42
commit 7ab9bb779c
3 changed files with 16 additions and 6 deletions

View File

@ -223,7 +223,7 @@ public class MediaBindingBean {
// try EXIF Date-Taken for image files or File Last-Modified for generic files
try {
return new ImageMetadata(f).getDateTaken().get();
return getPhoto().getDateTaken().get();
} catch (Exception e) {
// ignore and default to file creation date
}
@ -895,17 +895,17 @@ public class MediaBindingBean {
@Define("exif")
public AssociativeScriptObject getImageMetadata() throws Exception {
return new AssociativeScriptObject(new ImageMetadata(getMediaFile()).snapshot());
return new AssociativeScriptObject(getPhoto().snapshot());
}
@Define("camera")
public AssociativeEnumObject getCamera() throws Exception {
return new ImageMetadata(getMediaFile()).getCameraModel().map(AssociativeEnumObject::new).orElse(null);
return getPhoto().getCameraModel().map(AssociativeEnumObject::new).orElse(null);
}
@Define("location")
public AssociativeEnumObject getLocation() throws Exception {
return new ImageMetadata(getMediaFile()).getLocationTaken().map(AssociativeEnumObject::new).orElse(null);
return getPhoto().getLocationTaken().map(AssociativeEnumObject::new).orElse(null);
}
@Define("artist")
@ -943,6 +943,11 @@ public class MediaBindingBean {
return (AudioTrack) infoObject;
}
@Define("photo")
public ImageMetadata getPhoto() throws Exception {
return new ImageMetadata((File) infoObject);
}
@Define("pi")
public Integer getPart() {
if (infoObject instanceof AudioTrack)

View File

@ -27,6 +27,7 @@ import com.drew.metadata.Tag;
import com.drew.metadata.exif.ExifIFD0Directory;
import com.drew.metadata.exif.ExifSubIFDDirectory;
import com.drew.metadata.exif.GpsDirectory;
import com.drew.metadata.file.FileSystemDirectory;
import net.filebot.Cache;
import net.filebot.CacheType;
@ -69,6 +70,10 @@ public class ImageMetadata {
return values;
}
public Optional<String> getName() {
return extract(m -> m.getFirstDirectoryOfType(FileSystemDirectory.class)).map(d -> d.getString(FileSystemDirectory.TAG_FILE_NAME));
}
public Optional<ZonedDateTime> getDateTaken() {
return extract(m -> m.getFirstDirectoryOfType(ExifIFD0Directory.class)).map(d -> d.getDate(ExifSubIFDDirectory.TAG_DATETIME)).map(d -> {
return d.toInstant().atZone(ZoneOffset.UTC);

View File

@ -10,8 +10,8 @@ import net.filebot.util.FileUtilities;
public class FileNameFormat extends Format {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
return toAppendTo.append(FileUtilities.getName((File) obj));
public StringBuffer format(Object obj, StringBuffer sb, FieldPosition pos) {
return sb.append(FileUtilities.getName((File) obj));
}
@Override