|
|
|
@ -3,6 +3,13 @@ const moment = require('moment')
|
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
|
|
const EXIF_DATE_FORMAT = 'YYYY:MM:DD HH:mm:ssZ'
|
|
|
|
|
|
|
|
|
|
// infer dates from files with a date-looking filename
|
|
|
|
|
const FILENAME_DATE_REGEX = /\d{4}[_\-.\s]?(\d{2}[_\-.\s]?){5}\..{3,4}/
|
|
|
|
|
|
|
|
|
|
// moment ignores non-numeric characters when parsing
|
|
|
|
|
const FILENAME_DATE_FORMAT = 'YYYYMMDD HHmmss'
|
|
|
|
|
|
|
|
|
|
var index = 0
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -13,7 +20,7 @@ function Media (file) {
|
|
|
|
|
this.file = file
|
|
|
|
|
this.filename = path.basename(file.path)
|
|
|
|
|
this.urls = _.mapValues(file.output, o => o.path)
|
|
|
|
|
this.date = exifDate(file)
|
|
|
|
|
this.date = getDate(file)
|
|
|
|
|
this.caption = caption(file)
|
|
|
|
|
this.isVideo = (file.type === 'video')
|
|
|
|
|
this.isAnimated = animated(file)
|
|
|
|
@ -26,13 +33,17 @@ function Media (file) {
|
|
|
|
|
// ]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function exifDate (file) {
|
|
|
|
|
function getDate (file) {
|
|
|
|
|
const date = tagValue(file, 'EXIF', 'DateTimeOriginal') ||
|
|
|
|
|
tagValue(file, 'H264', 'DateTimeOriginal') ||
|
|
|
|
|
tagValue(file, 'QuickTime', 'CreationDate')
|
|
|
|
|
if (date) {
|
|
|
|
|
return moment(date, EXIF_DATE_FORMAT).valueOf()
|
|
|
|
|
} else {
|
|
|
|
|
if (FILENAME_DATE_REGEX.test(file.path)) {
|
|
|
|
|
const namedate = moment(file.path, FILENAME_DATE_FORMAT)
|
|
|
|
|
if (namedate.isValid()) return namedate.valueOf()
|
|
|
|
|
}
|
|
|
|
|
return file.date
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|