up lowest date possible, refacto search date in exif tags
This commit is contained in:
parent
23f79d92df
commit
e0dca75316
29
index.ts
29
index.ts
@ -12,14 +12,31 @@ import log from 'loglevel'
|
||||
--------------------- */
|
||||
import rangement_instance from './conf/configs'
|
||||
import finder from './utils/finder'
|
||||
import minimist from "minimist";
|
||||
|
||||
const mini_arguments = minimist(process.argv.slice(2))
|
||||
|
||||
if (mini_arguments['help'] || mini_arguments['h']) {
|
||||
|
||||
console.log('Rangement - aide:', `
|
||||
Permet de renommer en masse des photos avec des ajouts de filetags automatiques.
|
||||
Documentation: https://www.cipherbliss.com/organiser-ses-fichiers-avec-des-tags-avec-filetags
|
||||
|
||||
syntaxe:
|
||||
rangement [fichiers] [options].
|
||||
options:
|
||||
-h, --help : affiche l'aide.
|
||||
-lowestYear=1970 : ne garde les dates exif pour le renommage que si elles sont supérieures à ce numéro d'année
|
||||
`)
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
log.setLevel(rangement_instance.log_level)
|
||||
log.info(' ')
|
||||
log.setLevel(rangement_instance.log_level)
|
||||
log.info(' ')
|
||||
|
||||
|
||||
finder.parseArguments()
|
||||
finder.guessFileNameOnAllFilesFromArguments()
|
||||
finder.parseArguments()
|
||||
finder.guessFileNameOnAllFilesFromArguments()
|
||||
|
||||
|
||||
console.log('hello ts', finder)
|
||||
}
|
||||
|
107
utils/finder.ts
107
utils/finder.ts
@ -25,6 +25,7 @@ export default class finder {
|
||||
filesModified: 0,
|
||||
filesNotModified: 0,
|
||||
}
|
||||
private static moments: any[] = []
|
||||
private static otherRenames: any = [];
|
||||
private static fileList: any = [];
|
||||
private static expandedFileList: any = [];
|
||||
@ -86,7 +87,7 @@ export default class finder {
|
||||
} else {
|
||||
|
||||
log.debug(' -------- le fichier existe bien, déstructuration')
|
||||
let structureForFile = this.destructurateFileName(fullPath)
|
||||
let structureForFile: fileDestructuration = this.destructurateFileName(fullPath)
|
||||
log.debug(' -------- ', fullPath)
|
||||
log.debug(' -------- ', structureForFile)
|
||||
|
||||
@ -101,15 +102,23 @@ export default class finder {
|
||||
this.findExifCreationDate(structureForFile.fullPath)
|
||||
.then(data => {
|
||||
log.info(' ... chercher la date de création : "' + structureForFile.freeText + '"')
|
||||
log.debug('data', data)
|
||||
let foundDate = this.findEarliestDateInExifData(data)
|
||||
let gpsData = this.findGpsCoordinates(data)
|
||||
if (gpsData) {
|
||||
structureForFile.tags.push('has-gps')
|
||||
}
|
||||
|
||||
let isScreenshot = this.findScreenshot(structureForFile.fileNameOriginal)
|
||||
|
||||
if (isScreenshot) {
|
||||
structureForFile.freeText.replace(`Capture d'écran`, '')
|
||||
structureForFile.freeText.replace(`Screenshot`, '')
|
||||
structureForFile.tags.push('screenshot')
|
||||
}
|
||||
|
||||
|
||||
log.info(' =>>>>>>> foundDate : ', foundDate)
|
||||
if (foundDate) {
|
||||
if (foundDate && (foundDate !== 'Invalid Date')) {
|
||||
structureForFile.dateStampExif = foundDate
|
||||
} else {
|
||||
log.info('pas de date trouvée dans le nom')
|
||||
@ -256,9 +265,13 @@ export default class finder {
|
||||
static parseArguments() {
|
||||
this.mini_arguments = minimist(process.argv.slice(2))
|
||||
log.debug('arguments', this.mini_arguments)
|
||||
if (this.mini_arguments['lowerYear']) {
|
||||
log.info('année minimale à retenir pour la sélection des dates:' , this.mini_arguments['lowerYear'])
|
||||
}
|
||||
if (!this.mini_arguments._.length) {
|
||||
log.info('pas de fichier ou de dossier demandé, veuillez spécifier un chemin en argument')
|
||||
}
|
||||
console.log('this.mini_arguments', this.mini_arguments)
|
||||
}
|
||||
|
||||
static shouldWeChangeName(structureForFile: fileDestructuration) {
|
||||
@ -498,6 +511,36 @@ export default class finder {
|
||||
return result
|
||||
}
|
||||
|
||||
static dateIsGood(date: Date):boolean {
|
||||
if (!date) {
|
||||
return false
|
||||
}
|
||||
let year: number = date.getFullYear();
|
||||
console.log('date', typeof date, year)
|
||||
console.log('(year > 1970)', (year > 1970))
|
||||
|
||||
|
||||
|
||||
let lowerYearPossible = this.mini_arguments['lowerYear']
|
||||
if(!lowerYearPossible){
|
||||
lowerYearPossible = 2004
|
||||
}
|
||||
let today: Date = new Date();
|
||||
let higherYearPossible = today.getFullYear()
|
||||
let isDateGood = (year >= lowerYearPossible) && (year <= higherYearPossible)
|
||||
console.log('lowerYearPossible', lowerYearPossible)
|
||||
if(!isDateGood){
|
||||
log.warn(' date is not good :', date)
|
||||
}
|
||||
return isDateGood
|
||||
}
|
||||
|
||||
private static pushToMomentDatesIfGood(someDate: Date): void {
|
||||
if (this.dateIsGood(someDate)) {
|
||||
this.moments.push(someDate)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* finds the earliest part in several exif date info
|
||||
* @param exifData
|
||||
@ -505,57 +548,24 @@ export default class finder {
|
||||
*/
|
||||
static findEarliestDateInExifData(exifData: any) {
|
||||
log.debug(' finder - findEarliestDateInExifData')
|
||||
|
||||
if (exifData) {
|
||||
|
||||
let moments = []
|
||||
let exifDates: string[] = ['DateTimeOriginal', 'FileModificationDateTime', 'FileModificationDate', 'ModificationDateTime', 'ModifyDate', 'FileAccessDateTime', 'DateTime', 'FileInodeChangeDateTime', 'CreateDate']
|
||||
exifDates.forEach((exifDateKind: string): void => {
|
||||
if (exifData[exifDateKind]) {
|
||||
log.debug(' finder exifDates - : ', exifDateKind, exifData[exifDateKind])
|
||||
this.pushToMomentDatesIfGood(exifData[exifDateKind])
|
||||
}
|
||||
})
|
||||
|
||||
console.log(' finder - exif data : ', exifData)
|
||||
log.info(' finder - exif data : ', exifData)
|
||||
if (exifData.DateTimeOriginal) {
|
||||
log.debug(' finder - image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal)
|
||||
moments.push(exifData.DateTimeOriginal)
|
||||
}
|
||||
if (exifData.FileModificationDateTime) {
|
||||
log.debug(' finder - image créée le : File Modification Date/Time : ', exifData.FileModificationDateTime)
|
||||
moments.push(exifData.FileModificationDateTime)
|
||||
}
|
||||
if (exifData.FileModificationDate) {
|
||||
log.debug(' finder - image créée le : File Modification Date/Time : ', exifData.FileModificationDate)
|
||||
moments.push(exifData.FileModificationDate)
|
||||
}
|
||||
if (exifData.ModificationDateTime) {
|
||||
log.debug(' finder - image créée le : ModificationDateTime : ', exifData.ModificationDateTime)
|
||||
moments.push(exifData.ModificationDateTime)
|
||||
}
|
||||
if (exifData.ModifyDate) {
|
||||
log.debug(' finder - image créée le : ModifyDate : ', exifData.ModifyDate)
|
||||
moments.push(exifData.ModifyDate)
|
||||
}
|
||||
if (exifData.FileAccessDateTime) {
|
||||
moments.push(exifData.FileAccessDateTime)
|
||||
}
|
||||
if (exifData.DateTime) {
|
||||
moments.push(exifData.DateTime)
|
||||
}
|
||||
if (exifData.FileInodeChangeDateTime) {
|
||||
moments.push(exifData.FileInodeChangeDateTime)
|
||||
}
|
||||
if (exifData.FileModificationDateTime) {
|
||||
log.debug(' finder - image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime)
|
||||
moments.push(exifData.FileModificationDateTime)
|
||||
}
|
||||
if (exifData.CreateDate) {
|
||||
// donne des dates trop anciennes par rapport à la réalité
|
||||
// log.debug(' finder - image créée le : CreateDate : ', exifData.CreateDate)
|
||||
// moments.push(exifData.CreateDate)
|
||||
}
|
||||
|
||||
moments = moments.map(d => {
|
||||
this.moments = this.moments.map(d => {
|
||||
let newdate = moment(d)
|
||||
return newdate
|
||||
})
|
||||
let minDate = moment.min(moments)
|
||||
let minDate = moment.min(this.moments)
|
||||
|
||||
log.info(' finder - dates moments:', this.moments)
|
||||
log.debug(' finder - minDate :::::::::', minDate)
|
||||
log.info(' finder - minDate :::::::::', minDate.format(rangement_instance.iso_date_format))
|
||||
|
||||
@ -592,7 +602,7 @@ export default class finder {
|
||||
}
|
||||
|
||||
let exifPromise = await exifr.parse(filepath);
|
||||
log.debug(' -------- exifdata', exifPromise)
|
||||
// log.debug(' -------- exifdata', exifPromise)
|
||||
|
||||
return exifPromise
|
||||
|
||||
@ -608,4 +618,5 @@ export default class finder {
|
||||
return [folders, fileName]
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user