find oldest date in exif data

This commit is contained in:
Tykayn 2023-06-27 16:06:22 +02:00 committed by tykayn
parent 00207c8e39
commit 98487704f3
1 changed files with 42 additions and 28 deletions

View File

@ -2,7 +2,7 @@ import fs from 'node-fs'
// list.map(folder => {
// getExifCreationDate(filepath)
// })
import exif from 'node-exif'
import exifr from 'exifr'
import moment from 'moment'
const pathFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher'
@ -24,47 +24,55 @@ function convertDateToTimeInFileName (inputDate) {
return inputDate.replace(' ', 'T')
}
function getExifCreationDate (filepath) {
console.log('filepath', filepath)
try {
new exif.ExifImage({ image: filepath }, function (error, exifData) {
if (error) {
function findFormattedDate(inputString){
console.log(exifData)
console.log('Error: ' + error.message)
} else if (exifData) {
return inputString.match(/^[0-9]{4}-?[0-9]{2}-?[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/)
}
function getExifCreationDate (filepath) {
console.log('filepath', filepath)
exifr.parse(filepath).then(exifData => {
if (exifData) {
let moments = []
moments = moments.map(d => moment(d))
console.log('exif data : ', exifData) // Do something with your data!
if (exifData.exif.DateTimeOriginal) {
if (exifData.DateTimeOriginal) {
console.log('image créée le : DateTimeOriginal : ', exifData.exif.DateTimeOriginal) // Do something with your data!
moments.push(exifData.exif.DateTimeOriginal)
// console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
moments.push(exifData.DateTimeOriginal)
}
if (exifData.exif.FileModificationDateTime) {
if (exifData.ModifyDate) {
console.log('image créée le : FileModificationDateTime : ', exifData.exif.FileModificationDateTime) // Do something with your data!
moments.push(exifData.exif.FileModificationDateTime)
// console.log('image modifiée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data!
moments.push(exifData.ModifyDate)
}
if (exifData.exif.CreateDate) {
if (exifData.FileModificationDateTime) {
console.log('image créée le : CreateDate : ', exifData.exif.CreateDate) // Do something with your data!
moments.push(exifData.exif.CreateDate)
// console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
moments.push(exifData.FileModificationDateTime)
}
if (exifData.CreateDate) {
// console.log('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
moments.push(exifData.CreateDate)
}
moments = moments.map(d => {
let newdate = moment(d)
return newdate
})
let minDate = moment.min(moments)
console.log('minDate', minDate)
return minDate
} else {
console.log('pas de exif data')
return null
}
})
} catch (error) {
console.log('Error: ' + error.message)
}
}).catch(error => console.log('Error: ' + error.message))
}
/**
@ -85,10 +93,13 @@ function renameFile (originalFileName, fileMixedNewName) {
})
}
let list = getDirectories(pathFolder)
console.log('list', list)
// let list = getDirectories(pathFolder)
// console.log('list', list)
let originalFileName = '2023-06-23T08.55.05.jpg'
let formattedDatePIMBefore = findFormattedDate(originalFileName)
console.log('formattedDatePIMBefore', formattedDatePIMBefore)
let originalFileName = 'FzPHzOrWcAE6ALV.jpg'
let creationDateFound = getExifCreationDate(pathFolder + '/' + originalFileName)
let convertedToName = ''
if (creationDateFound) {
@ -109,4 +120,7 @@ const patternsFiles = {
'telegram_pic': '', // -4900281569878475578_1109.jpg
'open_camera': '^IMG_OC', // IMG_OC_20230617_092120_3.jpg
'screenshot': '^Screenshot', // Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png
}
}
getExifCreationDate('/home/poule/encrypted/stockage-syncable/photos/a_dispatcher/2023-06-23T18.36.47.jpg')