configurable target date format
@ -1,8 +1,9 @@
|
|||||||
class config_rangement {
|
class config_rangement {
|
||||||
log_level = 'info' // 'debug' | 'warn' |'info'
|
log_level = 'info' // 'debug' | 'warn' |'info'
|
||||||
version = '1.0.0'
|
version = '1.0.0'
|
||||||
tagSeparator = '1.0.0'
|
iso_date_format = 'yyyy-MM-DDTHH.mm.ss' // target format for dates in file names
|
||||||
tagSectionSeparator = '1.0.0'
|
tagSeparator = ' '
|
||||||
|
tagSectionSeparator = '--'
|
||||||
keepFreeText = true
|
keepFreeText = true
|
||||||
keepTags = true
|
keepTags = true
|
||||||
replaceUnderscoreWithSpaces = true
|
replaceUnderscoreWithSpaces = true
|
||||||
@ -41,6 +42,7 @@ class config_rangement {
|
|||||||
'auto_sort_folder': 'photos/captures écran screenshots'
|
'auto_sort_folder': 'photos/captures écran screenshots'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rangement_instance = new config_rangement();
|
const rangement_instance = new config_rangement();
|
||||||
|
23
finder.mjs
@ -1,10 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* la classe qui repère des patterns
|
* 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 exifr from 'exifr'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
|
||||||
log.setLevel(rangement_instance.log_level)
|
log.setLevel(rangement_instance.log_level)
|
||||||
|
|
||||||
|
|
||||||
@ -27,7 +28,7 @@ export default class finder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static findFormattedDate (filepath) {
|
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)
|
log.debug(' finder - match findFormattedDate', match)
|
||||||
let result = ''
|
let result = ''
|
||||||
if (match && match[0]) {
|
if (match && match[0]) {
|
||||||
@ -48,7 +49,7 @@ export default class finder {
|
|||||||
*/
|
*/
|
||||||
static findFileNameFreeTextPart (fileName) {
|
static findFileNameFreeTextPart (fileName) {
|
||||||
fileName = fileName.replace(this.findFileExtension(fileName), '')
|
fileName = fileName.replace(this.findFileExtension(fileName), '')
|
||||||
let boom = fileName.split(tagSectionSeparator)
|
let boom = fileName.split(rangement_instance.tagSectionSeparator)
|
||||||
if (boom.length) {
|
if (boom.length) {
|
||||||
let freeTextPart = boom[0].trim()
|
let freeTextPart = boom[0].trim()
|
||||||
log.debug(' finder - freeTextPart', freeTextPart)
|
log.debug(' finder - freeTextPart', freeTextPart)
|
||||||
@ -76,15 +77,15 @@ export default class finder {
|
|||||||
inputString = inputString.replace(extensionFile, '')
|
inputString = inputString.replace(extensionFile, '')
|
||||||
|
|
||||||
log.debug(' finder - extensionFile', extensionFile)
|
log.debug(' finder - extensionFile', extensionFile)
|
||||||
if (inputString.includes(tagSectionSeparator)) {
|
if (inputString.includes(rangement_instance.tagSectionSeparator)) {
|
||||||
log.debug(' finder - inputString', inputString)
|
log.debug(' finder - inputString', inputString)
|
||||||
if (inputString.length) {
|
if (inputString.length) {
|
||||||
|
|
||||||
let boom = inputString.split(tagSectionSeparator)
|
let boom = inputString.split(rangement_instance.tagSectionSeparator)
|
||||||
// log.debug(' finder - boom', boom)
|
log.debug(' finder - boom', boom)
|
||||||
if (boom.length) {
|
if (boom.length) {
|
||||||
let fileSectionsName = boom.splice(tagSeparator)
|
let fileSectionsName = boom.splice(rangement_instance.tagSeparator)
|
||||||
listOfTags = [...fileSectionsName[1].trim().split(tagSeparator)]
|
listOfTags = [...fileSectionsName[1].trim().split(rangement_instance.tagSeparator)]
|
||||||
log.debug(' finder - listOfTags', listOfTags)
|
log.debug(' finder - listOfTags', listOfTags)
|
||||||
} else {
|
} else {
|
||||||
log.debug(' finder - no boom', boom)
|
log.debug(' finder - no boom', boom)
|
||||||
@ -130,7 +131,7 @@ export default class finder {
|
|||||||
tags.push(tagName)
|
tags.push(tagName)
|
||||||
let uniqueArray = [...new Set(tags)]
|
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)
|
newFileName = newFileName.replace(/ {*}/, '') + this.findFileExtension(fileName)
|
||||||
return this.cleanSpaces(newFileName)
|
return this.cleanSpaces(newFileName)
|
||||||
}
|
}
|
||||||
@ -201,9 +202,9 @@ export default class finder {
|
|||||||
let minDate = moment.min(moments)
|
let minDate = moment.min(moments)
|
||||||
|
|
||||||
log.debug(' finder - minDate :::::::::', minDate)
|
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 {
|
} else {
|
||||||
log.debug(' finder - pas de exif data')
|
log.debug(' finder - pas de exif data')
|
||||||
return ''
|
return ''
|
||||||
|
@ -53,6 +53,9 @@ function renameFile(originalFileName, fileMixedNewName) {
|
|||||||
if (err) {
|
if (err) {
|
||||||
log.info('rename ERROR: ' + err)
|
log.info('rename ERROR: ' + err)
|
||||||
} else {
|
} else {
|
||||||
|
// otherRenames.push(originalFileName)
|
||||||
|
otherRenames.push(fileMixedNewName)
|
||||||
|
|
||||||
addOriginalFileNameIfMissing(originalFileName, fileMixedNewName)
|
addOriginalFileNameIfMissing(originalFileName, fileMixedNewName)
|
||||||
// rangement_instance.statistics['filesModified']++
|
// rangement_instance.statistics['filesModified']++
|
||||||
}
|
}
|
||||||
@ -72,9 +75,11 @@ function prependFileName(fileProperties, newText) {
|
|||||||
function makeFileNameFromProperties(fileProperties) {
|
function makeFileNameFromProperties(fileProperties) {
|
||||||
|
|
||||||
let tagPlace = ''
|
let tagPlace = ''
|
||||||
|
log.info('fileProperties.tags',fileProperties.tags)
|
||||||
if (fileProperties.tags.length && rangement_instance.keepTags) {
|
if (fileProperties.tags.length && rangement_instance.keepTags) {
|
||||||
tagPlace = ' ' + rangement_instance.tagSectionSeparator + ' '+ fileProperties.tags.join(rangement_instance.tagSeparator)
|
tagPlace = ' ' + rangement_instance.tagSectionSeparator + ' '+ fileProperties.tags.join(rangement_instance.tagSeparator)
|
||||||
}
|
}
|
||||||
|
console.log('fileProperties.dateStampExif', fileProperties.dateStampExif)
|
||||||
let newName = ''
|
let newName = ''
|
||||||
+ fileProperties.dateStampExif
|
+ fileProperties.dateStampExif
|
||||||
+ ' '
|
+ ' '
|
||||||
@ -91,11 +96,13 @@ function makeFileNameFromProperties(fileProperties) {
|
|||||||
return newName
|
return newName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let otherRenames = [];
|
||||||
|
|
||||||
function shouldWeChangeName(structureForFile) {
|
function shouldWeChangeName(structureForFile) {
|
||||||
log.info(' ______ shouldWeChangeName ', structureForFile.fileNameOriginal)
|
log.info(' ______ shouldWeChangeName ', structureForFile.fileNameOriginal)
|
||||||
let newName = makeFileNameFromProperties(structureForFile)
|
let newName = makeFileNameFromProperties(structureForFile)
|
||||||
log.debug('newName', newName)
|
log.debug('newName', newName)
|
||||||
if (structureForFile.fileNameOriginal !== newName) {
|
if (structureForFile.fileNameOriginal !== newName && !otherRenames.includes(newName)) {
|
||||||
|
|
||||||
log.info('\n ancien nom :', structureForFile.fileNameOriginal)
|
log.info('\n ancien nom :', structureForFile.fileNameOriginal)
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
Before Width: | Height: | Size: 55 KiB After Width: | Height: | Size: 55 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 55 KiB |