configurable target date format

This commit is contained in:
Tykayn 2023-07-04 16:14:25 +02:00 committed by tykayn
parent e1f819d8e3
commit 86ce8f5afe
8 changed files with 24 additions and 14 deletions

View File

@ -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();

View File

@ -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 ''

View File

@ -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)

View File

Before

Width:  |  Height:  |  Size: 1.7 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB