find oldest date in exif data
This commit is contained in:
parent
00207c8e39
commit
98487704f3
@ -2,7 +2,7 @@ import fs from 'node-fs'
|
|||||||
// list.map(folder => {
|
// list.map(folder => {
|
||||||
// getExifCreationDate(filepath)
|
// getExifCreationDate(filepath)
|
||||||
// })
|
// })
|
||||||
import exif from 'node-exif'
|
import exifr from 'exifr'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
|
|
||||||
const pathFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher'
|
const pathFolder = '/home/poule/encrypted/stockage-syncable/photos/a_dispatcher'
|
||||||
@ -24,47 +24,55 @@ function convertDateToTimeInFileName (inputDate) {
|
|||||||
return inputDate.replace(' ', 'T')
|
return inputDate.replace(' ', 'T')
|
||||||
}
|
}
|
||||||
|
|
||||||
function getExifCreationDate (filepath) {
|
function findFormattedDate(inputString){
|
||||||
console.log('filepath', filepath)
|
|
||||||
try {
|
|
||||||
new exif.ExifImage({ image: filepath }, function (error, exifData) {
|
|
||||||
if (error) {
|
|
||||||
|
|
||||||
console.log(exifData)
|
return inputString.match(/^[0-9]{4}-?[0-9]{2}-?[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/)
|
||||||
console.log('Error: ' + error.message)
|
}
|
||||||
} else if (exifData) {
|
function getExifCreationDate (filepath) {
|
||||||
|
|
||||||
|
console.log('filepath', filepath)
|
||||||
|
|
||||||
|
exifr.parse(filepath).then(exifData => {
|
||||||
|
|
||||||
|
if (exifData) {
|
||||||
|
|
||||||
let moments = []
|
let moments = []
|
||||||
moments = moments.map(d => moment(d))
|
|
||||||
|
|
||||||
console.log('exif data : ', exifData) // Do something with your data!
|
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!
|
// console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
|
||||||
moments.push(exifData.exif.DateTimeOriginal)
|
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!
|
// console.log('image modifiée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data!
|
||||||
moments.push(exifData.exif.FileModificationDateTime)
|
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!
|
// console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
|
||||||
moments.push(exifData.exif.CreateDate)
|
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)
|
let minDate = moment.min(moments)
|
||||||
|
|
||||||
console.log('minDate', minDate)
|
|
||||||
return minDate
|
return minDate
|
||||||
} else {
|
} else {
|
||||||
console.log('pas de exif data')
|
console.log('pas de exif data')
|
||||||
return null
|
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)
|
// let list = getDirectories(pathFolder)
|
||||||
console.log('list', list)
|
// 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 creationDateFound = getExifCreationDate(pathFolder + '/' + originalFileName)
|
||||||
let convertedToName = ''
|
let convertedToName = ''
|
||||||
if (creationDateFound) {
|
if (creationDateFound) {
|
||||||
@ -110,3 +121,6 @@ const patternsFiles = {
|
|||||||
'open_camera': '^IMG_OC', // IMG_OC_20230617_092120_3.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
|
'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')
|
||||||
|
Loading…
Reference in New Issue
Block a user