scripts/kartaview_exif_mapper/map-from-csv.ts

118 lines
3.1 KiB
TypeScript
Raw Normal View History

2023-09-20 17:33:05 +02:00
/**
conversion de données gpx
conversion de données exif
**/
2023-10-12 12:01:20 +02:00
// const fs = require('fs');
import {parse} from 'csv-parse/sync';
2023-09-20 17:33:05 +02:00
// @ts-ignore
import * as fs from 'node:fs';
// @ts-ignore
import path from "node:path";
// @ts-ignore
import minimist from 'minimist';
2023-10-12 12:01:20 +02:00
import {writeFileSync} from "fs";
2023-09-20 17:33:05 +02:00
// @ts-ignore
const moment = require("moment");
// configs
2023-10-12 12:01:20 +02:00
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"
2023-09-20 17:33:05 +02:00
let mini_arguments: any = minimist(process.argv.slice(2))
console.log('mini_arguments', mini_arguments)
2023-10-12 12:01:20 +02:00
interface csv_kartaview_interface{
sequence_id: string,
sequence_index: string,
name: string,
shot_date: string,
lat: string,
lng: string,
heading: string
2023-09-20 17:33:05 +02:00
}
2023-10-12 12:01:20 +02:00
/**
* 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'
* }
*/
2023-09-20 17:33:05 +02:00
function main() {
2023-10-12 10:52:04 +02:00
// TODO make it all
// ouvrir le fichier csv
2023-10-12 12:01:20 +02:00
// lire ses infos, mais seulement pour les photos des premiers 160 dossiers. jusqu'à 2810714.
2023-10-12 10:52:04 +02:00
// trouver les photos à partir du nom de fichier
// prendre les données du csv et les appliquer à chaque photo
// sauvegarder chaque photo
2023-10-12 12:01:20 +02:00
// 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}" \\
2023-10-12 12:01:20 +02:00
-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)
2023-09-20 17:33:05 +02:00
}
// run it all
main()
2023-10-12 12:01:20 +02:00
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
}