scripts/kartaview_exif_mapper/map-from-csv.ts

118 lines
3.1 KiB
TypeScript

/**
conversion de données gpx
conversion de données exif
**/
// const fs = require('fs');
import {parse} from 'csv-parse/sync';
// @ts-ignore
import * as fs from 'node:fs';
// @ts-ignore
import path from "node:path";
// @ts-ignore
import minimist from 'minimist';
import {writeFileSync} from "fs";
// @ts-ignore
const moment = require("moment");
// configs
let dossier_photo = "/home/poule/encrypted/stockage-syncable/photos/imagerie kartaview carto tel/kartaview_export_storage/share2tykayn/photo/"
let csv_file_path = "/home/tykayn/Nextcloud/ressources/social sorting/photos_gps_metadata_kartaview.csv"
let mini_arguments: any = minimist(process.argv.slice(2))
console.log('mini_arguments', mini_arguments)
interface csv_kartaview_interface{
sequence_id: string,
sequence_index: string,
name: string,
shot_date: string,
lat: string,
lng: string,
heading: string
}
/**
* example:
* {
* sequence_id: '3596249',
* sequence_index: '1',
* name: '3596249_f3ccd_60a0f9cda58b5.jpg',
* shot_date: '2020-09-04 13:13:19.000',
* lat: '48.618406',
* lng: '2.125376',
* heading: '106.61'
* }
*/
function main() {
// TODO make it all
// ouvrir le fichier csv
// lire ses infos, mais seulement pour les photos des premiers 160 dossiers. jusqu'à 2810714.
// trouver les photos à partir du nom de fichier
// prendre les données du csv et les appliquer à chaque photo
// sauvegarder chaque photo
// Load the CSV file
let csv_as_json = csv_to_json(csv_file_path)
csv_as_json.shift()
// console.log('records', csv_as_json)
let bash_script_exif_content = `#!/bin/bash
echo "applying exif info to photos"
`;
csv_as_json.forEach(( elem :csv_kartaview_interface)=> {
let iso = elem.shot_date;
let boom = elem.name.split('_')
let sequence_name:string = boom[0]
console.log('sequence_name', sequence_name)
let exif_command = `\n
exiftool -overwrite_original \\
-GPSDateTime="${iso}" \\
-AllDates="${iso}" \\
-MediaCreateDate="${iso}" \\
-MediaModifyDate="${iso}" \\
-TrackCreateDate=="${iso}" \\
-TrackModifyDate=="${iso}" \\
-GPSTrack="${elem.heading}" \\
-GPSImgDirection="${elem.heading}" \\
-GPSLongitude="${elem.lng}" \\
-GPSLatitude="${elem.lat}" \\
"${dossier_photo + sequence_name +'/'+ elem.name}"
`
bash_script_exif_content += exif_command
})
let ouput_bash_name= 'script_exif_apply_kartaview_from_csv.sh'
writeFileSync(ouput_bash_name, bash_script_exif_content)
console.log('fichier écrit', ouput_bash_name)
console.log('csv_as_json.length',csv_as_json.length)
}
// run it all
main()
function csv_to_json(csv_file_path:string){
const data = fs.readFileSync(csv_file_path,
{encoding: 'utf8', flag: 'r'});
const records = parse(data, {
columns: true,
skip_empty_lines: true
});
return records
}