mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-11 20:05:04 -05:00
Refactor local datasources (exif, xattr, file)
This commit is contained in:
parent
b425ab6d42
commit
7ab9bb779c
@ -223,7 +223,7 @@ public class MediaBindingBean {
|
|||||||
|
|
||||||
// try EXIF Date-Taken for image files or File Last-Modified for generic files
|
// try EXIF Date-Taken for image files or File Last-Modified for generic files
|
||||||
try {
|
try {
|
||||||
return new ImageMetadata(f).getDateTaken().get();
|
return getPhoto().getDateTaken().get();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// ignore and default to file creation date
|
// ignore and default to file creation date
|
||||||
}
|
}
|
||||||
@ -895,17 +895,17 @@ public class MediaBindingBean {
|
|||||||
|
|
||||||
@Define("exif")
|
@Define("exif")
|
||||||
public AssociativeScriptObject getImageMetadata() throws Exception {
|
public AssociativeScriptObject getImageMetadata() throws Exception {
|
||||||
return new AssociativeScriptObject(new ImageMetadata(getMediaFile()).snapshot());
|
return new AssociativeScriptObject(getPhoto().snapshot());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("camera")
|
@Define("camera")
|
||||||
public AssociativeEnumObject getCamera() throws Exception {
|
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")
|
@Define("location")
|
||||||
public AssociativeEnumObject getLocation() throws Exception {
|
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")
|
@Define("artist")
|
||||||
@ -943,6 +943,11 @@ public class MediaBindingBean {
|
|||||||
return (AudioTrack) infoObject;
|
return (AudioTrack) infoObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Define("photo")
|
||||||
|
public ImageMetadata getPhoto() throws Exception {
|
||||||
|
return new ImageMetadata((File) infoObject);
|
||||||
|
}
|
||||||
|
|
||||||
@Define("pi")
|
@Define("pi")
|
||||||
public Integer getPart() {
|
public Integer getPart() {
|
||||||
if (infoObject instanceof AudioTrack)
|
if (infoObject instanceof AudioTrack)
|
||||||
|
@ -27,6 +27,7 @@ import com.drew.metadata.Tag;
|
|||||||
import com.drew.metadata.exif.ExifIFD0Directory;
|
import com.drew.metadata.exif.ExifIFD0Directory;
|
||||||
import com.drew.metadata.exif.ExifSubIFDDirectory;
|
import com.drew.metadata.exif.ExifSubIFDDirectory;
|
||||||
import com.drew.metadata.exif.GpsDirectory;
|
import com.drew.metadata.exif.GpsDirectory;
|
||||||
|
import com.drew.metadata.file.FileSystemDirectory;
|
||||||
|
|
||||||
import net.filebot.Cache;
|
import net.filebot.Cache;
|
||||||
import net.filebot.CacheType;
|
import net.filebot.CacheType;
|
||||||
@ -69,6 +70,10 @@ public class ImageMetadata {
|
|||||||
return values;
|
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() {
|
public Optional<ZonedDateTime> getDateTaken() {
|
||||||
return extract(m -> m.getFirstDirectoryOfType(ExifIFD0Directory.class)).map(d -> d.getDate(ExifSubIFDDirectory.TAG_DATETIME)).map(d -> {
|
return extract(m -> m.getFirstDirectoryOfType(ExifIFD0Directory.class)).map(d -> d.getDate(ExifSubIFDDirectory.TAG_DATETIME)).map(d -> {
|
||||||
return d.toInstant().atZone(ZoneOffset.UTC);
|
return d.toInstant().atZone(ZoneOffset.UTC);
|
||||||
|
@ -10,8 +10,8 @@ import net.filebot.util.FileUtilities;
|
|||||||
public class FileNameFormat extends Format {
|
public class FileNameFormat extends Format {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
|
public StringBuffer format(Object obj, StringBuffer sb, FieldPosition pos) {
|
||||||
return toAppendTo.append(FileUtilities.getName((File) obj));
|
return sb.append(FileUtilities.getName((File) obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user