2023-12-09 12:02:54 +01:00
|
|
|
import fs from "node:fs";
|
|
|
|
import path from "path";
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
import minimist from 'minimist';
|
2023-12-21 16:09:19 +01:00
|
|
|
import * as childProcess from 'child_process';
|
2023-12-09 12:02:54 +01:00
|
|
|
|
|
|
|
let mini_arguments: any = minimist(process.argv.slice(2))
|
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
let enable_batch_move_assembled_files = false;
|
|
|
|
|
|
|
|
let should_exec_geovisio_upload = false;
|
|
|
|
|
2023-12-09 12:02:54 +01:00
|
|
|
let folder = `/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_a_assembler/`
|
|
|
|
let subfolder = ``
|
|
|
|
|
|
|
|
if (mini_arguments['folder']) {
|
|
|
|
subfolder = mini_arguments['folder']
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* trouver les valeux min et max de numéros de séquence gopro dans un dossier contenant des photos jpg
|
|
|
|
* @param dirPath
|
|
|
|
*/
|
|
|
|
function findMinMaxNumberOfPhotos(dirPath: string): { min: number, max: number } {
|
|
|
|
|
|
|
|
console.log('dirPath', dirPath)
|
|
|
|
|
|
|
|
let minNumber: number = 0;
|
|
|
|
let maxNumber: number = 0;
|
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
let previousFileName = 0
|
2023-12-09 12:02:54 +01:00
|
|
|
// Boucler sur chaque fichier JPG dans le dossier
|
|
|
|
fs.readdirSync(dirPath).forEach(file => {
|
2023-12-21 16:09:19 +01:00
|
|
|
|
|
|
|
let currentFileName = path.extname(file)
|
2023-12-09 12:02:54 +01:00
|
|
|
// Vérifier si le fichier est un fichier JPG
|
2023-12-21 16:09:19 +01:00
|
|
|
if (currentFileName === '.jpg' || currentFileName === '.JPG') {
|
2023-12-09 12:02:54 +01:00
|
|
|
// Éxtraire le nombre du nom de fichier
|
|
|
|
let matches: any = file.match(/(\d+)/);
|
|
|
|
if (matches && matches.length && matches[0]) {
|
|
|
|
let number = parseInt(matches[0]);
|
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
if (previousFileName + 1 !== number) {
|
|
|
|
console.log('saut de nombre / séquence à ', previousFileName, number)
|
|
|
|
}
|
2023-12-09 12:02:54 +01:00
|
|
|
// Sauver le nombre minimal et maximal trouvé jusqu'à présent
|
|
|
|
if (minNumber === 0 && number > 0) {
|
|
|
|
minNumber = number;
|
|
|
|
}
|
|
|
|
if (number > maxNumber) {
|
|
|
|
maxNumber = number;
|
|
|
|
}
|
2023-12-21 16:09:19 +01:00
|
|
|
|
|
|
|
previousFileName = number
|
2023-12-09 12:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
min: minNumber,
|
|
|
|
max: maxNumber,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = findMinMaxNumberOfPhotos(folder + subfolder)
|
2023-12-10 17:58:57 +01:00
|
|
|
console.log('result', result)
|
|
|
|
console.log("script :\n", `
|
|
|
|
ts-node /home/poule/encrypted/stockage-syncable/www/development/html/scripts/hugin-gopro-fusion/main.ts --goproSubFolder=INBOX_a_assembler/${subfolder}
|
|
|
|
bash /home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_PTO_hugin/hugin_executor_from_${result.min}_to_${result.max}.sh
|
|
|
|
bash /home/poule/encrypted/stockage-syncable/www/development/html/scripts/hugin-gopro-fusion/exif_batch.sh ${result.min} ${result.max} INBOX_a_assembler/${subfolder}
|
|
|
|
|
|
|
|
`)
|
2023-12-18 16:52:26 +01:00
|
|
|
|
|
|
|
const hugin_assemblages_script_output_path = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/hugin_assemblages_script_output';
|
2023-12-21 16:09:19 +01:00
|
|
|
const envois_todo_panoramax = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/PANORAMAX_envois_todo/' + subfolder;
|
2023-12-18 16:52:26 +01:00
|
|
|
const startNumber = result.min;
|
|
|
|
const endNumber = result.max;
|
|
|
|
|
|
|
|
// const startNumber = 1;
|
|
|
|
// const endNumber = 5;
|
|
|
|
|
|
|
|
function renameFile(fileName: string): void {
|
|
|
|
const filePath = path.join(hugin_assemblages_script_output_path, fileName);
|
|
|
|
|
|
|
|
if (fs.existsSync(filePath)) {
|
|
|
|
const newFileName = `assemblage_0${startNumber}.jpg`;
|
2023-12-21 16:09:19 +01:00
|
|
|
const newFilePath = path.join(envois_todo_panoramax, newFileName);
|
|
|
|
|
|
|
|
console.log('rename: ', filePath, newFilePath)
|
2023-12-18 16:52:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
fs.renameSync(filePath, newFilePath);
|
2023-12-21 16:09:19 +01:00
|
|
|
} else {
|
2023-12-18 16:52:26 +01:00
|
|
|
console.log('ce fichier est inexistant', filePath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function createDirectory(folderName: string): void {
|
2023-12-21 16:09:19 +01:00
|
|
|
console.log('createDirectory', folderName)
|
2023-12-18 16:52:26 +01:00
|
|
|
if (!fs.existsSync(folderName)) {
|
|
|
|
fs.mkdirSync(folderName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFileNames(): string[] {
|
|
|
|
const files = fs.readdirSync(hugin_assemblages_script_output_path);
|
|
|
|
const fileNames = files.filter((fileName) => {
|
|
|
|
const regex = /^assemblage_\d+(\.\d+)?\.jpg$/;
|
|
|
|
return regex.test(fileName);
|
|
|
|
});
|
|
|
|
|
|
|
|
return fileNames;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* déplacer des imageries assemblées en masse dans un dossier "à envoyer"
|
|
|
|
* @param startNumber
|
|
|
|
* @param endNumber
|
|
|
|
*/
|
2023-12-21 16:09:19 +01:00
|
|
|
function batch_move_assembled_files(startNumber: number, endNumber: number) {
|
2023-12-18 16:52:26 +01:00
|
|
|
const fileNames = getFileNames();
|
2023-12-21 16:09:19 +01:00
|
|
|
console.log('fileNames', fileNames)
|
2023-12-18 16:52:26 +01:00
|
|
|
|
|
|
|
for (let i = startNumber; i <= endNumber; i++) {
|
|
|
|
const fileName = `assemblage_0${i}.jpg`;
|
|
|
|
|
|
|
|
console.log('fileName', fileName)
|
2023-12-21 16:09:19 +01:00
|
|
|
renameFile(fileName);
|
2023-12-18 16:52:26 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
console.log(' déplacer les assemblages dans ' + envois_todo_panoramax, startNumber, endNumber)
|
2023-12-18 16:52:26 +01:00
|
|
|
|
|
|
|
createDirectory(envois_todo_panoramax);
|
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
if (enable_batch_move_assembled_files) {
|
|
|
|
|
|
|
|
batch_move_assembled_files(startNumber, endNumber)
|
|
|
|
}
|
2023-12-18 16:52:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
function executeCommand(command: string, folderName: string): void {
|
|
|
|
const fullCommand = `${command} "${folderName}"`;
|
|
|
|
|
|
|
|
childProcess.exec(fullCommand, (error, stdout, stderr) => {
|
|
|
|
if (error) {
|
|
|
|
console.error(`Error executing command: ${fullCommand}`);
|
|
|
|
console.error(error);
|
|
|
|
} else {
|
|
|
|
console.log(`Output of command: ${fullCommand}`);
|
|
|
|
console.log(stdout);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
function exec_geovisio(envois_todo_panoramax: string): void {
|
2023-12-18 16:52:26 +01:00
|
|
|
const folderName = envois_todo_panoramax;
|
|
|
|
const command = 'geovisio upload --api-url https://panoramax.openstreetmap.fr';
|
|
|
|
|
|
|
|
executeCommand(command, folderName);
|
|
|
|
}
|
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
if (should_exec_geovisio_upload) {
|
|
|
|
exec_geovisio(envois_todo_panoramax);
|
|
|
|
} else {
|
|
|
|
console.log(' l envoi vers geovisio automatique est désactivé ')
|
|
|
|
}
|
2023-12-18 16:52:26 +01:00
|
|
|
|
2023-12-21 16:09:19 +01:00
|
|
|
console.log("exécuter geovisio upload")
|