Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | 2x 2x 5x 5x 5x 5x 2x 5x 8x 8x 8x 3x 3x 3x 3x 3x 3x 1x 3x 3x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | /** * la classe qui repère des patterns */ import rangement_instance from './configs.mjs' import exifr from 'exifr' import moment from 'moment' import log from 'loglevel' log.setLevel(rangement_instance.log_level) /** * finds patterns for file name */ export default class finder { static statistics = { filesModified: 0, } static reportStatistics () { log.info('statistics', this.statistics) } static findScreenshot (inputString) { return inputString.match(/screenshot/i) || inputString.match(/capture d'écran/i) } static findFormattedDate (filepath) { let match = filepath.match(/\d{4}-\d{2}-\d{2}T\d{2}\.\d{2}\.\d{2}/ig) log.debug(' finder - match findFormattedDate', match) let result = '' if (match && match[0]) { result = match[0] } return result } static findFileExtension (inputString) { let result = inputString.match(/\.\w{3,4}$/i) Eif (result.length) { return result[0] } return '' } /** * find the section of file name which contains the free text to describe the picture * @param fileName * @returns {*|string} */ static findFileNameFreeTextPart (fileName) { fileName = fileName.replace(this.findFileExtension(fileName), '') let boom = fileName.split(rangement_instance.tagSectionSeparator) Eif (boom.length) { let freeTextPart = boom[0].trim() // remove date let foundDate = this.findFormattedDate(freeTextPart) if (foundDate) { freeTextPart = freeTextPart.replace(foundDate, '').trim() } log.debug(' finder - freeTextPart:', freeTextPart) return freeTextPart } return fileName.trim() } /** * find an array of tags * @param inputString * @returns {[]} */ static findTagSectionInString (inputString) { let listOfTags = [] // remove extension let extensionFile = finder.findFileExtension(inputString) if (extensionFile) { inputString = inputString.replace(extensionFile, '') } else E{ log.debug(' finder - no extensionFile', extensionFile, inputString) extensionFile = '' } inputString = inputString.replace(extensionFile, '') log.debug(' finder - extensionFile', extensionFile) Eif (inputString.includes(rangement_instance.tagSectionSeparator)) { log.debug(' finder - inputString', inputString) Eif (inputString.length) { let boom = inputString.split(rangement_instance.tagSectionSeparator) log.debug(' finder - boom', boom) if (boom.length) { let fileSectionsName = boom.splice(rangement_instance.tagSeparator) listOfTags = [...fileSectionsName[1].trim().split(rangement_instance.tagSeparator)] log.debug(' finder - listOfTags', listOfTags) } else E{ log.debug(' finder - no boom', boom) } } } return listOfTags } static cleanSpaces (inputString) { return inputString.trim().replace(/ *g/, ' ') } static searchAndReplaceInFileName (searchString, replaceString, fileName) { return this.cleanSpaces(fileName.replace(searchString, replaceString)) } /** * search screenshot clues and rename */ static searchAndRenameScreenshots (fileName) { if (finder.findScreenshot(fileName)) { let tags = this.findTagSectionInString(fileName) log.debug(' finder - tags', tags) if (!tags.includes('screenshot')) { fileName = this.addTagInFileName('screenshot', fileName) fileName = this.searchAndReplaceInFileName('Screenshot', '', fileName) log.debug(' finder - screenShotMockFileName:', fileName) return this.cleanSpaces(fileName) } log.debug(' finder - is a screenshot, remove screenshot in name, and add tag screenshot') } else { return null } } static addTagInFileName (tagName, fileName) { let tags = this.findTagSectionInString(fileName) let firstPart = this.findFileNameFreeTextPart(fileName) tags.push(tagName) let uniqueArray = [...new Set(tags)] let newFileName = firstPart + ' ' + rangement_instance.tagSectionSeparator + ' ' + tags.join(rangement_instance.tagSeparator) newFileName = newFileName.replace(/ {*}/, '') + this.findFileExtension(fileName) return this.cleanSpaces(newFileName) } /** * convertit un nom de fichier en une structure décrivant plusieurs parties correspondant au pattern d'archivage * @param fullPath * @returns {{extension: *, dateStamp: string, freeText: (*|string), tags: *[]}} */ static destructurateFileName (fullPath) { let [folderPath, fileNameOriginal] = this.findFolderPath(fullPath) let dateStampInFileNameOriginal = this.findFormattedDate(fileNameOriginal) return { fullPath, folderPath, fileNameOriginal, dateStampInFileNameOriginal, dateStampExif: '', freeText: this.findFileNameFreeTextPart(fileNameOriginal), tags: this.findTagSectionInString(fileNameOriginal), extension: this.findFileExtension(fileNameOriginal), } } /** * finds the earliest part in several exif date info * @param exifData * @returns {string} */ static findEarliestDateInExifData (exifData) { if (exifData) { let moments = [] log.debug(' finder - exif data : ', exifData) // Do something with your data! if (exifData.DateTimeOriginal) { log.debug(' finder - image créée le : DateTimeOriginal : ', exifData.DateTimeOriginal) // Do something with your data! moments.push(exifData.DateTimeOriginal) } if (exifData.ModificationDateTime) { log.debug(' finder - image créée le : ModificationDateTime : ', exifData.ModificationDateTime) // Do something with your data! moments.push(exifData.ModificationDateTime) } if (exifData.ModifyDate) { log.debug(' finder - image créée le : ModifyDate : ', exifData.ModifyDate) // Do something with your data! moments.push(exifData.ModifyDate) } if (exifData.FileAccessDateTime) { moments.push(exifData.FileAccessDateTime) } if (exifData.FileInodeChangeDateTime) { moments.push(exifData.FileInodeChangeDateTime) } if (exifData.FileModificationDateTime) { log.debug(' finder - image créée le : FileModificationDateTime : ', exifData.FileModificationDateTime) // Do something with your data! moments.push(exifData.FileModificationDateTime) } if (exifData.CreateDate) { log.debug(' finder - 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) log.debug(' finder - minDate :::::::::', minDate) log.info(' finder - minDate :::::::::', minDate.format(rangement_instance.iso_date_format)) return minDate.format(rangement_instance.iso_date_format) } else { log.debug(' finder - pas de exif data') return '' } } static findTemplateInFileName (fileName) { // test all templates from configuration } static appendFileName(fileProperties, newText) { fileProperties.freeText = finder.cleanSpaces(fileProperties.freeText + ' ' + newText) return fileProperties } static prependFileName(fileProperties, newText) { fileProperties.freeText = finder.cleanSpaces(newText + ' ' + fileProperties.freeText) return fileProperties } /** * examine plusieurs propriétés exif de date et retourne la plus ancienne * @param filepath */ static async findExifCreationDate (filepath) { log.debug(' finder - filepath', filepath) let dateAlreadyInFileName = finder.findFormattedDate(filepath) if (dateAlreadyInFileName) { log.debug(' finder - ------ dateAlreadyInFileName', dateAlreadyInFileName) } return await exifr.parse(filepath) } static findFolderPath (filePath) { let folders = filePath.split('/') let fileName = folders.pop() folders = filePath.replace(fileName, '') log.debug(' finder - \n - folders', folders) log.debug(' finder - - fileName', fileName, '\n') return [folders, fileName] } } |