fetch sub folder
This commit is contained in:
parent
66df16671e
commit
62d14c07b4
20
configs.mjs
20
configs.mjs
@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
export default class config_rangement{
|
class config_rangement{
|
||||||
log_level ='debug' // [ 'debug' 'none']
|
log_level ='debug' // 'debug' | 'warn' |'info'
|
||||||
version = '1.0.0'
|
version = '1.0.0'
|
||||||
tagSeparator = '1.0.0'
|
tagSeparator = '1.0.0'
|
||||||
tagSectionSeparator = '1.0.0'
|
tagSectionSeparator = '1.0.0'
|
||||||
|
keepFreeText= true
|
||||||
|
keepTags= true
|
||||||
enableTestsLocally= false
|
enableTestsLocally= false
|
||||||
reportStatistics= false
|
reportStatistics= false
|
||||||
base_archive_folder= '/home/poule/encrypted/stockage-syncable/'
|
base_archive_folder= '/home/poule/encrypted/stockage-syncable/'
|
||||||
@ -39,7 +41,13 @@ export default class config_rangement{
|
|||||||
} ,
|
} ,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
export const tagSeparator = ' '
|
const rangement_instance = new config_rangement();
|
||||||
export const tagSectionSeparator = '--'
|
|
||||||
export const enableTestsLocally = false
|
export const tagSeparator = rangement_instance.tagSeparator
|
||||||
export const reportStatistics = false
|
export const tagSectionSeparator = rangement_instance.tagSectionSeparator
|
||||||
|
export const enableTestsLocally = rangement_instance.enableTestsLocally
|
||||||
|
export const reportStatistics = rangement_instance.reportStatistics
|
||||||
|
|
||||||
|
|
||||||
|
export default rangement_instance
|
||||||
|
|
||||||
|
56
finder.mjs
56
finder.mjs
@ -1,10 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* la classe qui repère des patterns
|
* la classe qui repère des patterns
|
||||||
*/
|
*/
|
||||||
import { tagSectionSeparator, tagSeparator } from './configs.mjs'
|
import rangement_instance , { tagSectionSeparator, tagSeparator} from './configs.mjs'
|
||||||
import exifr from 'exifr'
|
import exifr from 'exifr'
|
||||||
import moment from 'moment'
|
import moment from 'moment'
|
||||||
import path from 'path'
|
import log from "loglevel";
|
||||||
|
log.setLevel(rangement_instance.log_level)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* finds patterns for file name
|
* finds patterns for file name
|
||||||
@ -16,7 +18,7 @@ export default class finder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static reportStatistics () {
|
static reportStatistics () {
|
||||||
console.log('statistics',
|
log.info('statistics',
|
||||||
this.statistics)
|
this.statistics)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,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)
|
||||||
// console.log('match findFormattedDate', match)
|
// log.debug('match findFormattedDate', match)
|
||||||
let result = ''
|
let result = ''
|
||||||
if (match && match[0]) {
|
if (match && match[0]) {
|
||||||
result = match[0]
|
result = match[0]
|
||||||
@ -49,7 +51,7 @@ export default class finder {
|
|||||||
let boom = fileName.split(tagSectionSeparator)
|
let boom = fileName.split(tagSectionSeparator)
|
||||||
if (boom.length) {
|
if (boom.length) {
|
||||||
let freeTextPart = boom[0].trim()
|
let freeTextPart = boom[0].trim()
|
||||||
console.log('freeTextPart', freeTextPart)
|
log.debug('freeTextPart', freeTextPart)
|
||||||
return freeTextPart
|
return freeTextPart
|
||||||
}
|
}
|
||||||
return fileName.trim()
|
return fileName.trim()
|
||||||
@ -68,24 +70,24 @@ export default class finder {
|
|||||||
if (extensionFile) {
|
if (extensionFile) {
|
||||||
extensionFile = extensionFile[0]
|
extensionFile = extensionFile[0]
|
||||||
} else {
|
} else {
|
||||||
console.log('no extensionFile', extensionFile, inputString)
|
log.debug('no extensionFile', extensionFile, inputString)
|
||||||
extensionFile = ''
|
extensionFile = ''
|
||||||
}
|
}
|
||||||
inputString = inputString.replace(extensionFile, '')
|
inputString = inputString.replace(extensionFile, '')
|
||||||
|
|
||||||
// console.log('extensionFile', extensionFile)
|
// log.debug('extensionFile', extensionFile)
|
||||||
if (inputString.includes(tagSectionSeparator)) {
|
if (inputString.includes(tagSectionSeparator)) {
|
||||||
// console.log('inputString', inputString)
|
// log.debug('inputString', inputString)
|
||||||
if (inputString.length) {
|
if (inputString.length) {
|
||||||
|
|
||||||
let boom = inputString.split(tagSectionSeparator)
|
let boom = inputString.split(tagSectionSeparator)
|
||||||
// console.log('boom', boom)
|
// log.debug('boom', boom)
|
||||||
if (boom.length) {
|
if (boom.length) {
|
||||||
let fileSectionsName = boom.splice(tagSeparator)
|
let fileSectionsName = boom.splice(tagSeparator)
|
||||||
listOfTags = [...fileSectionsName[1].trim().split(tagSeparator)]
|
listOfTags = [...fileSectionsName[1].trim().split(tagSeparator)]
|
||||||
// console.log('listOfTags', listOfTags)
|
// log.debug('listOfTags', listOfTags)
|
||||||
} else {
|
} else {
|
||||||
console.log('no boom', boom)
|
log.debug('no boom', boom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,15 +108,15 @@ export default class finder {
|
|||||||
static searchAndRenameScreenshots (fileName) {
|
static searchAndRenameScreenshots (fileName) {
|
||||||
if (finder.findScreenshot(fileName)) {
|
if (finder.findScreenshot(fileName)) {
|
||||||
let tags = this.findTagSectionInString(fileName)
|
let tags = this.findTagSectionInString(fileName)
|
||||||
console.log('tags', tags)
|
log.debug('tags', tags)
|
||||||
if (!tags.includes('screenshot')) {
|
if (!tags.includes('screenshot')) {
|
||||||
|
|
||||||
fileName = this.addTagInFileName('screenshot', fileName)
|
fileName = this.addTagInFileName('screenshot', fileName)
|
||||||
fileName = this.searchAndReplaceInFileName('Screenshot', '', fileName)
|
fileName = this.searchAndReplaceInFileName('Screenshot', '', fileName)
|
||||||
console.log('screenShotMockFileName:', fileName)
|
log.debug('screenShotMockFileName:', fileName)
|
||||||
return this.cleanSpaces(fileName)
|
return this.cleanSpaces(fileName)
|
||||||
}
|
}
|
||||||
console.log('is a screenshot, remove screenshot in name, and add tag screenshot')
|
log.debug('is a screenshot, remove screenshot in name, and add tag screenshot')
|
||||||
} else {
|
} else {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@ -164,17 +166,17 @@ export default class finder {
|
|||||||
|
|
||||||
let moments = []
|
let moments = []
|
||||||
|
|
||||||
// console.log('exif data : ', exifData) // Do something with your data!
|
// log.debug('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!
|
// log.debug('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
|
||||||
moments.push(exifData.DateTimeOriginal)
|
moments.push(exifData.DateTimeOriginal)
|
||||||
}
|
}
|
||||||
if (exifData.ModificationDateTime) {
|
if (exifData.ModificationDateTime) {
|
||||||
// console.log('image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data!
|
// log.debug('image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data!
|
||||||
moments.push(exifData.ModificationDateTime)
|
moments.push(exifData.ModificationDateTime)
|
||||||
}
|
}
|
||||||
if (exifData.ModifyDate) {
|
if (exifData.ModifyDate) {
|
||||||
// console.log('image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data!
|
// log.debug('image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data!
|
||||||
moments.push(exifData.ModifyDate)
|
moments.push(exifData.ModifyDate)
|
||||||
}
|
}
|
||||||
if (exifData.FileAccessDateTime) {
|
if (exifData.FileAccessDateTime) {
|
||||||
@ -184,11 +186,11 @@ 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!
|
// log.debug('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!
|
// log.debug('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
|
||||||
moments.push(exifData.CreateDate)
|
moments.push(exifData.CreateDate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,12 +200,12 @@ export default class finder {
|
|||||||
})
|
})
|
||||||
let minDate = moment.min(moments)
|
let minDate = moment.min(moments)
|
||||||
|
|
||||||
// console.log('minDate :::::::::', minDate)
|
// log.debug('minDate :::::::::', minDate)
|
||||||
console.log('minDate :::::::::', minDate.format('yyyy-MM-DDTHH:mm:ss'))
|
log.debug('minDate :::::::::', minDate.format('yyyy-MM-DDTHH:mm:ss'))
|
||||||
|
|
||||||
return minDate.format('yyyy-MM-DDTHH:mm:ss')
|
return minDate.format('yyyy-MM-DDTHH:mm:ss')
|
||||||
} else {
|
} else {
|
||||||
console.log('pas de exif data')
|
log.debug('pas de exif data')
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,11 +216,11 @@ export default class finder {
|
|||||||
*/
|
*/
|
||||||
static async findExifCreationDate (filepath) {
|
static async findExifCreationDate (filepath) {
|
||||||
|
|
||||||
console.log('filepath', filepath)
|
log.debug('filepath', filepath)
|
||||||
let dateAlreadyInFileName = finder.findFormattedDate(filepath)
|
let dateAlreadyInFileName = finder.findFormattedDate(filepath)
|
||||||
if (dateAlreadyInFileName) {
|
if (dateAlreadyInFileName) {
|
||||||
|
|
||||||
console.log('------ dateAlreadyInFileName', dateAlreadyInFileName)
|
log.debug('------ dateAlreadyInFileName', dateAlreadyInFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
return await exifr.parse(filepath)
|
return await exifr.parse(filepath)
|
||||||
@ -230,8 +232,8 @@ export default class finder {
|
|||||||
let fileName = folders.pop()
|
let fileName = folders.pop()
|
||||||
folders = filePath.replace(fileName, '')
|
folders = filePath.replace(fileName, '')
|
||||||
|
|
||||||
console.log('\n - folders', folders)
|
log.debug('\n - folders', folders)
|
||||||
console.log(' - fileName', fileName, '\n')
|
log.debug(' - fileName', fileName, '\n')
|
||||||
return [folders, fileName]
|
return [folders, fileName]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
259
index.mjs
259
index.mjs
@ -2,143 +2,222 @@
|
|||||||
* @name tykayn Rangement
|
* @name tykayn Rangement
|
||||||
* @description Rangement sorts and rename files depending on their exif data
|
* @description Rangement sorts and rename files depending on their exif data
|
||||||
* @contact contact@cipherbliss.com
|
* @contact contact@cipherbliss.com
|
||||||
--------------------- */
|
--------------------- */
|
||||||
/** ---------------------
|
/** ---------------------
|
||||||
libs
|
libs
|
||||||
--------------------- */
|
--------------------- */
|
||||||
import fs from 'node-fs'
|
import fs from 'node-fs'
|
||||||
import minimist from 'minimist'
|
import minimist from 'minimist'
|
||||||
import log from 'loglevel';
|
import log from 'loglevel';
|
||||||
|
import path from "node:path";
|
||||||
/** ---------------------
|
/** ---------------------
|
||||||
custom utilities and configuration
|
custom utilities and configuration
|
||||||
--------------------- */
|
--------------------- */
|
||||||
import { enableTestsLocally, reportStatistics,tagSectionSeparator, tagSeparator } from './configs.mjs'
|
import rangement_instance from './configs.mjs'
|
||||||
import {
|
import {
|
||||||
TestFindFormattedDate,
|
TestFindFormattedDate,
|
||||||
TestScreenShotIsFoundAndRenamed,
|
TestScreenShotIsFoundAndRenamed,
|
||||||
TestTagsAreDetectedInFileName
|
TestTagsAreDetectedInFileName
|
||||||
} from './testFunctions.mjs'
|
} from './testFunctions.mjs'
|
||||||
import finder from './finder.mjs'
|
import finder from './finder.mjs'
|
||||||
|
|
||||||
|
import exiftool from "node-exiftool";
|
||||||
|
|
||||||
let mini_arguments
|
let mini_arguments
|
||||||
log.setLevel('info')
|
|
||||||
|
log.setLevel(rangement_instance.log_level)
|
||||||
log.info(' ')
|
log.info(' ')
|
||||||
|
|
||||||
function parseArguments () {
|
function parseArguments() {
|
||||||
mini_arguments = minimist(process.argv.slice(2))
|
mini_arguments = minimist(process.argv.slice(2))
|
||||||
log.info('arguments', mini_arguments)
|
log.debug('arguments', mini_arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
parseArguments()
|
function addOriginalFileNameIfMissing(originalFileName, fileMixedNewName) {
|
||||||
|
|
||||||
function renameFile (originalFileName, fileMixedNewName) {
|
const ep = new exiftool.ExiftoolProcess()
|
||||||
fs.rename(originalFileName, fileMixedNewName, function (err) {
|
|
||||||
log.info('name changed', fileMixedNewName)
|
ep
|
||||||
if (err) log.info('rename ERROR: ' + err)
|
.open(fileMixedNewName)
|
||||||
})
|
.then(() => ep.writeMetadata(fileMixedNewName, {
|
||||||
|
'OriginalFileName+': originalFileName,
|
||||||
|
}))
|
||||||
|
.then(console.log, console.error)
|
||||||
|
.then(() => ep.close())
|
||||||
|
.catch(console.error)
|
||||||
}
|
}
|
||||||
|
|
||||||
function appendFileName (fileProperties, newText) {
|
function renameFile(originalFileName, fileMixedNewName) {
|
||||||
fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText)
|
fs.rename(originalFileName, fileMixedNewName, function (err) {
|
||||||
return fileProperties
|
log.info('name changed', fileMixedNewName)
|
||||||
|
if (err) {
|
||||||
|
log.info('rename ERROR: ' + err)
|
||||||
|
} else {
|
||||||
|
addOriginalFileNameIfMissing(originalFileName, fileMixedNewName)
|
||||||
|
rangement_instance.statistics['filesModified']++
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function prependFileName (fileProperties, newText) {
|
function appendFileName(fileProperties, newText) {
|
||||||
fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText)
|
fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText)
|
||||||
return fileProperties
|
return fileProperties
|
||||||
|
}
|
||||||
|
|
||||||
|
function prependFileName(fileProperties, newText) {
|
||||||
|
fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText)
|
||||||
|
return fileProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeFileNameFromProperties(fileProperties) {
|
function makeFileNameFromProperties(fileProperties) {
|
||||||
|
|
||||||
let tagPlace = ''
|
let tagPlace = ''
|
||||||
if (fileProperties.tags.length) {
|
if (fileProperties.tags.length) {
|
||||||
tagPlace = ' ' + tagSectionSeparator + ' '
|
tagPlace = ' ' + rangement_instance.tagSectionSeparator + ' '
|
||||||
}
|
}
|
||||||
// return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+' ' + tagSectionSeparator + ' ' + '.', '.')
|
return '' + fileProperties.dateStampExif + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension
|
||||||
return ''+fileProperties.dateStampExif + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldWeChangeName (structureForFile) {
|
function shouldWeChangeName(structureForFile) {
|
||||||
log.info(' ______ allez hop fini la recherche on fait un nouveau nom')
|
log.info(' ______ allez hop fini la recherche on fait un nouveau nom')
|
||||||
log.info('structureForFile', structureForFile)
|
log.info('structureForFile', structureForFile)
|
||||||
let newName = makeFileNameFromProperties(structureForFile)
|
let newName = makeFileNameFromProperties(structureForFile)
|
||||||
if (structureForFile.fileNameOriginal !== newName) {
|
if (structureForFile.fileNameOriginal !== newName) {
|
||||||
|
|
||||||
log.info('\n ancien nom :', structureForFile.fileNameOriginal)
|
log.info('\n ancien nom :', structureForFile.fileNameOriginal)
|
||||||
// log.info(' nouveau nom:', foundDate +structureForFile.freeText + structureForFile.tags.join(tagSeparator) + structureForFile.extension )
|
|
||||||
log.info(' nouveau nom:', newName)
|
log.info(' nouveau nom:', newName)
|
||||||
if(! mini_arguments.dryRun){
|
if (!mini_arguments['dry-run']) {
|
||||||
renameFile(structureForFile.fullPath, structureForFile.folderPath + newName)
|
renameFile(structureForFile.fullPath, structureForFile.folderPath + newName)
|
||||||
}
|
} else {
|
||||||
else{
|
log.info('no renaming for real, this is a dry run')
|
||||||
log.info('no renaming for real, this is a dry run')
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
log.info(' rien à changer')
|
||||||
log.info(' rien à changer')
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function guessFileNameOnAllFilesFromArguments () {
|
/**
|
||||||
|
* guess file name on one file which is not a directory
|
||||||
|
* @param fullPath
|
||||||
|
*/
|
||||||
|
function guessFileNameOnOnefile(fullPath) {
|
||||||
|
|
||||||
// parcourir les dossiers
|
fs.stat(fullPath, (err, stats) => {
|
||||||
// parcourir les fichiers
|
|
||||||
|
|
||||||
log.info('liste des fichiers', mini_arguments._)
|
if (err) {
|
||||||
let fileList = mini_arguments._
|
log.error('échec fichier', err)
|
||||||
|
log.error('ce fichier n existe pas: ', fullPath)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
|
||||||
fileList.forEach(fullPath => {
|
let structureForFile = finder.destructurateFileName(fullPath)
|
||||||
|
|
||||||
let structureForFile = finder.destructurateFileName(fullPath)
|
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
|
||||||
|
if (!structureForFile.dateStampInFileNameOriginal) {
|
||||||
|
log.debug(' le nom de fichier ne contient pas de date formatée au début')
|
||||||
|
|
||||||
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
|
finder.findExifCreationDate(structureForFile.fullPath)
|
||||||
if (!structureForFile.dateStampInFileNameOriginal) {
|
.then(data => {
|
||||||
log.info(' le nom de fichier ne contient pas de date formatée au début')
|
log.debug(' ... chercher la date de création')
|
||||||
|
let foundDate = finder.findEarliestDateInExifData(data)
|
||||||
|
|
||||||
finder.findExifCreationDate(structureForFile.fullPath)
|
log.info(' =>>>>>>> foundDate : ', foundDate)
|
||||||
.then(data => {
|
if (foundDate) {
|
||||||
log.info(' ... chercher la date de création')
|
structureForFile.dateStampExif = foundDate
|
||||||
let foundDate = finder.findEarliestDateInExifData(data)
|
shouldWeChangeName(structureForFile)
|
||||||
|
|
||||||
log.info(' =>>>>>>> foundDate : ', foundDate)
|
} else {
|
||||||
if (foundDate) {
|
log.info('pas de date trouvée dans le nom')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
,
|
||||||
|
(error) => {
|
||||||
|
log.warn('/////////// Error in reading exif of file: ' + error.message)
|
||||||
|
return ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let expandedFileList = []
|
||||||
|
let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd());
|
||||||
|
console.log('cwd', cwd)
|
||||||
|
|
||||||
|
function guessFileNameOnAllFilesFromArguments() {
|
||||||
|
|
||||||
|
|
||||||
// finder.findEarliestDateInExifData(fullPath).then(response => {
|
// parcourir les fichiers
|
||||||
// log.info(' ... trouvée')
|
log.debug('liste des fichiers', mini_arguments._)
|
||||||
// if (response) {
|
let fileList = mini_arguments._
|
||||||
structureForFile.dateStampExif = foundDate
|
|
||||||
|
|
||||||
shouldWeChangeName(structureForFile)
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
} else {
|
// test file exists
|
||||||
log.info('pas de date trouvée dans le nom')
|
fileList.forEach(fullPath => {
|
||||||
}
|
// parcourir les dossiers
|
||||||
|
isFolderOrFile(`${fullPath}`)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
}
|
log.info('expanded file list :', expandedFileList)
|
||||||
,
|
expandedFileList.forEach(filePath => guessFileNameOnOnefile(filePath))
|
||||||
(error) => {
|
|
||||||
log.info('/////////// Error in reading exif of file: ' + error.message)
|
|
||||||
return ''
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function readSubdirectories(baseDir) {
|
||||||
|
const newGlob = baseDir;
|
||||||
|
let fileList = [];
|
||||||
|
fs.readdir(baseDir, (err, files) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
console.log('files', files)
|
||||||
|
files.forEach((subDirOrFile) => {
|
||||||
|
const newFullPath = path.resolve(baseDir, subDirOrFile);
|
||||||
|
|
||||||
|
if (fs.existsSync(newFullPath)) {
|
||||||
|
const s = fs.statSync(newFullPath);
|
||||||
|
|
||||||
|
if (s.isFile()) {
|
||||||
|
fileList.push(cwd+'/'+subDirOrFile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return fileList
|
||||||
|
});
|
||||||
|
return fileList
|
||||||
|
}
|
||||||
|
|
||||||
|
function isFolderOrFile(fileName) {
|
||||||
|
const stat = fs.statSync(cwd + '/' + fileName);
|
||||||
|
|
||||||
|
if (stat.isDirectory()) {
|
||||||
|
let fileList = readSubdirectories(fileName);
|
||||||
|
console.log('fileList in directory ',fileName, '\n', fileList)
|
||||||
|
if (fileList) {
|
||||||
|
expandedFileList.push(...fileList)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (stat.isFile()) {
|
||||||
|
expandedFileList.push(cwd + '/' + fileName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parseArguments()
|
||||||
|
|
||||||
guessFileNameOnAllFilesFromArguments()
|
guessFileNameOnAllFilesFromArguments()
|
||||||
|
|
||||||
// run tests
|
|
||||||
if (enableTestsLocally) {
|
|
||||||
|
|
||||||
TestTagsAreDetectedInFileName()
|
// run tests
|
||||||
TestFindFormattedDate()
|
if (rangement_instance.enableTestsLocally) {
|
||||||
TestScreenShotIsFoundAndRenamed()
|
|
||||||
|
TestTagsAreDetectedInFileName()
|
||||||
|
TestFindFormattedDate()
|
||||||
|
TestScreenShotIsFoundAndRenamed()
|
||||||
}
|
}
|
||||||
if (reportStatistics || mini_arguments.stats) {
|
if (rangement_instance.reportStatistics || mini_arguments.stats) {
|
||||||
finder.reportStatistics()
|
finder.reportStatistics()
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import finder from "./finders.mjs";
|
// import finder from "./finders.mjs";
|
||||||
// const finders = require('./finders.mjs')
|
const finders = require('./finders.mjs')
|
||||||
|
|
||||||
describe('rangement file name', () => {
|
describe('rangement file name', () => {
|
||||||
|
|
||||||
|
43
package-lock.json
generated
43
package-lock.json
generated
@ -13,6 +13,7 @@
|
|||||||
"i18next": "^23.2.6",
|
"i18next": "^23.2.6",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
|
"node-exiftool": "^2.3.0",
|
||||||
"node-fs": "^0.1.7"
|
"node-fs": "^0.1.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -2742,6 +2743,11 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"node_modules/catchment": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/catchment/-/catchment-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-6sTXWtTXI+MTHrHVnvZnOM8q2ujbQ+qJF0Mu8NM3jifMBCiZssjol/nBHQqOEiKSZKf1e4+wCrgmTXzWzvZs5w=="
|
||||||
|
},
|
||||||
"node_modules/chalk": {
|
"node_modules/chalk": {
|
||||||
"version": "4.1.2",
|
"version": "4.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||||
@ -4249,6 +4255,11 @@
|
|||||||
"tmpl": "1.0.5"
|
"tmpl": "1.0.5"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/makepromise": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/makepromise/-/makepromise-1.0.0.tgz",
|
||||||
|
"integrity": "sha512-M1q31Q56rlA+gwvmfWj7QFDMIJOuj527fQx/rN3dlzUtsopC9ZjtyekIBW4Fw0HZP6O6Azuw3/Vtk5O59bXz7A=="
|
||||||
|
},
|
||||||
"node_modules/merge-stream": {
|
"node_modules/merge-stream": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz",
|
||||||
@ -4317,6 +4328,24 @@
|
|||||||
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
"integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"node_modules/node-exiftool": {
|
||||||
|
"version": "2.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-exiftool/-/node-exiftool-2.3.0.tgz",
|
||||||
|
"integrity": "sha512-UZd+k07thqXqp/1udsZghAFrjrsYfP8Kg48I9uv02FZAmT1Wasr8aAPMCObnYkJiWoD/V8UrGjiSzgfNQy9zBw==",
|
||||||
|
"dependencies": {
|
||||||
|
"is-stream": "1.1.0",
|
||||||
|
"restream": "1.2.0",
|
||||||
|
"wrote": "0.6.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/node-exiftool/node_modules/is-stream": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
|
||||||
|
"integrity": "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/node-fs": {
|
"node_modules/node-fs": {
|
||||||
"version": "0.1.7",
|
"version": "0.1.7",
|
||||||
"resolved": "https://registry.npmjs.org/node-fs/-/node-fs-0.1.7.tgz",
|
"resolved": "https://registry.npmjs.org/node-fs/-/node-fs-0.1.7.tgz",
|
||||||
@ -4818,6 +4847,11 @@
|
|||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/restream": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/restream/-/restream-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-RpnOjVCRrc/jO6j1U+E0X9mPjMUUitjEms/IaR18wb8AdPHg46UBmB2aEA6JKgpGbhOcHsDLyurmeZhd4kQXgg=="
|
||||||
|
},
|
||||||
"node_modules/semver": {
|
"node_modules/semver": {
|
||||||
"version": "6.3.0",
|
"version": "6.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||||
@ -5313,6 +5347,15 @@
|
|||||||
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
|
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/wrote": {
|
||||||
|
"version": "0.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/wrote/-/wrote-0.6.1.tgz",
|
||||||
|
"integrity": "sha512-5vDwEuRou4yCOzR08bUdY+n/HuOA21L7A4tVsm/kEu2R2APN8tYWvxQbM1hFJk49lR7x47KZMtCu2k8S9WISUA==",
|
||||||
|
"dependencies": {
|
||||||
|
"catchment": "1.0.0",
|
||||||
|
"makepromise": "1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/y18n": {
|
"node_modules/y18n": {
|
||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
"i18next": "^23.2.6",
|
"i18next": "^23.2.6",
|
||||||
"minimist": "^1.2.8",
|
"minimist": "^1.2.8",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.29.4",
|
||||||
|
"node-exiftool": "^2.3.0",
|
||||||
"node-fs": "^0.1.7"
|
"node-fs": "^0.1.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
création de la config
|
création de la config
|
||||||
*/
|
*/
|
||||||
import config from './configs.mjs'
|
// import i18next from 'i18next'
|
||||||
import i18next from 'i18next'
|
import config_rangement from "./configs";
|
||||||
let base_archive_folder = config.base_archive_folder
|
|
||||||
|
|
||||||
const { stdin, stdout } = process;
|
const { stdin, stdout } = process;
|
||||||
|
|
||||||
@ -20,7 +19,8 @@ function prompt(question) {
|
|||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const name = await prompt(i18next.t("home.title"))
|
// const name = await prompt(i18next.t("home.title"))
|
||||||
|
const name = await prompt(`squoi le dossier de base des archives? [${config_rangement.base_archive_folder}]`)
|
||||||
// const age = await prompt("What's your age? ");
|
// const age = await prompt("What's your age? ");
|
||||||
// const email = await prompt("What's your email address? ");
|
// const email = await prompt("What's your email address? ");
|
||||||
// const user = { name, age, email };
|
// const user = { name, age, email };
|
||||||
|
Before Width: | Height: | Size: 1.7 MiB After Width: | Height: | Size: 1.7 MiB |
BIN
testFiles/meme/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg
Normal file
BIN
testFiles/meme/2023-06-14T13.29.22 FyB8cZnWIAc21rw -- meme.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
BIN
testFiles/meme/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg
Normal file
BIN
testFiles/meme/2023-06-26T18.53.59 FzjSx2YWcAEqsde -- meme.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 55 KiB |
Loading…
Reference in New Issue
Block a user