check source photo exists

This commit is contained in:
Tykayn 2023-11-23 15:14:37 +01:00 committed by tykayn
parent a9d8e372d8
commit 67c1130498
2 changed files with 87 additions and 33 deletions

View File

@ -0,0 +1,53 @@
const fs = require('fs');
const path = require('path');
// Chemin du dossier INBOX_a_assembler
const inboxDir = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_a_assembler';
// Chemin du dossier de destination pour les séquences assemblées
const outDir = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_a_assembler';
// Parse les fichiers dans le dossier INBOX_a_assembler
fs.readdirSync(inboxDir).forEach((file: any) => {
console.log('file', file)
let dossier = file
// Ignorer les fichiers qui ne sont pas des dossiers
if (!fs.lstatSync(path.join(inboxDir, dossier)).isDirectory()) return;
console.log('dossier', dossier)
// Extraire le numéro du nom de fichier
const number = dossier.match(/\d+/);
console.log('number', number[0])
// Si le dossier de la séquence existe déjà, ignorez-le
// if (fs.existsSync(path.join(outDir, number[0]))) return;
// Créer le dossier de la séquence
// fs.mkdirSync(path.join(outDir, number[0]));
// Copier les photos front et back dans le nouveau dossier
let lepath_source_front = path.join('' + inboxDir, number[0] + 'GFRNT', '*.JPG')
let lepath_source_back = path.join('' + inboxDir, number[0] + 'GBACK', '*.JPG')
let lepath_destination = path.join('' + outDir, number[0])
console.log('source front', lepath_source_front)
console.log('source back', lepath_source_back)
console.log('destination', lepath_destination)
const files_front = fs.readdirSync(path.join(inboxDir, number[0] + 'GFRNT'));
console.log('files front', files_front.length)
if (files_front.length > 2) {
fs.renameSync(lepath_source_front, lepath_destination);
}
const files_back = fs.readdirSync(path.join(inboxDir, number[0] + 'GBACK'));
console.log('files back', files_back.length)
if (files_back.length > 2) {
fs.renameSync(lepath_source_back, lepath_destination);
}
});

View File

