diff --git a/rangement/configs.mjs b/rangement/configs.mjs index eecef525..0ec87b41 100644 --- a/rangement/configs.mjs +++ b/rangement/configs.mjs @@ -2,5 +2,5 @@ export const tagSeparator = ' ' export const tagSectionSeparator = '--' export const enableTestsLocally = false -export const reportStatistics = true +export const reportStatistics = false export const version = '1.0.0' \ No newline at end of file diff --git a/rangement/finder.mjs b/rangement/finder.mjs index c8818b7d..20bb1e0a 100644 --- a/rangement/finder.mjs +++ b/rangement/finder.mjs @@ -163,7 +163,10 @@ export default class finder { console.log('filepath', filepath) let dateAlreadyInFileName = finder.findFormattedDate(filepath) + if(dateAlreadyInFileName){ + console.log('------ dateAlreadyInFileName', dateAlreadyInFileName) + } exifr.parse(filepath).then(exifData => { @@ -171,17 +174,25 @@ export default class finder { 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) } + if (exifData.ModificationDateTime) { + // console.log('image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data! + moments.push(exifData.ModificationDateTime) + } if (exifData.ModifyDate) { - - // console.log('image modifiée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data! + // console.log('image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data! moments.push(exifData.ModifyDate) } + if (exifData.FileAccessDateTime) { + moments.push(exifData.FileAccessDateTime) + } + if (exifData.FileInodeChangeDateTime) { + moments.push(exifData.FileInodeChangeDateTime) + } if (exifData.FileModificationDateTime) { // console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data! @@ -199,12 +210,15 @@ export default class finder { }) let minDate = moment.min(moments) - return minDate + return minDate.format('Y-M-DTH:i:s') } else { console.log('pas de exif data') - return null + return '' } - }).catch(error => console.log('Error: ' + error.message)) + }).catch(error => { + console.log('/////////// Error in reading exif of file: ' + error.message) + return '' + }) } } \ No newline at end of file diff --git a/rangement/index.mjs b/rangement/index.mjs index 2ee2af1c..f7641945 100644 --- a/rangement/index.mjs +++ b/rangement/index.mjs @@ -24,7 +24,7 @@ console.log(' ') function parseArguments () { mini_arguments = minimist(process.argv.slice(2)) - // console.log('arguments', mini_arguments) + console.log('arguments', mini_arguments) } parseArguments() @@ -38,7 +38,12 @@ function renameFile (originalFileName, fileMixedNewName) { function makeFileNameFromProperties (fileProperties) { - return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + ' ' + tagSectionSeparator + ' ' + fileProperties.tags.join(tagSeparator) + fileProperties.extension) + + let tagPlace = ''; + if(fileProperties.tags.length){ + tagPlace = ' ' + tagSectionSeparator + ' ' + } + return finder.cleanSpaces( fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+ ' ' + tagSectionSeparator + ' '+'.' ,'.') } function appendFileName (fileProperties, newText) { @@ -51,6 +56,37 @@ function prependFileName (fileProperties, newText) { return fileProperties } +function guessFileNameOnAllFilesFromArguments(){ + + // parcourir les dossiers + // parcourir les fichiers + + console.log('liste des fichiers', 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) + if(foundDate){ + structureForFile.dateStamp = (finder.findExifCreationDate(fileName) + '') + } + } + + let newname = makeFileNameFromProperties(structureForFile) + if(fileName !== newname ){ + + console.log(' nouveau nom:',newname ) + }else{ + console.log(' rien à changer' ) + } + }) + +} + +guessFileNameOnAllFilesFromArguments() + // run tests if (enableTestsLocally) { @@ -60,4 +96,4 @@ if (enableTestsLocally) { } if (reportStatistics || mini_arguments.stats) { finder.reportStatistics() -} \ No newline at end of file +} diff --git a/rangement/testFiles/received_582637990728055.webp b/rangement/testFiles/received_582637990728055.webp new file mode 100644 index 00000000..71eedad5 Binary files /dev/null and b/rangement/testFiles/received_582637990728055.webp differ diff --git a/rangement/testFiles/tempFileForShare_20210910-004429.jpg b/rangement/testFiles/tempFileForShare_20210910-004429.jpg new file mode 100755 index 00000000..10a9808b Binary files /dev/null and b/rangement/testFiles/tempFileForShare_20210910-004429.jpg differ diff --git a/rangement/testFiles/un_document.pdf b/rangement/testFiles/un_document.pdf new file mode 100644 index 00000000..e69de29b diff --git a/rangement/testFiles/une_photo.jpg b/rangement/testFiles/une_photo.jpg new file mode 100644 index 00000000..e69de29b diff --git a/rangement/testFiles/une_photo_pas_pareil.jpg b/rangement/testFiles/une_photo_pas_pareil.jpg new file mode 100644 index 00000000..e69de29b diff --git a/rangement/testFiles/une_photo_pas_pareil.png b/rangement/testFiles/une_photo_pas_pareil.png new file mode 100644 index 00000000..e69de29b