Added {dt} timestamp binding

This commit is contained in:
Reinhard Pointner 2017-02-27 04:48:39 +08:00
parent 40bab4a1fb
commit d6a8dfc00e
2 changed files with 24 additions and 13 deletions

View File

@ -14,6 +14,8 @@ 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;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -548,6 +550,10 @@ public class ExpressionFormatMethods {
return Stream.of(DefaultGroovyMethods.min(self), DefaultGroovyMethods.max(self)).filter(Objects::nonNull).distinct().collect(toList()); return Stream.of(DefaultGroovyMethods.min(self), DefaultGroovyMethods.max(self)).filter(Objects::nonNull).distinct().collect(toList());
} }
public static String format(Temporal self, String pattern) {
return DateTimeFormatter.ofPattern(pattern).format(self);
}
/** /**
* Episode utilities (EXPERIMENTAL) * Episode utilities (EXPERIMENTAL)
*/ */

View File

@ -202,22 +202,27 @@ 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(getTimeStamp());
return null;
}
@Define("dt")
public ZonedDateTime getTimeStamp() {
File f = getMediaFile();
// 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
if (infoObject instanceof File) { try {
File f = (File) infoObject; return new ImageMetadata(f).getDateTaken().get();
} catch (Exception e) {
// ignore and default to file creation date
}
try { try {
return new ImageMetadata(f).getDateTaken().map(SimpleDate::new).get(); return Instant.ofEpochMilli(getCreationDate(f)).atZone(ZoneOffset.systemDefault());
} catch (Exception e) { } catch (Exception e) {
// ignore and default to file creation date debug.warning(e::toString);
}
try {
return new SimpleDate(getCreationDate(f));
} catch (Exception e) {
debug.warning(e::toString);
}
} }
return null; return null;