Created
July 25, 2017 03:40
-
-
Save reconbot/5dcf58172e617b6bcd9325c5bc26e2e2 to your computer and use it in GitHub Desktop.
Quick and dirty exif created at time to file modification time copy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const Promise = require('bluebird') | |
const moment = require('moment') | |
const { promisify } = require('util') | |
const touch = promisify(require('touch')) | |
var getExifData = promisify(require('exif').ExifImage) | |
const readdir = promisify(fs.readdir) | |
const stat = promisify(fs.stat) | |
async function main() { | |
const files = await readdir('./') | |
const images = files.filter(file => /\.jpg/.test(file)) | |
const filesWithDate = await Promise.map(images, async (fileName) => { | |
const data = await getExifData(fileName) | |
const statData = await stat(fileName) | |
if (!data.exif.CreateDate) { | |
console.log(fileName, 'has a bad exif created Date') | |
return | |
} | |
const exifCreatedAt = moment(data.exif.CreateDate, 'YYYY:MM:DD HH:mm:ss').toDate() | |
const mtime = moment(statData.mtime) | |
const wrong = !mtime.isSame(exifCreatedAt) | |
const retval = { fileName, exifCreatedAt, exifCreatedAtRaw: data.exif.CreateDate, mtime, wrong } | |
if (wrong) { | |
console.log(retval) | |
await touch(fileName, { time: exifCreatedAt }) | |
} | |
return retval | |
}, { concurrency: 5 }) | |
return 'DONE!' | |
} | |
main().then((data) => { | |
console.log(data) | |
process.exit(0) | |
}, err => { | |
console.error(err) | |
process.exit(1) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment