find tags and extension of file

This commit is contained in:
Tykayn 2023-06-27 18:12:43 +02:00 committed by tykayn
parent 2a2ece88a7
commit dabebeb6fa
1 changed files with 60 additions and 41 deletions

View File

@ -24,68 +24,88 @@ function convertDateToTimeInFileName (inputDate) {
return inputDate.replace(' ', 'T') return inputDate.replace(' ', 'T')
} }
function findFormattedDate(inputString){ function findFormattedDate (inputString) {
return inputString.match(/^[0-9]{4}-?[0-9]{2}-?[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/) return inputString.match(/^[0-9]{4}-?[0-9]{2}-?[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}$/)
} }
function getExifCreationDate (filepath) { function getExifCreationDate (filepath) {
console.log('filepath', filepath) console.log('filepath', filepath)
exifr.parse(filepath).then(exifData => { exifr.parse(filepath).then(exifData => {
if (exifData) { if (exifData) {
let moments = [] let moments = []
// console.log('exif data : ', exifData) // Do something with your data! // console.log('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! // console.log('image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data!
moments.push(exifData.DateTimeOriginal) moments.push(exifData.DateTimeOriginal)
} }
if (exifData.ModifyDate) { if (exifData.ModifyDate) {
// console.log('image modifiée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data! // console.log('image modifiée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data!
moments.push(exifData.ModifyDate) moments.push(exifData.ModifyDate)
}
if (exifData.FileModificationDateTime) {
// console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
moments.push(exifData.FileModificationDateTime)
}
if (exifData.CreateDate) {
// console.log('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
moments.push(exifData.CreateDate)
}
moments = moments.map(d => {
let newdate = moment(d)
return newdate
})
let minDate = moment.min(moments)
return minDate
} else {
console.log('pas de exif data')
return null
} }
}).catch(error => console.log('Error: ' + error.message)) if (exifData.FileModificationDateTime) {
// console.log('image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data!
moments.push(exifData.FileModificationDateTime)
}
if (exifData.CreateDate) {
// console.log('image créée le : CreateDate : ', exifData.CreateDate) // Do something with your data!
moments.push(exifData.CreateDate)
}
moments = moments.map(d => {
let newdate = moment(d)
return newdate
})
let minDate = moment.min(moments)
return minDate
} else {
console.log('pas de exif data')
return null
}
}).catch(error => console.log('Error: ' + error.message))
} }
const tagSeparator = ' ' const tagSeparator = ' '
const tagSectionSeparator = '--' const tagSectionSeparator = '--'
function findTagSectionInString(inputString){ let fileSectionsName;
function findTagSectionInString (inputString) {
let listOfTags = [] let listOfTags = []
if(inputString.includes(tagSectionSeparator)){ // remove extension
let boom = inputString.splice(tagSectionSeparator) let extensionFile = inputString.match(/\.\w{3,4}$/i)
if(boom.length){
listOfTags = [...boom.splice(tagSeparator)] extensionFile = extensionFile[0]
inputString = inputString.replace(extensionFile, '')
console.log('extensionFile', extensionFile)
if (inputString.includes(tagSectionSeparator)) {
console.log('inputString', inputString)
if (inputString.length) {
let boom = inputString.split(tagSectionSeparator)
console.log('boom', boom)
if (boom.length) {
fileSectionsName = boom.splice(tagSeparator);
listOfTags = [... fileSectionsName[1].trim().split(tagSeparator)]
console.log('listOfTags', listOfTags)
}else{
console.log('no boom', boom)
}
} }
} }
return listOfTags; return listOfTags
} }
/** /**
@ -135,6 +155,5 @@ const patternsFiles = {
'screenshot': '^Screenshot', // Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png 'screenshot': '^Screenshot', // Screenshot 2023-06-15 at 15-26-04 Instance Panoramax OSM-FR.png
} }
// 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')