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