2023-06-29 18:58:08 +02:00
|
|
|
/**---------------------
|
|
|
|
* @name tykayn Rangement
|
|
|
|
* @description Rangement sorts and rename files depending on their exif data
|
|
|
|
* @contact contact@cipherbliss.com
|
|
|
|
--------------------- */
|
|
|
|
/** ---------------------
|
|
|
|
libs
|
|
|
|
--------------------- */
|
2023-06-27 15:40:50 +02:00
|
|
|
import fs from 'node-fs'
|
2023-06-29 18:58:08 +02:00
|
|
|
import minimist from 'minimist'
|
|
|
|
/** ---------------------
|
|
|
|
custom utilities and configuration
|
|
|
|
--------------------- */
|
|
|
|
import { enableTestsLocally, reportStatistics, tagSectionSeparator, tagSeparator } from './configs.mjs'
|
|
|
|
import {
|
|
|
|
TestFindFormattedDate,
|
|
|
|
TestScreenShotIsFoundAndRenamed,
|
|
|
|
TestTagsAreDetectedInFileName
|
|
|
|
} from './testFunctions.mjs'
|
|
|
|
import finder from './finder.mjs'
|
|
|
|
|
2023-06-29 19:49:58 +02:00
|
|
|
let mini_arguments
|
2023-06-29 18:58:08 +02:00
|
|
|
console.log(' ')
|
2023-06-29 18:59:12 +02:00
|
|
|
|
2023-06-29 18:58:08 +02:00
|
|
|
function parseArguments () {
|
|
|
|
mini_arguments = minimist(process.argv.slice(2))
|
2023-06-29 19:33:31 +02:00
|
|
|
console.log('arguments', mini_arguments)
|
2023-06-29 18:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
parseArguments()
|
2023-06-27 15:40:50 +02:00
|
|
|
|
2023-06-29 18:58:08 +02:00
|
|
|
function renameFile (originalFileName, fileMixedNewName) {
|
|
|
|
fs.rename(originalFileName, fileMixedNewName, function (err) {
|
|
|
|
if (err) console.log('rename ERROR: ' + err)
|
|
|
|
})
|
2023-06-27 23:03:35 +02:00
|
|
|
}
|
|
|
|
|
2023-06-29 18:58:08 +02:00
|
|
|
function makeFileNameFromProperties (fileProperties) {
|
2023-06-29 19:33:31 +02:00
|
|
|
|
2023-06-29 19:49:58 +02:00
|
|
|
let tagPlace = ''
|
|
|
|
if (fileProperties.tags.length) {
|
2023-06-29 19:33:31 +02:00
|
|
|
tagPlace = ' ' + tagSectionSeparator + ' '
|
|
|
|
}
|
2023-06-29 19:49:58 +02:00
|
|
|
return finder.cleanSpaces(fileProperties.dateStamp + ' ' + fileProperties.freeText + tagPlace + fileProperties.tags.join(tagSeparator) + fileProperties.extension).replace(+' ' + tagSectionSeparator + ' ' + '.', '.')
|
2023-06-27 23:03:35 +02:00
|
|
|
}
|
2023-06-27 16:06:22 +02:00
|
|
|
|
2023-06-29 18:58:08 +02:00
|
|
|
function appendFileName (fileProperties, newText) {
|
|
|
|
fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText)
|
|
|
|
return fileProperties
|
2023-06-27 23:18:00 +02:00
|
|
|
}
|
2023-06-29 17:09:18 +02:00
|
|
|
|
2023-06-29 18:58:08 +02:00
|
|
|
function prependFileName (fileProperties, newText) {
|
|
|
|
fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText)
|
|
|
|
return fileProperties
|
2023-06-27 23:03:35 +02:00
|
|
|
}
|
2023-06-29 17:09:18 +02:00
|
|
|
|
2023-06-29 19:49:58 +02:00
|
|
|
async function guessFileNameOnAllFilesFromArguments () {
|
2023-06-29 19:33:31 +02:00
|
|
|
|
|
|
|
// parcourir les dossiers
|
|
|
|
// parcourir les fichiers
|
|
|
|
|
|
|
|
console.log('liste des fichiers', mini_arguments._)
|
2023-06-29 19:49:58 +02:00
|
|
|
let fileList = mini_arguments._
|
|
|
|
|
2023-06-29 19:33:31 +02:00
|
|
|
fileList.forEach(fileName => {
|
|
|
|
|
|
|
|
let structureForFile = finder.destructurateFileName(fileName)
|
|
|
|
// examiner les infos exif de chaque fichier pour proposer un nouveau nom
|
2023-06-29 19:49:58 +02:00
|
|
|
if (!structureForFile.dateStamp) {
|
2023-06-29 19:33:31 +02:00
|
|
|
let foundDate = finder.findExifCreationDate(fileName)
|
2023-06-29 19:49:58 +02:00
|
|
|
console.log(' =>>>>>>> foundDate : ', foundDate)
|
|
|
|
if (foundDate) {
|
|
|
|
structureForFile.dateStamp = (finder.findExifCreationDate(fileName) + '')
|
|
|
|
|
|
|
|
} else {
|
|
|
|
console.log(' pas de date trouvée dans le nom')
|
2023-06-29 19:33:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
let newname = makeFileNameFromProperties(structureForFile)
|
2023-06-29 19:49:58 +02:00
|
|
|
if (fileName !== newname) {
|
2023-06-29 19:33:31 +02:00
|
|
|
|
2023-06-29 19:49:58 +02:00
|
|
|
console.log(' nouveau nom:', newname)
|
|
|
|
} else {
|
|
|
|
console.log(' rien à changer')
|
2023-06-29 19:33:31 +02:00
|
|
|
}
|
2023-06-29 19:49:58 +02:00
|
|
|
|
|
|
|
|
2023-06-29 19:33:31 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
guessFileNameOnAllFilesFromArguments()
|
|
|
|
|
2023-06-27 23:18:00 +02:00
|
|
|
// run tests
|
2023-06-29 18:13:46 +02:00
|
|
|
if (enableTestsLocally) {
|
2023-06-27 23:18:00 +02:00
|
|
|
|
2023-06-29 18:58:08 +02:00
|
|
|
TestTagsAreDetectedInFileName()
|
|
|
|
TestFindFormattedDate()
|
|
|
|
TestScreenShotIsFoundAndRenamed()
|
2023-06-27 23:18:00 +02:00
|
|
|
}
|
2023-06-29 19:49:58 +02:00
|
|
|
if (reportStatistics || mini_arguments.stats) {
|
2023-06-29 18:58:08 +02:00
|
|
|
finder.reportStatistics()
|
2023-06-29 19:33:31 +02:00
|
|
|
}
|