{d} and {y} now evaluate to Exif Date-Taken if possible when dealing with generic files
This commit is contained in:
parent
86b7c4e4fd
commit
bd826cb297
|
@ -35,7 +35,7 @@
|
||||||
<classpathentry kind="lib" path="lib/jars/AppleJavaExtensions.jar"/>
|
<classpathentry kind="lib" path="lib/jars/AppleJavaExtensions.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/controlsfx.jar" sourcepath="lib/ivy/source/controlsfx.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/controlsfx.jar" sourcepath="lib/ivy/source/controlsfx.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/lanterna.jar" sourcepath="lib/ivy/source/lanterna.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/lanterna.jar" sourcepath="lib/ivy/source/lanterna.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/metadata-extractor.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/metadata-extractor.jar" sourcepath="lib/ivy/source/metadata-extractor.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/ivy/jar/xmpcore.jar"/>
|
<classpathentry kind="lib" path="lib/ivy/jar/xmpcore.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
@ -10,7 +10,6 @@ import static net.filebot.media.MediaDetection.*;
|
||||||
import static net.filebot.util.RegularExpressions.*;
|
import static net.filebot.util.RegularExpressions.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.attribute.BasicFileAttributeView;
|
import java.nio.file.attribute.BasicFileAttributeView;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
@ -505,7 +504,7 @@ public class ExpressionFormatMethods {
|
||||||
return creationDate;
|
return creationDate;
|
||||||
}
|
}
|
||||||
return attr.lastModifiedTime().toMillis();
|
return attr.lastModifiedTime().toMillis();
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,10 +125,8 @@ public class MediaBindingBean {
|
||||||
return getEpisode().getSeriesInfo().getStartDate().getYear();
|
return getEpisode().getSeriesInfo().getStartDate().getYear();
|
||||||
if (infoObject instanceof Movie)
|
if (infoObject instanceof Movie)
|
||||||
return getMovie().getYear();
|
return getMovie().getYear();
|
||||||
if (infoObject instanceof AudioTrack)
|
|
||||||
return getMusic().getAlbumReleaseDate().getYear();
|
|
||||||
|
|
||||||
return null;
|
return getReleaseDate().getYear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Define("ny")
|
@Define("ny")
|
||||||
|
@ -204,8 +202,21 @@ public class MediaBindingBean {
|
||||||
return getMovieInfo().getReleased();
|
return getMovieInfo().getReleased();
|
||||||
if (infoObject instanceof AudioTrack)
|
if (infoObject instanceof AudioTrack)
|
||||||
return getMusic().getAlbumReleaseDate();
|
return getMusic().getAlbumReleaseDate();
|
||||||
if (infoObject instanceof File)
|
|
||||||
return new SimpleDate(getCreationDate(((File) infoObject)));
|
// try EXIF Date-Taken for image files or File Last-Modified for generic files
|
||||||
|
if (infoObject instanceof File) {
|
||||||
|
File f = (File) infoObject;
|
||||||
|
|
||||||
|
ZonedDateTime d = ImageMetadata.getDateTaken(f);
|
||||||
|
if (d != null) {
|
||||||
|
return new SimpleDate(d);
|
||||||
|
}
|
||||||
|
|
||||||
|
long t = getCreationDate(f);
|
||||||
|
if (t > 0) {
|
||||||
|
return new SimpleDate(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,11 @@ import static net.filebot.Logging.*;
|
||||||
import static net.filebot.similarity.Normalization.*;
|
import static net.filebot.similarity.Normalization.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
|
||||||
import com.drew.imaging.ImageMetadataReader;
|
import com.drew.imaging.ImageMetadataReader;
|
||||||
|
@ -12,6 +16,10 @@ import com.drew.imaging.ImageProcessingException;
|
||||||
import com.drew.metadata.Directory;
|
import com.drew.metadata.Directory;
|
||||||
import com.drew.metadata.Metadata;
|
import com.drew.metadata.Metadata;
|
||||||
import com.drew.metadata.Tag;
|
import com.drew.metadata.Tag;
|
||||||
|
import com.drew.metadata.exif.ExifIFD0Directory;
|
||||||
|
import com.drew.metadata.exif.ExifSubIFDDirectory;
|
||||||
|
|
||||||
|
import net.filebot.util.FileUtilities.ExtensionFileFilter;
|
||||||
|
|
||||||
public class ImageMetadata extends LinkedHashMap<String, String> {
|
public class ImageMetadata extends LinkedHashMap<String, String> {
|
||||||
|
|
||||||
|
@ -34,4 +42,24 @@ public class ImageMetadata extends LinkedHashMap<String, String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ZonedDateTime getDateTaken(File file) {
|
||||||
|
if (SUPPORTED_FILE_TYPES.accept(file)) {
|
||||||
|
try {
|
||||||
|
Metadata metadata = ImageMetadataReader.readMetadata(file);
|
||||||
|
ExifIFD0Directory directory = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
|
||||||
|
Date date = directory.getDate(ExifSubIFDDirectory.TAG_DATETIME);
|
||||||
|
|
||||||
|
if (date != null) {
|
||||||
|
return date.toInstant().atZone(ZoneOffset.UTC);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
debug.warning(e::toString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue