-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathingestor.ts
131 lines (115 loc) · 3.97 KB
/
ingestor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/* tslint:disable:2691*/
import {ensureDirSync, existsSync, copy} from "https://deno.land/[email protected]/fs/mod.ts";
import { parse } from "https://deno.land/std/flags/mod.ts";
import { delay } from "https://deno.land/[email protected]/async/mod.ts";
import { exec, OutputMode, IExecResponse } from "https://deno.land/x/exec/mod.ts";
const opts = parse(Deno.args);
const inDir = opts?.["_"]?.[0] + "";
function jpgtranCommandGenerator(infile: string, outfile: string):string {
let command = "jpegtran";
command += " -copy all";
command += " -rotate 270";
if(opts?.c) command += " -crop 3000x3100+0+450";
command += ` -outfile ${outfile}`;
command += ` ${infile}`;
return command;
}
function exiftoolCommandGenerator(file:string, rig:string, date:string): string {
let command = "exiftool";
command += `-ExifIFD:SerialNumber="${rig}"`
command += `-ExifIFD:DateTimeOriginal="${date}"`
command += `-ExifIFD:FocalLengthIn35mmFormat="59.4034"`
if(opts?.test)command += "-v3"
command += ` ${file}`;
return command;
}
if(!inDir){
console.log("No Import Directory Given!");
Deno.exit(1);
}
if(!existsSync(inDir)){
console.log("Import Directory Is Missing!");
Deno.exit(1);
}
// Check exiftool
{
let response: IExecResponse;
try {
response = await exec(
"exiftool",
{ output: OutputMode.Capture },
);
} catch (error) {
response = {status:{code:99,success:false},output:""};
}
if(
response.status.code != 0 ||
!response.status.success ||
response.output != "Syntax: exiftool [OPTIONS] FILE\n\nConsult the exiftool documentation for a full list of options."
){
console.log("Failed to verify exiftool is installed!");
Deno.exit(2);
}
}
// Check jpegtran
{let response: IExecResponse;
try {
response = await exec(
"jpegtran -version",
{ output: OutputMode.Capture },
);
} catch (error) {
response = { status: { code: 99, success: false }, output: "" };
}
if(
response.status.code != 0 ||
!response.status.success ||
response.output != ""
){
console.log(response);
console.log("Failed to verify jpegtran is installed!");
Deno.exit(2);
}
}
const originExp = /origin_(\d)\.jpg/;
const rootDir: string = "./" + Date.now();
const rigDir: string = rootDir + "/rig";
//ensureDirSync(rootDir);
//ensureDirSync(rigDir);
for (let index = 1; index <= 6; index++) {
ensureDirSync(`${rigDir}/${index-1}`);
}
let voidQueue: Promise<void>[] = [];
let commandQueue: Promise<IExecResponse>[] = [];
let counter=0;
for await (const dirEntry of Deno.readDir(inDir)) {
for await (const fileEntry of Deno.readDir(inDir + dirEntry.name)) {
if(originExp.test(fileEntry.name)){
let num = parseInt(originExp.exec(fileEntry.name)?.[1] || "1") - 1;
let filename = `${inDir}/${dirEntry.name}/${fileEntry.name}`
const command = jpgtranCommandGenerator(filename, `${rigDir}/${num}/${`${counter}`.padStart(4, "0")}.jpg`);
//console.log(command);
commandQueue.push(exec(
command,
//{ output: OutputMode.None },
));
//voidQueue.push(copy(filename, `${rigDir}/${num}/${dirEntry.name}.jpg`));
}
}
counter++;
}
await Promise.all(commandQueue);
console.log(`${commandQueue.length} items copied...`)
for (let id = 0; id < counter; id++) {
for (let rig = 0; rig <= 5; rig++) {
let fauxDate = `1997:09:02 ${Math.floor((id/60/60))%12}:${Math.floor(id/60)%60}:${id%60}`
const command = exiftoolCommandGenerator(`${rigDir}/${rig}/${`${id}`.padStart(4, "0")}.jpg`, `Pro2_Subcamera_${rig}`, fauxDate)
console.log(command);
/*commandQueue.push(exec(
command,
{ output: OutputMode.Capture },
));*/
// await delay(1000)
}
}
await Promise.all(commandQueue);