compare date found in file exif and file name

This commit is contained in:
Tykayn 2023-06-29 19:49:58 +02:00 committed by tykayn
parent 5f987701c7
commit 4fa3c3d92d
5 changed files with 28 additions and 23 deletions

View File

@ -159,7 +159,7 @@ export default class finder {
* examine plusieurs propriétés exif de date et retourne la plus ancienne
* @param filepath
*/
static findExifCreationDate (filepath) {
static async findExifCreationDate (filepath) {
console.log('filepath', filepath)
let dateAlreadyInFileName = finder.findFormattedDate(filepath)
@ -168,13 +168,13 @@ export default class finder {
console.log('------ dateAlreadyInFileName', dateAlreadyInFileName)
}
exifr.parse(filepath).then(exifData => {
await exifr.parse(filepath).then(exifData => {
if (exifData) {
let moments = []
console.log('exif data : ', exifData) // Do something with your data!
// console.log('exif data : ', exifData) // Do something with your data!
if (exifData.DateTimeOriginal) {
// console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
moments.push(exifData.DateTimeOriginal)
@ -194,12 +194,10 @@ export default class finder {
moments.push(exifData.FileInodeChangeDateTime)
}
if (exifData.FileModificationDateTime) {
// 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)
}
@ -210,7 +208,10 @@ export default class finder {
})
let minDate = moment.min(moments)
return minDate.format('Y-M-DTH:i:s')
// console.log('minDate :::::::::', minDate)
console.log('minDate :::::::::', minDate.format('yyyy-MM-DDTHH:mm:ss'))
return minDate.format('yyyy-MM-DDTHH:mm:ss')
} else {
console.log('pas de exif data')
return ''

View File

@ -19,7 +19,7 @@ import {
} from './testFunctions.mjs'
import finder from './finder.mjs'
let mini_arguments;
let mini_arguments
console.log(' ')
function parseArguments () {
@ -29,17 +29,15 @@ function parseArguments () {
parseArguments()
function renameFile (originalFileName, fileMixedNewName) {
fs.rename(originalFileName, fileMixedNewName, function (err) {
if (err) console.log('rename ERROR: ' + err)
})
}
function makeFileNameFromProperties (fileProperties) {
let tagPlace = '';
let tagPlace = ''
if (fileProperties.tags.length) {
tagPlace = ' ' + tagSectionSeparator + ' '
}
@ -56,24 +54,28 @@ function prependFileName (fileProperties, newText) {
return fileProperties
}
function guessFileNameOnAllFilesFromArguments(){
async function guessFileNameOnAllFilesFromArguments () {
// parcourir les dossiers
// parcourir les fichiers
console.log('liste des fichiers', mini_arguments._)
let fileList = mini_arguments._;
let fileList = mini_arguments._
fileList.forEach(fileName => {
let structureForFile = finder.destructurateFileName(fileName)
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
if (!structureForFile.dateStamp) {
let foundDate = finder.findExifCreationDate(fileName)
console.log(' =>>>>>>> foundDate : ', foundDate)
if (foundDate) {
structureForFile.dateStamp = (finder.findExifCreationDate(fileName) + '')
}
}
} else {
console.log(' pas de date trouvée dans le nom')
}
}
let newname = makeFileNameFromProperties(structureForFile)
if (fileName !== newname) {
@ -81,6 +83,8 @@ function guessFileNameOnAllFilesFromArguments(){
} else {
console.log(' rien à changer')
}
})
}
@ -94,6 +98,6 @@ if (enableTestsLocally) {
TestFindFormattedDate()
TestScreenShotIsFoundAndRenamed()
}
if (reportStatistics || mini_arguments.stats) {
if (reportStatistics || mini_arguments.stats) {
finder.reportStatistics()
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 43 KiB