This commit is contained in:
Tykayn 2023-06-27 23:18:00 +02:00 committed by tykayn
parent 4e1b774e8c
commit 30ec55c1c8
1 changed files with 57 additions and 17 deletions

View File

@ -25,7 +25,7 @@ function convertDateToTimeInFileName (inputDate) {
} }
function findFormattedDate (inputString) { function findFormattedDate (inputString) {
return inputString.matchAll(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/i) return inputString.match(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ig)
} }
function findScreenshot (inputString) { function findScreenshot (inputString) {
@ -179,8 +179,8 @@ function addTagInFileName (tagName, fileName) {
let uniqueArray = [...new Set(tags)] let uniqueArray = [...new Set(tags)]
let newFileName = firstPart + ' ' + tagSectionSeparator + ' ' + tags.join(tagSeparator) let newFileName = firstPart + ' ' + tagSectionSeparator + ' ' + tags.join(tagSeparator)
newFileName = newFileName.replace(/ {*}/, '') newFileName = newFileName.replace(/ {*}/, '') + findFileExtension(fileName)
return newFileName return cleanSpaces( newFileName)
} }
const patternsFiles = { const patternsFiles = {
@ -207,7 +207,7 @@ function destructurateFileName (fileName) {
function cleanSpaces (inputString) { function cleanSpaces (inputString) {
return inputString.replace(/ *g/, ' ') return inputString.trim().replace(/ *g/, ' ')
} }
function makeFileNameFromProperties (fileProperties) { function makeFileNameFromProperties (fileProperties) {
@ -224,26 +224,62 @@ function prependFileName (fileProperties, newText) {
return fileProperties return fileProperties
} }
function searchAndReplaInFileName(searchString, replaceString, fileName){ function searchAndReplaInFileName (searchString, replaceString, fileName) {
return cleanSpaces(fileName.replace(searchString, replaceString)) return cleanSpaces(fileName.replace(searchString, replaceString))
} }
// getExifCreationDate('/home/poule/encrypted/stockage-syncable/photos/a_dispatcher/2023-06-23T18.36.47 -- machin bidule.jpg') // getExifCreationDate('/home/poule/encrypted/stockage-syncable/photos/a_dispatcher/2023-06-23T18.36.47 -- machin bidule.jpg')
// findTagSectionInString('2023-06-23T18.36.47 -- machin bidule.jpg') // findTagSectionInString('2023-06-23T18.36.47 -- machin bidule.jpg')
let screenShotMockFileName = 'Screenshot 2023-06-15 at 15-28-21 Instance Panoramax OSM-FR.png' function searchAndRenameScreenshots(fileName){
screenShotMockFileName = 'Capture d\'écran 2023-06-15.png' if (findScreenshot(fileName)) {
if (findScreenshot(screenShotMockFileName)) { let tags = findTagSectionInString(fileName)
let tags = findTagSectionInString(screenShotMockFileName)
console.log('tags', tags) console.log('tags', tags)
if (!tags.includes('screenshot')) { if (!tags.includes('screenshot')) {
screenShotMockFileName.replace('Screenshot', '')
screenShotMockFileName = addTagInFileName('screenshot', screenShotMockFileName) fileName = addTagInFileName('screenshot', fileName)
console.log('screenShotMockFileName:', screenShotMockFileName) fileName = searchAndReplaInFileName('Screenshot', '', fileName)
console.log('screenShotMockFileName:', fileName)
return cleanSpaces( fileName)
} }
console.log('is a screenshot, remove screenshot in name, and add tag screenshot') console.log('is a screenshot, remove screenshot in name, and add tag screenshot')
}else{
return null
}
} }
function TestScreenShotIsFoundAndRenamed () {
let screenShotMockFileName = 'Screenshot 2023-06-15 at 15-28-21 Instance Panoramax OSM-FR.png'
let screenShotMockFileNameExpected = '2023-06-15 at 15-28-21 Instance Panoramax OSM-FR -- screenshot.png'
let found = searchAndRenameScreenshots(screenShotMockFileName)
console.log('found', found)
if(found == screenShotMockFileNameExpected){
console.log('TestScreenShotIsFoundAndRenamed : test succès')
}else{
console.log('TestScreenShotIsFoundAndRenamed : FAIL:')
console.log(found)
console.log(screenShotMockFileNameExpected)
}
}
TestScreenShotIsFoundAndRenamed()
/**
* work in progress
*
*/
function TestDateIsDetectedInFileName () {
let mockFileName = 'Capture d\'écran 2023-06-15T10:11:12.png'
let expectedFileNameAfterRename = '2023-06-15T10:11:12 -- screeenshot.png'
let foundDate = findFormattedDate(mockFileName)
console.log('foundDate', foundDate)
}
// run tests
TestDateIsDetectedInFileName()
/** /**
----------------------- parties non réalisées ----------------------- ----------------------- parties non réalisées -----------------------
@ -251,15 +287,19 @@ if (findScreenshot(screenShotMockFileName)) {
--------------------------------------------------------------------- ---------------------------------------------------------------------
**/ **/
function DownloadedTelegramPictureRename (fileName) { function TestDownloadedTelegramPictureRename (fileName) {
let fileProperties = destructurateFileName(fileName) let fileProperties = destructurateFileName(fileName)
} }
function hasDifferentDateInNameThanExif () { function hasDifferentDateInNameThanExif () {
} }
function moveToArchive (targetDirectory, fileFullPath) {
// find current directory,
// rename file to move it
}
/** /**
* écrit un nouveau nom de fichier formatté * écrit un nouveau nom de fichier formatté
* @param convertedToName * @param convertedToName