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) {
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) {
@ -179,8 +179,8 @@ function addTagInFileName (tagName, fileName) {
let uniqueArray = [...new Set(tags)]
let newFileName = firstPart + ' ' + tagSectionSeparator + ' ' + tags.join(tagSeparator)
newFileName = newFileName.replace(/ {*}/, '')
return newFileName
newFileName = newFileName.replace(/ {*}/, '') + findFileExtension(fileName)
return cleanSpaces( newFileName)
}
const patternsFiles = {
@ -207,7 +207,7 @@ function destructurateFileName (fileName) {
function cleanSpaces (inputString) {
return inputString.replace(/ *g/, ' ')
return inputString.trim().replace(/ *g/, ' ')
}
function makeFileNameFromProperties (fileProperties) {
@ -224,26 +224,62 @@ function prependFileName (fileProperties, newText) {
return fileProperties
}
function searchAndReplaInFileName(searchString, replaceString, fileName){
function searchAndReplaInFileName (searchString, replaceString, fileName) {
return cleanSpaces(fileName.replace(searchString, replaceString))
}
// 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')
let screenShotMockFileName = 'Screenshot 2023-06-15 at 15-28-21 Instance Panoramax OSM-FR.png'
screenShotMockFileName = 'Capture d\'écran 2023-06-15.png'
if (findScreenshot(screenShotMockFileName)) {
let tags = findTagSectionInString(screenShotMockFileName)
console.log('tags', tags)
if (!tags.includes('screenshot')) {
screenShotMockFileName.replace('Screenshot', '')
function searchAndRenameScreenshots(fileName){
if (findScreenshot(fileName)) {
let tags = findTagSectionInString(fileName)
console.log('tags', tags)
if (!tags.includes('screenshot')) {
screenShotMockFileName = addTagInFileName('screenshot', screenShotMockFileName)
console.log('screenShotMockFileName:', screenShotMockFileName)
fileName = addTagInFileName('screenshot', fileName)
fileName = searchAndReplaInFileName('Screenshot', '', fileName)
console.log('screenShotMockFileName:', fileName)
return cleanSpaces( fileName)
}
console.log('is a screenshot, remove screenshot in name, and add tag screenshot')
}else{
return null
}
console.log('is a screenshot, remove screenshot in name, and add tag screenshot')
}
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 -----------------------
@ -251,15 +287,19 @@ if (findScreenshot(screenShotMockFileName)) {
---------------------------------------------------------------------
**/
function DownloadedTelegramPictureRename (fileName) {
function TestDownloadedTelegramPictureRename (fileName) {
let fileProperties = destructurateFileName(fileName)
}
function hasDifferentDateInNameThanExif () {
}
function moveToArchive (targetDirectory, fileFullPath) {
// find current directory,
// rename file to move it
}
/**
* écrit un nouveau nom de fichier formatté
* @param convertedToName