diff --git a/configs.mjs b/configs.mjs index aa93229..da79b8f 100644 --- a/configs.mjs +++ b/configs.mjs @@ -1,8 +1,9 @@ class config_rangement { log_level = 'info' // 'debug' | 'warn' |'info' version = '1.0.0' - tagSeparator = '1.0.0' - tagSectionSeparator = '1.0.0' + iso_date_format = 'yyyy-MM-DDTHH.mm.ss' // target format for dates in file names + tagSeparator = ' ' + tagSectionSeparator = '--' keepFreeText = true keepTags = true replaceUnderscoreWithSpaces = true @@ -41,6 +42,7 @@ class config_rangement { 'auto_sort_folder': 'photos/captures écran screenshots' }, } + ; } const rangement_instance = new config_rangement(); diff --git a/finder.mjs b/finder.mjs index 1a41ecc..6f366cc 100644 --- a/finder.mjs +++ b/finder.mjs @@ -1,10 +1,11 @@ /** * la classe qui repère des patterns */ -import rangement_instance , { tagSectionSeparator, tagSeparator} from './configs.mjs' +import rangement_instance from './configs.mjs' import exifr from 'exifr' import moment from 'moment' import log from "loglevel"; + log.setLevel(rangement_instance.log_level) @@ -27,7 +28,7 @@ export default class finder { } static findFormattedDate (filepath) { - let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ig) + let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}/ig) log.debug(' finder - match findFormattedDate', match) let result = '' if (match && match[0]) { @@ -48,7 +49,7 @@ export default class finder { */ static findFileNameFreeTextPart (fileName) { fileName = fileName.replace(this.findFileExtension(fileName), '') - let boom = fileName.split(tagSectionSeparator) + let boom = fileName.split(rangement_instance.tagSectionSeparator) if (boom.length) { let freeTextPart = boom[0].trim() log.debug(' finder - freeTextPart', freeTextPart) @@ -76,15 +77,15 @@ export default class finder { inputString = inputString.replace(extensionFile, '') log.debug(' finder - extensionFile', extensionFile) - if (inputString.includes(tagSectionSeparator)) { + if (inputString.includes(rangement_instance.tagSectionSeparator)) { log.debug(' finder - inputString', inputString) if (inputString.length) { - let boom = inputString.split(tagSectionSeparator) - // log.debug(' finder - boom', boom) + let boom = inputString.split(rangement_instance.tagSectionSeparator) + log.debug(' finder - boom', boom) if (boom.length) { - let fileSectionsName = boom.splice(tagSeparator) - listOfTags = [...fileSectionsName[1].trim().split(tagSeparator)] + let fileSectionsName = boom.splice(rangement_instance.tagSeparator) + listOfTags = [...fileSectionsName[1].trim().split(rangement_instance.tagSeparator)] log.debug(' finder - listOfTags', listOfTags) } else { log.debug(' finder - no boom', boom) @@ -130,7 +131,7 @@ export default class finder { tags.push(tagName) let uniqueArray = [...new Set(tags)] - let newFileName = firstPart + ' ' + tagSectionSeparator + ' ' + tags.join(tagSeparator) + let newFileName = firstPart + ' ' + rangement_instance.tagSectionSeparator + ' ' + tags.join(rangement_instance.tagSeparator) newFileName = newFileName.replace(/ {*}/, '') + this.findFileExtension(fileName) return this.cleanSpaces(newFileName) } @@ -201,9 +202,9 @@ export default class finder { let minDate = moment.min(moments) log.debug(' finder - minDate :::::::::', minDate) - log.debug(' finder - minDate :::::::::', minDate.format('yyyy-MM-DDTHH:mm:ss')) + log.info(' finder - minDate :::::::::', minDate.format(rangement_instance.iso_date_format)) - return minDate.format('yyyy-MM-DDTHH:mm:ss') + return minDate.format(rangement_instance.iso_date_format) } else { log.debug(' finder - pas de exif data') return '' diff --git a/index.mjs b/index.mjs index a149219..6546801 100644 --- a/index.mjs +++ b/index.mjs @@ -53,6 +53,9 @@ function renameFile(originalFileName, fileMixedNewName) { if (err) { log.info('rename ERROR: ' + err) } else { + // otherRenames.push(originalFileName) + otherRenames.push(fileMixedNewName) + addOriginalFileNameIfMissing(originalFileName, fileMixedNewName) // rangement_instance.statistics['filesModified']++ } @@ -72,9 +75,11 @@ function prependFileName(fileProperties, newText) { function makeFileNameFromProperties(fileProperties) { let tagPlace = '' + log.info('fileProperties.tags',fileProperties.tags) if (fileProperties.tags.length && rangement_instance.keepTags) { tagPlace = ' ' + rangement_instance.tagSectionSeparator + ' '+ fileProperties.tags.join(rangement_instance.tagSeparator) } + console.log('fileProperties.dateStampExif', fileProperties.dateStampExif) let newName = '' + fileProperties.dateStampExif + ' ' @@ -91,11 +96,13 @@ function makeFileNameFromProperties(fileProperties) { return newName } +let otherRenames = []; + function shouldWeChangeName(structureForFile) { log.info(' ______ shouldWeChangeName ', structureForFile.fileNameOriginal) let newName = makeFileNameFromProperties(structureForFile) log.debug('newName', newName) - if (structureForFile.fileNameOriginal !== newName) { + if (structureForFile.fileNameOriginal !== newName && !otherRenames.includes(newName)) { log.info('\n ancien nom :', structureForFile.fileNameOriginal) diff --git a/testFiles/2020-06-21T14:27:19 image.jpg b/testFiles/image.jpg similarity index 100% rename from testFiles/2020-06-21T14:27:19 image.jpg rename to testFiles/image.jpg diff --git a/testFiles/meme/ FzjSx2YWcAEqsde -- meme.jpg b/testFiles/meme/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg similarity index 100% rename from testFiles/meme/ FzjSx2YWcAEqsde -- meme.jpg rename to testFiles/meme/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg diff --git a/testFiles/meme/ FyB8cZnWIAc21rw -- meme.jpg b/testFiles/meme/eueueu -- meme.jpg similarity index 100% rename from testFiles/meme/ FyB8cZnWIAc21rw -- meme.jpg rename to testFiles/meme/eueueu -- meme.jpg diff --git a/testFiles/meme_base/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg b/testFiles/meme_base/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg new file mode 100644 index 0000000..ed40ffb Binary files /dev/null and b/testFiles/meme_base/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg differ diff --git a/testFiles/meme_base/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg b/testFiles/meme_base/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg new file mode 100644 index 0000000..b150550 Binary files /dev/null and b/testFiles/meme_base/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg differ