@ -1,7 +1,8 @@
/**
conversion de données gpx
conversion de données exif
utilisation:
Utilisation:
ts-node main.ts --goproMin=80800 --goproMax=80801 --goproSubFolder="rouen_oct23"
**/
@ -10,21 +11,21 @@
import * as fs from 'node:fs';
// @ts-ignore
import minimist from 'minimist';
// @ts-ignore
const moment = require("moment");
let mini_arguments: any = minimist(process.argv.slice(2))
// configs
/**
* ces paramètres permettent de traiter par lots des assemblages sans avoir à scanner le dossier
*/
let gorpro_fusion_separated_photos_folder = ''
let gopro_fusion_separated_photos_folder = ''
let disable_pto_write = true;
let previous_zero = '0'// numéro de photo gopro minimum front et back. correspond à GF080800.JPG + GB080800.JPG
let goproMin = 80800// numéro de photo gopro minimum front et back. correspond à GF080800.JPG + GB080800.JPG
let goproMax = 80801 // et maximum. correspond à GF080866.JPG + GB080866.JPG
let addExifToolInScript = false;
let outputStitchedFolder = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/hugin_assemblages_script_output/'
let addExifToolInScript = true;
let base_gopro_folder = '/home/poule/encrypted/stockage-syncable/photos/imageries/gopro'
let outputStitchedFolder = base_gopro_folder + '/hugin_assemblages_script_output/'
if (mini_arguments['addExifToolInScript']) {
addExifToolInScript = mini_arguments['addExifToolInScript']
@ -36,7 +37,7 @@ if (mini_arguments['goproMin']) {
goproMin = mini_arguments['goproMin']
}
if (mini_arguments['goproSubFolder']) {
gorpro_fusion_separated_photos_folder = mini_arguments['goproSubFolder']
gopro_fusion_separated_photos_folder = mini_arguments['goproSubFolder']
}
if (mini_arguments['goproMax']) {
goproMax = mini_arguments['goproMax']
@ -51,15 +52,13 @@ extension_photo_source = 'JPG'
let gopro_folder = "/home/poule/encrypted/stockage-syncable/photos/imageries/gopro";
let dossier_pto_output = `/home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_PTO_hugin`;
let absolutePath = `${gopro_folder}/${gorpro_fusion_separated_photos_folder}`;
let folder = `${gopro_folder}/${gorpro_fusion_separated_photos_folder}`
let absolutePath = `${gopro_folder}/${gopro_fusion_separated_photos_folder}`;
let folder = `${gopro_folder}/${gopro_fusion_separated_photos_folder}`
if (mini_arguments['folder']) {
folder = mini_arguments['folder']
}
let subFolder = ""
let dossier_assemblages_output = `${gopro_folder}/hugin_assemblages_script_output`;
console.log('mini_arguments', mini_arguments)
@ -83,9 +82,9 @@ function findMinMaxNumberOfPhotos(dirPath: string): { min: number, max: number }
// Vérifier si le fichier est un fichier JPG
if (path.extname(file) === '.jpg' || path.extname(file) === '.JPG') {
// Éxtraire le nombre du nom de fichier
let matches:any = file.match(/(\d+)/);
let matches: any = file.match(/(\d+)/);
if (matches && matches.length && matches[0]) {
let number = 1 * parseInt(matches[0]);
let number = parseInt(matches[0]);
// Sauver le nombre minimal et maximal trouvé jusqu'à présent
if (minNumber === 0 && number > 0) {
@ -104,11 +103,6 @@ function findMinMaxNumberOfPhotos(dirPath: string): { min: number, max: number }
}
}
function getGoproFiles(folder: string) {
console.log('getGoproFiles folder', folder)
return fs.readdirSync('' + folder)
}
function makeBashScriptHugin(minmax: any) {
console.log('makeBashScriptHugin')
@ -119,28 +113,33 @@ function makeBashScriptHugin(minmax: any) {
minmax.max
); ii++) {
// console.log('make PTO file : ii', ii)
// makePto(absolutePath, ii)
let currentNumber = `${previous_zero}${ii}`;
// let currentNumber = '080096';
let ptoContent = makePto(absolutePath, currentNumber);
let ptoFileName = `merging_${currentNumber}.pto`
let stitchedFileName = `assemblage_${currentNumber}`
let input_front_jpg = base_gopro_folder + '/' + gopro_fusion_separated_photos_folder + '/GF' + currentNumber + '.JPG'
let ptoPath = `${dossier_pto_output}/${ptoFileName}`
scriptsContent += '\n\n# capture n°' + currentNumber
scriptsContent += '\nif [ ! -f ' + outputStitchedFolder + stitchedFileName + '.jpg ]; then \n' +
'hugin_executor' +
scriptsContent +=
'\nif [ ! -f ' + outputStitchedFolder + stitchedFileName + '.jpg ]; then \n' +
'\n if [ -f ' + input_front_jpg + ' ]; then \n' +
' hugin_executor' +
' ' + ptoPath + ' ' +
'--stitching ' +
'--prefix=' + stitchedFileName +
' -t=6' +
'\n' +
' fi' +
'\n' +
'fi'
if (!disable_pto_write) {
// console.log('ptoContent', ptoContent)
writeFile(ptoFileName, ptoContent)
}
}
@ -150,9 +149,9 @@ function makeBashScriptHugin(minmax: any) {
}
console.log('##############\n pour lancer le script : \n', 'bash /home/poule/encrypted/stockage-syncable/photos/imageries/gopro/INBOX_PTO_hugin/hugin_executor_from_' + goproMin + '_to_' + goproMax + '.sh',
'\n'+
' bash /home/poule/encrypted/stockage-syncable/www/development/html/scripts/hugin-gopro-fusion/exif_batch.sh '+goproMin+' '+goproMax+' '+gorpro_fusion_separated_photos_folder,
'\n'+
'\n' +
' bash /home/poule/encrypted/stockage-syncable/www/development/html/scripts/hugin-gopro-fusion/exif_batch.sh ' + goproMin + ' ' + goproMax + ' ' + gopro_fusion_separated_photos_folder,
'\n' +
'\n##############\n'
)
console.log('hugin_batch_command: \n', hugin_batch_command)
@ -160,7 +159,6 @@ function makeBashScriptHugin(minmax: any) {
writeFile('hugin_executor_from_' + goproMin + '_to_' + goproMax + '.sh', scriptsContent);
}
function makePto(absolutePath: string, currentNumber: string) {
@ -274,10 +272,12 @@ function writeFile(fileName: string, fileContent: any) {
)
}
let scriptsContent = '#!/bin/bash' +
'\necho "éxécuter tous les fichiers PTO dans : ' + dossier_assemblages_output + '"\n ' +
'\ncd ' + dossier_assemblages_output + '\n';
'\n pwd\n';
let scriptsContent = `#!/bin/bash
echo "éxécuter tous les fichiers PTO dans : ${dossier_assemblages_output}"
cd ${dossier_assemblages_output}
`;
"\n pwd\n";
function main() {
@ -287,6 +287,7 @@ function main() {
})
}
let minmax = findMinMaxNumberOfPhotos(folder)
console.log('minmax', minmax)