From 1468f0387ceb3847e1e9443efcbe89aaaa91afb5 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Mon, 14 Aug 2023 16:55:58 +0200 Subject: [PATCH] add exif lib --- kartaview_exif_mapper/main.ts | 98 ++++++++++++++++------------------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/kartaview_exif_mapper/main.ts b/kartaview_exif_mapper/main.ts index aa663330..a28b4630 100644 --- a/kartaview_exif_mapper/main.ts +++ b/kartaview_exif_mapper/main.ts @@ -2,6 +2,9 @@ conversion de données gpx conversion de données exif **/ + +// @ts-ignore +import piexif, { IExif, IExifElement, TagValues } from 'piexif'; import * as fs from 'node:fs'; // @ts-ignore import path from "node:path"; @@ -22,7 +25,7 @@ let folders_list_txt: any = [ // "6102537", "6102569", "6127433", "6133465", "6242729", "6329129", "6329177", "6329241", "6329305", "6329321", "6738633", "6738809", "6738953", "6752761", // "6752889", // "6752905", - "6752921", + // "6752921", "6752937", // "6752953", "6760985", "6761049", "6761289", "6794633", "7325929", "7326457", "7328265", "7330009", "7330025", // "7330041", @@ -51,7 +54,7 @@ if (mini_arguments['gpx-input']) { } -let dossier_photo: string = folder + "photo" +let dossier_photo: string = folder + "test_photo_apply" let dossier_gpx_input: string = folder + "metadata_file" let path_gpx_input: string = dossier_gpx_input + "/" + sequence_name + "/" + file_gpx @@ -61,7 +64,6 @@ if (mini_arguments['gpx-input-path']) { let gpxData: any = {} -let tableKartaviewTrace: any = [] function makeGpxFromKartaview(tableKartaviewTrace: any) { @@ -113,29 +115,43 @@ function reduceGpxPointsToInterval(sequence_name: any) { let interval = Math.round(gpxData[sequence_name].length / photos_count_in_sequence) let ii = 1; console.log('--------- sequence_name', sequence_name) + console.log('--------- nombre de photos ', photos_count_in_sequence) + console.log('--------- nombre de points gpx ', gpxData[sequence_name].length) console.log('--------- interval: prendre une donnée gps tous les ', interval, 'points de la trace de séquence') - let jj=0 + let jj = 0 let photo_counter = 0 gpxData[sequence_name].forEach((elem: any) => { // only work on an interval of files to assign gps coordinates jj++ ii-- - if(ii<=0){ + if (ii <= 0) { // set the gps coordinates to the picture in sequence let timestamp = elem[6] * 1000 let lat = elem[0] let lon = elem[1] let date = new Date(timestamp) let iso = date.toISOString() - console.log('* point de trace n°', jj) - console.log('* lat, lon', lat,lon) - console.log('* date iso', iso) - ii =interval*1 - photo_counter++ + // console.log('* point de trace n°', jj) + // console.log('* lat, lon', lat,lon) + // console.log('* date iso', iso) + ii = interval * 1 + + let exif = {}; + + exif[piexif.ExifIFD.DateTimeOriginal] = iso; + + let file_photo_name = photo_folders_counter[sequence_name][photo_counter] - console.log('file_photo_name to apply exif data', file_photo_name) + console.log('file_photo_name to apply exif data', photo_counter, file_photo_name) + if (file_photo_name) { + // set exif data + // https://piexifjs.readthedocs.io/en/latest/functions.html#insert + // piexif.insert(exifStr, jpegData) + + } + photo_counter++ } }) @@ -183,7 +199,7 @@ function openKartaviewTxtGPX(filepath: any, sequence_name: string) { writeFile('' + fileName + '_trace.gpx', content_gpx) } - if(Object.keys(gpxData).length === folders_list_txt.length){ + if (Object.keys(gpxData).length === folders_list_txt.length) { gather() } // console.log('gpx_content', gpx_content) @@ -193,8 +209,6 @@ function openKartaviewTxtGPX(filepath: any, sequence_name: string) { let cwd = path.dirname(process.cwd()) + '/' + path.basename(process.cwd()) -let expandedFileList: any = [] - /** * get a list of all files in a path * @param folderPath @@ -204,31 +218,10 @@ async function getAllFilesInFolder(folderPath: string) { console.log('reading folder ', folderPath) filesList = fs.readdirSync(folderPath); - // console.log('readSubdirectories - files', folderPath, filesList.length) - - // filesList.forEach((subDirOrFile:any) => { - // const newFullPath = cwd + '/' + subDirOrFile - // - // if (fs.existsSync(newFullPath)) { - // const s = fs.statSync(newFullPath) - // - // if (s.isFile()) { - // expandedFileList.push(cwd + '/' + subDirOrFile) - // console.log('add file', cwd + '/' + subDirOrFile) - // } - // } - // }) return filesList; } -function mapExifDataOnListOfFilesFromGpxData(listOfFiles: any, gpxData: any) { - listOfFiles.forEach((elem: any) => { - // find corresponding timestamp - // add exif info - // save file - }) -} function writeFile(fileName: string, fileContent: any) { console.log('write file', fileName) @@ -248,17 +241,9 @@ let photo_folders_counter: any = {} function listPhotos(sequence_number: string) { let photo_folder = dossier_photo + '/' + sequence_number; - - let gps_points = gpxData[sequence_number] - // console.log('gps_points', gps_points) - // pour réconcilier les données, on divise la trace en part égales du nombre de photos présentes dans la séquence. - getAllFilesInFolder(photo_folder) .then(listOfFiles => { - - // console.log('listOfFiles', listOfFiles) photo_folders_counter[sequence_number] = listOfFiles - }) } @@ -282,15 +267,9 @@ async function getGPXAndEnrichExifOfPhotosInFolder(sequence_number: string) { } -console.log('dossiers à traiter: ', folders_list_txt.length) -folders_list_txt.forEach((elem: string) => { - getGPXAndEnrichExifOfPhotosInFolder(elem).then(r => { - console.log('r', r) - } - ) -}) - - +/** + * runs after all sequences have gotten their photo and gpx data + */ function gather() { @@ -303,3 +282,18 @@ function gather() { }) } + +function main() { + + console.log('dossiers à traiter: ', folders_list_txt.length) + folders_list_txt.forEach((elem: string) => { + getGPXAndEnrichExifOfPhotosInFolder(elem).then(r => { + console.log('r', r) + } + ) + }) +} + +// run it all +main() +