compare date found in file exif and file name
This commit is contained in:
parent
5f987701c7
commit
4fa3c3d92d
|
@ -159,7 +159,7 @@ export default class finder {
|
||||||
* examine plusieurs propriétés exif de date et retourne la plus ancienne
|
* examine plusieurs propriétés exif de date et retourne la plus ancienne
|
||||||
* @param filepath
|
* @param filepath
|
||||||
*/
|
*/
|
||||||
static findExifCreationDate (filepath) {
|
static async findExifCreationDate (filepath) {
|
||||||
|
|
||||||
console.log('filepath', filepath)
|
console.log('filepath', filepath)
|
||||||
let dateAlreadyInFileName = finder.findFormattedDate(filepath)
|
let dateAlreadyInFileName = finder.findFormattedDate(filepath)
|
||||||
|
@ -168,13 +168,13 @@ export default class finder {
|
||||||
console.log('------ dateAlreadyInFileName', dateAlreadyInFileName)
|
console.log('------ dateAlreadyInFileName', dateAlreadyInFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
exifr.parse(filepath).then(exifData => {
|
await exifr.parse(filepath).then(exifData => {
|
||||||
|
|
||||||
if (exifData) {
|
if (exifData) {
|
||||||
|
|
||||||
let moments = []
|
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) {
|
if (exifData.DateTimeOriginal) {
|
||||||
// console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
|
// console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
|
||||||
moments.push(exifData.DateTimeOriginal)
|
moments.push(exifData.DateTimeOriginal)
|
||||||
|
@ -194,12 +194,10 @@ export default class finder {
|
||||||
moments.push(exifData.FileInodeChangeDateTime)
|
moments.push(exifData.FileInodeChangeDateTime)
|
||||||
}
|
}
|
||||||
if (exifData.FileModificationDateTime) {
|
if (exifData.FileModificationDateTime) {
|
||||||
|
|
||||||
// console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
|
// console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
|
||||||
moments.push(exifData.FileModificationDateTime)
|
moments.push(exifData.FileModificationDateTime)
|
||||||
}
|
}
|
||||||
if (exifData.CreateDate) {
|
if (exifData.CreateDate) {
|
||||||
|
|
||||||
// console.log('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
|
// console.log('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
|
||||||
moments.push(exifData.CreateDate)
|
moments.push(exifData.CreateDate)
|
||||||
}
|
}
|
||||||
|
@ -210,7 +208,10 @@ export default class finder {
|
||||||
})
|
})
|
||||||
let minDate = moment.min(moments)
|
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 {
|
} else {
|
||||||
console.log('pas de exif data')
|
console.log('pas de exif data')
|
||||||
return ''
|
return ''
|
||||||
|
|
|
@ -19,7 +19,7 @@ import {
|
||||||
} from './testFunctions.mjs'
|
} from './testFunctions.mjs'
|
||||||
import finder from './finder.mjs'
|
import finder from './finder.mjs'
|
||||||
|
|
||||||
let mini_arguments;
|
let mini_arguments
|
||||||
console.log(' ')
|
console.log(' ')
|
||||||
|
|
||||||
function parseArguments () {
|
function parseArguments () {
|
||||||
|
@ -29,21 +29,19 @@ function parseArguments () {
|
||||||
|
|
||||||
parseArguments()
|
parseArguments()
|
||||||
|
|
||||||
|
|
||||||
function renameFile (originalFileName, fileMixedNewName) {
|
function renameFile (originalFileName, fileMixedNewName) {
|
||||||
fs.rename(originalFileName, fileMixedNewName, function (err) {
|
fs.rename(originalFileName, fileMixedNewName, function (err) {
|
||||||
if (err) console.log('rename ERROR: ' + err)
|
if (err) console.log('rename ERROR: ' + err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function makeFileNameFromProperties (fileProperties) {
|
function makeFileNameFromProperties (fileProperties) {
|
||||||
|
|
||||||
let tagPlace = '';
|
let tagPlace = ''
|
||||||
if(fileProperties.tags.length){
|
if (fileProperties.tags.length) {
|
||||||
tagPlace = ' ' + tagSectionSeparator + ' '
|
tagPlace = ' ' + tagSectionSeparator + ' '
|
||||||
}
|
}
|
||||||
return finder.cleanSpaces( fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+ ' ' + tagSectionSeparator + ' '+'.' ,'.')
|
return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+' ' + tagSectionSeparator + ' ' + '.', '.')
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendFileName (fileProperties, newText) {
|
function appendFileName (fileProperties, newText) {
|
||||||
|
@ -56,31 +54,37 @@ function prependFileName (fileProperties, newText) {
|
||||||
return fileProperties
|
return fileProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
function guessFileNameOnAllFilesFromArguments(){
|
async function guessFileNameOnAllFilesFromArguments () {
|
||||||
|
|
||||||
// parcourir les dossiers
|
// parcourir les dossiers
|
||||||
// parcourir les fichiers
|
// parcourir les fichiers
|
||||||
|
|
||||||
console.log('liste des fichiers', mini_arguments._)
|
console.log('liste des fichiers', mini_arguments._)
|
||||||
let fileList = mini_arguments._;
|
let fileList = mini_arguments._
|
||||||
|
|
||||||
fileList.forEach(fileName => {
|
fileList.forEach(fileName => {
|
||||||
|
|
||||||
let structureForFile = finder.destructurateFileName(fileName)
|
let structureForFile = finder.destructurateFileName(fileName)
|
||||||
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
|
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
|
||||||
if(!structureForFile.dateStamp){
|
if (!structureForFile.dateStamp) {
|
||||||
let foundDate = finder.findExifCreationDate(fileName)
|
let foundDate = finder.findExifCreationDate(fileName)
|
||||||
if(foundDate){
|
console.log(' =>>>>>>> foundDate : ', foundDate)
|
||||||
structureForFile.dateStamp = (finder.findExifCreationDate(fileName) + '')
|
if (foundDate) {
|
||||||
|
structureForFile.dateStamp = (finder.findExifCreationDate(fileName) + '')
|
||||||
|
|
||||||
|
} else {
|
||||||
|
console.log(' pas de date trouvée dans le nom')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let newname = makeFileNameFromProperties(structureForFile)
|
let newname = makeFileNameFromProperties(structureForFile)
|
||||||
if(fileName !== newname ){
|
if (fileName !== newname) {
|
||||||
|
|
||||||
console.log(' nouveau nom:',newname )
|
console.log(' nouveau nom:', newname)
|
||||||
}else{
|
} else {
|
||||||
console.log(' rien à changer' )
|
console.log(' rien à changer')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -94,6 +98,6 @@ if (enableTestsLocally) {
|
||||||
TestFindFormattedDate()
|
TestFindFormattedDate()
|
||||||
TestScreenShotIsFoundAndRenamed()
|
TestScreenShotIsFoundAndRenamed()
|
||||||
}
|
}
|
||||||
if (reportStatistics || mini_arguments.stats) {
|
if (reportStatistics || mini_arguments.stats) {
|
||||||
finder.reportStatistics()
|
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 |
Loading…
Reference in New Issue