@slidevideo/cli 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +42 -0
- package/IMPRESSUM.md +18 -4
- package/LICENSE-TERMS.md +46 -13
- package/README.md +5 -3
- package/addons/slidevideo/global-top.vue +1 -1
- package/addons/slidevideo/playback-entries.ts +1 -1
- package/addons/slidevideo/preview.ts +2 -2
- package/dist/adapters/browser-runtime.d.ts +3 -0
- package/dist/adapters/elevenlabs.d.ts +1 -0
- package/dist/adapters/elevenlabs.js +8 -4
- package/dist/adapters/powerpoint.d.ts +1 -1
- package/dist/adapters/powerpoint.js +10 -11
- package/dist/adapters/slidev-inspection.js +2 -4
- package/dist/adapters/slidev-server.js +136 -15
- package/dist/adapters/slidev.d.ts +9 -0
- package/dist/adapters/slidev.js +347 -62
- package/dist/annotations.d.ts +1 -1
- package/dist/annotations.js +3 -3
- package/dist/assembly.d.ts +44 -38
- package/dist/assembly.js +60 -21
- package/dist/calibration.js +5 -4
- package/dist/cli.js +88 -31
- package/dist/compositor.d.ts +30 -3
- package/dist/compositor.js +196 -30
- package/dist/contracts.d.ts +6 -6
- package/dist/executables.d.ts +2 -0
- package/dist/executables.js +27 -8
- package/dist/media.d.ts +7 -1
- package/dist/media.js +23 -4
- package/dist/pipeline.d.ts +1 -1
- package/dist/pipeline.js +107 -42
- package/dist/preview/server.js +4 -4
- package/dist/run.d.ts +1 -1
- package/dist/run.js +8 -3
- package/dist/setup-install.d.ts +1 -0
- package/dist/setup-install.js +8 -1
- package/dist/setup.d.ts +26 -8
- package/dist/setup.js +168 -76
- package/dist/speech.js +10 -6
- package/dist/storyboard.js +3 -6
- package/dist/timing.js +2 -2
- package/dist/update-check-worker.d.ts +1 -0
- package/dist/update-check-worker.js +28 -0
- package/dist/update-check.d.ts +4 -0
- package/dist/update-check.js +79 -0
- package/package.json +7 -3
- package/schemas/schedule.v1.json +389 -1
- package/schemas/storyboard.v1.json +342 -1
- package/skills/slidevideo/SKILL.md +2 -2
- package/skills/slidevideo/references/production.md +7 -6
- package/skills/slidevideo/references/storyboard.md +9 -8
- package/schemas/schedule.v2.json +0 -496
- package/schemas/storyboard.v2.json +0 -802
package/dist/compositor.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { writeFile } from 'node:fs/promises';
|
|
3
|
-
import { pipeline } from 'node:stream/promises';
|
|
4
3
|
import { createCanvas, ImageData } from '@napi-rs/canvas';
|
|
5
|
-
import {
|
|
4
|
+
import { executionSignal, hasStageDeadline } from './media.js';
|
|
6
5
|
import { executable } from './executables.js';
|
|
7
6
|
import { ProductionError, requireCondition } from './errors.js';
|
|
8
7
|
import { loadOverlayImage } from './overlay-assets.js';
|
|
@@ -90,59 +89,226 @@ function completion(child, operation) {
|
|
|
90
89
|
void done.catch(() => { });
|
|
91
90
|
return done;
|
|
92
91
|
}
|
|
93
|
-
export
|
|
94
|
-
|
|
92
|
+
export function splitFrameLayers(layers) {
|
|
93
|
+
let lastDynamic = -1;
|
|
94
|
+
for (let index = 0; index < layers.length; index++) {
|
|
95
|
+
if (layers[index].opacityAt !== undefined)
|
|
96
|
+
lastDynamic = index;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
canvasLayers: layers.slice(0, lastDynamic + 1),
|
|
100
|
+
staticTopLayers: layers.slice(lastDynamic + 1),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
export function planCompositor(frameCount, fps, audioOrigin, applications, canvasLayers) {
|
|
104
|
+
if (frameCount <= 0 || (!applications.length && !canvasLayers.length))
|
|
105
|
+
return { kind: 'none' };
|
|
106
|
+
const raw = [];
|
|
107
|
+
let activeFrames = 0;
|
|
108
|
+
let openStart = -1;
|
|
109
|
+
for (let frame = 0; frame < frameCount; frame++) {
|
|
110
|
+
const time = Math.max(0, frame * 1000 / fps - audioOrigin);
|
|
111
|
+
const active = applications.some(item => frame >= item.first_frame && frame < item.end_frame)
|
|
112
|
+
|| canvasLayers.some(layer => (layer.opacityAt ? layer.opacityAt(time) : layer.opacity) > 0);
|
|
113
|
+
if (active) {
|
|
114
|
+
activeFrames++;
|
|
115
|
+
if (openStart < 0)
|
|
116
|
+
openStart = frame;
|
|
117
|
+
}
|
|
118
|
+
else if (openStart >= 0) {
|
|
119
|
+
raw.push({ start: openStart, end: frame });
|
|
120
|
+
openStart = -1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
if (openStart >= 0)
|
|
124
|
+
raw.push({ start: openStart, end: frameCount });
|
|
125
|
+
if (activeFrames === 0)
|
|
126
|
+
return { kind: 'none' };
|
|
127
|
+
const merged = [];
|
|
128
|
+
for (const interval of raw) {
|
|
129
|
+
const previous = merged[merged.length - 1];
|
|
130
|
+
if (previous && interval.start - previous.end <= 4)
|
|
131
|
+
previous.end = interval.end;
|
|
132
|
+
else
|
|
133
|
+
merged.push({ ...interval });
|
|
134
|
+
}
|
|
135
|
+
const selectedFrames = merged.reduce((sum, item) => sum + (item.end - item.start), 0);
|
|
136
|
+
if (selectedFrames < frameCount * 0.65 && merged.length <= 64) {
|
|
137
|
+
const betweenExpr = merged.map(({ start, end }) => start === end - 1 ? `eq(n,${start})` : `between(n,${start},${end - 1})`).join('+');
|
|
138
|
+
const terms = [`N+${merged[0].start}`];
|
|
139
|
+
let cumulative = merged[0].end - merged[0].start;
|
|
140
|
+
for (let index = 1; index < merged.length; index++) {
|
|
141
|
+
const gap = merged[index].start - merged[index - 1].end;
|
|
142
|
+
terms.push(`${gap}*gte(N,${cumulative})`);
|
|
143
|
+
cumulative += merged[index].end - merged[index].start;
|
|
144
|
+
}
|
|
145
|
+
const ptsExpr = `(${terms.join('+')})/(${fps}*TB)`;
|
|
146
|
+
return { kind: 'sparse', intervals: merged, selectedFrames, activeFrames, betweenExpr, ptsExpr, canvasLayers };
|
|
147
|
+
}
|
|
148
|
+
return { kind: 'full', activeFrames, canvasLayers };
|
|
149
|
+
}
|
|
150
|
+
export async function compositeFrames(source, baseFilter, encoderArgs, output, applications, plan, frameCount, audioOrigin) {
|
|
151
|
+
const signal = executionSignal();
|
|
95
152
|
signal?.throwIfAborted();
|
|
96
153
|
const canvas = createCanvas(output.width, output.height);
|
|
97
154
|
const context = canvas.getContext('2d', { alpha: false });
|
|
98
155
|
const bytes = output.width * output.height * 4;
|
|
99
|
-
const
|
|
100
|
-
const
|
|
156
|
+
const slots = [Buffer.allocUnsafe(bytes), Buffer.allocUnsafe(bytes)];
|
|
157
|
+
const slotImages = slots.map(buffer => new ImageData(new Uint8ClampedArray(buffer.buffer, buffer.byteOffset, buffer.byteLength), output.width, output.height));
|
|
101
158
|
const ffmpeg = executable('ffmpeg');
|
|
102
|
-
const
|
|
159
|
+
const expectedDecodedFrames = plan.kind === 'sparse' ? plan.selectedFrames : frameCount;
|
|
160
|
+
const decoderFilter = plan.kind === 'sparse' ? `${baseFilter},select='${plan.betweenExpr}'` : baseFilter;
|
|
161
|
+
const decoder = spawn(ffmpeg, ['-v', 'error', '-xerror', '-i', source, '-vf', decoderFilter, '-frames:v', String(expectedDecodedFrames), '-pix_fmt', 'rgba', '-fps_mode', 'passthrough', '-f', 'rawvideo', '-'], { stdio: ['ignore', 'pipe', 'pipe'], signal, killSignal: 'SIGKILL', windowsHide: true });
|
|
103
162
|
const decoded = completion(decoder, 'Composite frame decoding');
|
|
104
163
|
const encoder = spawn(ffmpeg, encoderArgs, { stdio: ['pipe', 'ignore', 'pipe'], signal, killSignal: 'SIGKILL', windowsHide: true });
|
|
164
|
+
encoder.stdin.on('error', () => { });
|
|
105
165
|
const encoded = completion(encoder, 'Composite frame encoding');
|
|
106
|
-
|
|
107
|
-
|
|
166
|
+
const writeToEncoder = (buffer) => new Promise((resolve, reject) => {
|
|
167
|
+
const onError = (error) => { cleanup(); reject(error); };
|
|
168
|
+
const onDrain = () => { cleanup(); resolve(); };
|
|
169
|
+
const onClose = () => { cleanup(); reject(new ProductionError('ANNOTATION_COMPOSITOR', 'Composite frame encoder closed its input early', 7)); };
|
|
170
|
+
const onAbort = () => { cleanup(); reject(signal?.reason ?? new ProductionError('INTERRUPTED', 'Compositor aborted', 7)); };
|
|
171
|
+
const cleanup = () => {
|
|
172
|
+
encoder.stdin.off('error', onError);
|
|
173
|
+
encoder.stdin.off('drain', onDrain);
|
|
174
|
+
encoder.stdin.off('close', onClose);
|
|
175
|
+
signal?.removeEventListener('abort', onAbort);
|
|
176
|
+
};
|
|
177
|
+
if (encoder.stdin.destroyed || !encoder.stdin.writable) {
|
|
178
|
+
reject(new ProductionError('ANNOTATION_COMPOSITOR', 'Composite frame encoder input is not writable', 7));
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (encoder.stdin.write(buffer)) {
|
|
182
|
+
resolve();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
encoder.stdin.once('error', onError);
|
|
186
|
+
encoder.stdin.once('drain', onDrain);
|
|
187
|
+
encoder.stdin.once('close', onClose);
|
|
188
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
189
|
+
});
|
|
190
|
+
let decodedCount = 0;
|
|
191
|
+
let paintedFrames = 0;
|
|
192
|
+
let intervalIndex = 0;
|
|
193
|
+
let frameInInterval = plan.kind === 'sparse' ? plan.intervals[0].start : 0;
|
|
194
|
+
const nextFrameIndex = () => {
|
|
195
|
+
if (plan.kind === 'full')
|
|
196
|
+
return decodedCount++;
|
|
197
|
+
const current = frameInInterval++;
|
|
198
|
+
if (frameInInterval >= plan.intervals[intervalIndex].end && intervalIndex + 1 < plan.intervals.length) {
|
|
199
|
+
intervalIndex++;
|
|
200
|
+
frameInInterval = plan.intervals[intervalIndex].start;
|
|
201
|
+
}
|
|
202
|
+
decodedCount++;
|
|
203
|
+
return current;
|
|
204
|
+
};
|
|
205
|
+
const pump = async () => {
|
|
108
206
|
let filled = 0;
|
|
109
|
-
|
|
207
|
+
let slot = 0;
|
|
208
|
+
for await (const chunk of decoder.stdout) {
|
|
110
209
|
let position = 0;
|
|
111
210
|
while (position < chunk.length) {
|
|
112
211
|
signal?.throwIfAborted();
|
|
212
|
+
const target = slots[slot];
|
|
113
213
|
const count = Math.min(bytes - filled, chunk.length - position);
|
|
114
|
-
chunk.copy(
|
|
214
|
+
chunk.copy(target, filled, position, position + count);
|
|
115
215
|
position += count;
|
|
116
216
|
filled += count;
|
|
117
217
|
if (filled !== bytes)
|
|
118
218
|
continue;
|
|
119
|
-
|
|
219
|
+
const frameIndex = nextFrameIndex();
|
|
220
|
+
const time = Math.max(0, frameIndex * 1000 / output.fps - audioOrigin);
|
|
221
|
+
let minLeft = Infinity;
|
|
222
|
+
let minTop = Infinity;
|
|
223
|
+
let maxRight = -Infinity;
|
|
224
|
+
let maxBottom = -Infinity;
|
|
225
|
+
const expand = (rect) => {
|
|
226
|
+
if (rect.width <= 0 || rect.height <= 0)
|
|
227
|
+
return;
|
|
228
|
+
if (rect.x < minLeft)
|
|
229
|
+
minLeft = rect.x;
|
|
230
|
+
if (rect.y < minTop)
|
|
231
|
+
minTop = rect.y;
|
|
232
|
+
if (rect.x + rect.width > maxRight)
|
|
233
|
+
maxRight = rect.x + rect.width;
|
|
234
|
+
if (rect.y + rect.height > maxBottom)
|
|
235
|
+
maxBottom = rect.y + rect.height;
|
|
236
|
+
};
|
|
120
237
|
for (const annotation of applications) {
|
|
121
|
-
if (
|
|
238
|
+
if (frameIndex < annotation.first_frame || frameIndex >= annotation.end_frame)
|
|
122
239
|
continue;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
240
|
+
expand(annotation.rectangle);
|
|
241
|
+
if (annotation.bottom_border)
|
|
242
|
+
expand(annotation.bottom_border.rectangle);
|
|
243
|
+
}
|
|
244
|
+
for (const layer of plan.canvasLayers) {
|
|
245
|
+
const opacity = layer.opacityAt ? layer.opacityAt(time) : layer.opacity;
|
|
246
|
+
if (opacity > 0)
|
|
247
|
+
expand(layer.rectangle);
|
|
248
|
+
}
|
|
249
|
+
if (minLeft < maxRight && minTop < maxBottom) {
|
|
250
|
+
const dx = Math.max(0, Math.floor(minLeft) - 1);
|
|
251
|
+
const dy = Math.max(0, Math.floor(minTop) - 1);
|
|
252
|
+
const maxX = Math.min(output.width, Math.ceil(maxRight) + 1);
|
|
253
|
+
const maxY = Math.min(output.height, Math.ceil(maxBottom) + 1);
|
|
254
|
+
const dw = maxX - dx;
|
|
255
|
+
const dh = maxY - dy;
|
|
256
|
+
if (dw > 0 && dh > 0) {
|
|
257
|
+
context.putImageData(slotImages[slot], 0, 0, dx, dy, dw, dh);
|
|
258
|
+
for (const annotation of applications) {
|
|
259
|
+
if (frameIndex < annotation.first_frame || frameIndex >= annotation.end_frame)
|
|
260
|
+
continue;
|
|
261
|
+
for (const paint of [annotation, ...(annotation.bottom_border ? [annotation.bottom_border] : [])]) {
|
|
262
|
+
const rect = paint.rectangle;
|
|
263
|
+
if (rect.width <= 0 || rect.height <= 0)
|
|
264
|
+
continue;
|
|
265
|
+
context.save();
|
|
266
|
+
context.fillStyle = paint.color;
|
|
267
|
+
context.globalAlpha = paint.opacity;
|
|
268
|
+
context.globalCompositeOperation = paint.blend;
|
|
269
|
+
context.fillRect(rect.x, rect.y, rect.width, rect.height);
|
|
270
|
+
context.restore();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
paintFrameLayers(context, plan.canvasLayers, time);
|
|
274
|
+
const patch = context.getImageData(dx, dy, dw, dh).data;
|
|
275
|
+
const patchBuffer = Buffer.from(patch.buffer, patch.byteOffset, patch.byteLength);
|
|
276
|
+
if (dx === 0 && dw === output.width) {
|
|
277
|
+
patchBuffer.copy(target, dy * output.width * 4, 0, dh * output.width * 4);
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
for (let row = 0; row < dh; row++) {
|
|
281
|
+
patchBuffer.copy(target, ((dy + row) * output.width + dx) * 4, row * dw * 4, (row + 1) * dw * 4);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
paintedFrames++;
|
|
131
285
|
}
|
|
132
286
|
}
|
|
133
|
-
|
|
134
|
-
const pixels = context.getImageData(0, 0, output.width, output.height).data;
|
|
135
|
-
yield Buffer.from(pixels.buffer, pixels.byteOffset, pixels.byteLength);
|
|
136
|
-
frames++;
|
|
287
|
+
await writeToEncoder(target);
|
|
137
288
|
filled = 0;
|
|
289
|
+
slot ^= 1;
|
|
138
290
|
}
|
|
139
291
|
}
|
|
140
|
-
requireCondition(filled === 0 &&
|
|
141
|
-
|
|
142
|
-
|
|
292
|
+
requireCondition(filled === 0 && decodedCount === expectedDecodedFrames, 'ANNOTATION_FRAMES', `Compositor received ${decodedCount} complete frames, expected ${expectedDecodedFrames}`, 7);
|
|
293
|
+
if (!encoder.stdin.destroyed && encoder.stdin.writable) {
|
|
294
|
+
await new Promise(resolve => {
|
|
295
|
+
const done = () => {
|
|
296
|
+
encoder.stdin.off('finish', done);
|
|
297
|
+
encoder.stdin.off('close', done);
|
|
298
|
+
encoder.stdin.off('error', done);
|
|
299
|
+
resolve();
|
|
300
|
+
};
|
|
301
|
+
encoder.stdin.once('finish', done);
|
|
302
|
+
encoder.stdin.once('close', done);
|
|
303
|
+
encoder.stdin.once('error', done);
|
|
304
|
+
encoder.stdin.end();
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
const timer = hasStageDeadline() ? undefined : setTimeout(() => { decoder.kill('SIGKILL'); encoder.kill('SIGKILL'); }, 120000);
|
|
143
309
|
try {
|
|
144
|
-
await Promise.all([
|
|
145
|
-
return { renderer: 'canvas-skia', version: '1.1.1', frames };
|
|
310
|
+
await Promise.all([pump(), decoded, encoded]);
|
|
311
|
+
return { renderer: 'canvas-skia', version: '1.1.1', frames: frameCount, composited_frames: paintedFrames, mode: plan.kind };
|
|
146
312
|
}
|
|
147
313
|
finally {
|
|
148
314
|
clearTimeout(timer);
|
package/dist/contracts.d.ts
CHANGED
|
@@ -146,7 +146,7 @@ export type ResolvedOverlay = Pick<ImageOverlay, 'id' | 'src' | 'box' | 'opacity
|
|
|
146
146
|
}[];
|
|
147
147
|
};
|
|
148
148
|
export type Storyboard = {
|
|
149
|
-
version: 1
|
|
149
|
+
version: 1;
|
|
150
150
|
deck: string;
|
|
151
151
|
voice?: Voice;
|
|
152
152
|
output: {
|
|
@@ -166,7 +166,7 @@ export type Storyboard = {
|
|
|
166
166
|
actions: Action[];
|
|
167
167
|
}[];
|
|
168
168
|
cues: Cue[];
|
|
169
|
-
annotations
|
|
169
|
+
annotations: Annotation[];
|
|
170
170
|
overlays?: ImageOverlay[];
|
|
171
171
|
};
|
|
172
172
|
export type Alignment = {
|
|
@@ -222,7 +222,7 @@ export type ScheduledAction = {
|
|
|
222
222
|
};
|
|
223
223
|
};
|
|
224
224
|
export type Schedule = {
|
|
225
|
-
version: 1
|
|
225
|
+
version: 1;
|
|
226
226
|
duration_ms: number;
|
|
227
227
|
actions: ScheduledAction[];
|
|
228
228
|
media: {
|
|
@@ -231,7 +231,7 @@ export type Schedule = {
|
|
|
231
231
|
duration_ms: number;
|
|
232
232
|
has_audio: boolean;
|
|
233
233
|
}[];
|
|
234
|
-
annotations
|
|
234
|
+
annotations: ResolvedAnnotation[];
|
|
235
235
|
overlays?: ResolvedOverlay[];
|
|
236
236
|
};
|
|
237
237
|
export type ObservedEvent = {
|
|
@@ -329,13 +329,13 @@ export interface PresentationAdapter {
|
|
|
329
329
|
version: string;
|
|
330
330
|
inspect(deck: string): Promise<PresentationInspection>;
|
|
331
331
|
inspectTargets?(storyboard: Storyboard): Promise<PresentationInspection['annotation_targets']>;
|
|
332
|
-
validate(storyboard: Storyboard, inspection: PresentationInspection, schedule?: Schedule): void
|
|
332
|
+
validate(storyboard: Storyboard, inspection: PresentationInspection, schedule?: Schedule): void | Promise<void>;
|
|
333
333
|
startPreview?(storyboard: Storyboard, schedule: Schedule, directory: string, parentOrigin: string): Promise<import('./preview/contracts.js').PreviewSession>;
|
|
334
334
|
prepare(storyboard: Storyboard, schedule: Schedule, directory: string, options?: ProductionOptions): Promise<void>;
|
|
335
335
|
execute(progress?: ProgressReporter): Promise<VisualArtifact>;
|
|
336
336
|
cleanup(): Promise<void>;
|
|
337
337
|
}
|
|
338
|
-
export type Stage = '
|
|
338
|
+
export type Stage = 'tts' | 'resolve' | 'record' | 'assemble';
|
|
339
339
|
export type RunManifest = {
|
|
340
340
|
version: 1;
|
|
341
341
|
run_id: string;
|
package/dist/executables.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ type Browser = {
|
|
|
11
11
|
};
|
|
12
12
|
export declare function withExecutables<T>(overrides: ToolPaths, run: () => T): T;
|
|
13
13
|
export declare function configuredLicense(): boolean;
|
|
14
|
+
export declare function configuredElevenLabsKey(): string | undefined;
|
|
15
|
+
export declare function saveElevenLabsKey(key: string): Promise<void>;
|
|
14
16
|
export declare function saveExecutablePaths(paths: ToolPaths): Promise<void>;
|
|
15
17
|
export declare function saveLicenseKey(key: string | null): Promise<void>;
|
|
16
18
|
export declare function isExecutable(path: string): boolean;
|
package/dist/executables.js
CHANGED
|
@@ -9,6 +9,8 @@ import { edgePython, managedBrowserDirectory, userConfigFile } from './installat
|
|
|
9
9
|
import { licenseStatus, revocationMessage } from './license-status.js';
|
|
10
10
|
export const toolNames = ['browser', 'python', 'ffmpeg', 'ffprobe'];
|
|
11
11
|
const windows = process.platform === 'win32';
|
|
12
|
+
const macos = process.platform === 'darwin';
|
|
13
|
+
const macosExtraDirectories = macos ? ['/opt/homebrew/bin', '/usr/local/bin'] : [];
|
|
12
14
|
const environmentPaths = { browser: 'SLIDEVIDEO_CHROMIUM', python: 'SLIDEVIDEO_PYTHON' };
|
|
13
15
|
const executableScope = new AsyncLocalStorage();
|
|
14
16
|
function readConfig() {
|
|
@@ -19,6 +21,9 @@ function readConfig() {
|
|
|
19
21
|
(configuration.licensed !== undefined && typeof configuration.licensed !== 'boolean')) {
|
|
20
22
|
throw new Error('Expected version 1 and an optional boolean licensed field');
|
|
21
23
|
}
|
|
24
|
+
if (configuration.elevenlabs_api_key !== undefined && typeof configuration.elevenlabs_api_key !== 'string') {
|
|
25
|
+
throw new Error('Expected a string elevenlabs_api_key');
|
|
26
|
+
}
|
|
22
27
|
const paths = configuration.paths;
|
|
23
28
|
if (paths !== undefined && (!paths || typeof paths !== 'object' || Array.isArray(paths) ||
|
|
24
29
|
Object.entries(paths).some(([tool, path]) => !toolNames.some(name => name === tool) || typeof path !== 'string' || !isAbsolute(path)))) {
|
|
@@ -41,6 +46,12 @@ export function configuredLicense() {
|
|
|
41
46
|
console.error(revocationMessage);
|
|
42
47
|
return status === 'active';
|
|
43
48
|
}
|
|
49
|
+
export function configuredElevenLabsKey() {
|
|
50
|
+
return (executableScope.getStore()?.configuration ?? readConfig()).elevenlabs_api_key;
|
|
51
|
+
}
|
|
52
|
+
export function saveElevenLabsKey(key) {
|
|
53
|
+
return updateConfig(configuration => { configuration.elevenlabs_api_key = key; });
|
|
54
|
+
}
|
|
44
55
|
export function saveExecutablePaths(paths) {
|
|
45
56
|
return updateConfig(configuration => { configuration.paths = { ...configuration.paths, ...paths }; });
|
|
46
57
|
}
|
|
@@ -100,18 +111,24 @@ export function browserCandidates() {
|
|
|
100
111
|
const windowsRoots = [process.env.LOCALAPPDATA, process.env.ProgramFiles, process.env['ProgramFiles(x86)']].filter((path) => !!path);
|
|
101
112
|
const locations = (...parts) => windowsRoots.map(root => join(root, ...parts));
|
|
102
113
|
record('Chromium', [
|
|
103
|
-
...(windows ? locations('Chromium', 'Application', 'chrome.exe')
|
|
114
|
+
...(windows ? locations('Chromium', 'Application', 'chrome.exe')
|
|
115
|
+
: macos ? ['/Applications/Chromium.app/Contents/MacOS/Chromium']
|
|
116
|
+
: ['/usr/lib/chromium/chromium']),
|
|
104
117
|
findOnPath('chromium'), findOnPath('chromium-browser'),
|
|
105
|
-
...(windows ? [] : ['/snap/bin/chromium']),
|
|
118
|
+
...(windows || macos ? [] : ['/snap/bin/chromium']),
|
|
106
119
|
chromium.executablePath(),
|
|
107
120
|
]);
|
|
108
121
|
record('Google Chrome', [
|
|
109
122
|
findOnPath('google-chrome'), findOnPath('google-chrome-stable'),
|
|
110
|
-
...(windows ? [findOnPath('chrome'), ...locations('Google', 'Chrome', 'Application', 'chrome.exe')]
|
|
123
|
+
...(windows ? [findOnPath('chrome'), ...locations('Google', 'Chrome', 'Application', 'chrome.exe')]
|
|
124
|
+
: macos ? ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome']
|
|
125
|
+
: ['/opt/google/chrome/chrome']),
|
|
111
126
|
]);
|
|
112
127
|
record('Microsoft Edge', [
|
|
113
128
|
findOnPath('microsoft-edge'), findOnPath('microsoft-edge-stable'),
|
|
114
|
-
...(windows ? [findOnPath('msedge'), ...locations('Microsoft', 'Edge', 'Application', 'msedge.exe')]
|
|
129
|
+
...(windows ? [findOnPath('msedge'), ...locations('Microsoft', 'Edge', 'Application', 'msedge.exe')]
|
|
130
|
+
: macos ? ['/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge']
|
|
131
|
+
: ['/opt/microsoft/msedge/msedge']),
|
|
115
132
|
]);
|
|
116
133
|
return [...found.values()];
|
|
117
134
|
}
|
|
@@ -122,7 +139,7 @@ export function browserName(path) {
|
|
|
122
139
|
const name = basename(path).toLowerCase();
|
|
123
140
|
return browserCandidates().find(browser => browser.path === path)?.name
|
|
124
141
|
?? (name.includes('edge') ? 'Microsoft Edge' : name.includes('chromium') ? 'Chromium'
|
|
125
|
-
: /(
|
|
142
|
+
: /(?:^|[-\s])chrome(?:-stable)?(?:\.exe)?$/.test(name) ? 'Google Chrome' : 'Custom browser');
|
|
126
143
|
}
|
|
127
144
|
export function toolCandidate(tool) {
|
|
128
145
|
const context = executableScope.getStore();
|
|
@@ -148,11 +165,13 @@ export function discoverExecutable(tool) {
|
|
|
148
165
|
path = browserCandidates().find(browser => browser.name === 'Chromium')?.path;
|
|
149
166
|
else if (tool === 'python') {
|
|
150
167
|
const managed = edgePython();
|
|
151
|
-
path = isExecutable(managed) ? managed : windows ? findOnPath('py') ?? findOnPath('python') : findOnPath('python3') ?? findOnPath('python');
|
|
168
|
+
path = isExecutable(managed) ? managed : windows ? findOnPath('py') ?? findOnPath('python') : findOnPath('python3', macosExtraDirectories) ?? findOnPath('python', macosExtraDirectories);
|
|
152
169
|
}
|
|
153
170
|
else {
|
|
154
|
-
const
|
|
155
|
-
|
|
171
|
+
const extraDirectories = windows && process.env.LOCALAPPDATA
|
|
172
|
+
? [join(process.env.LOCALAPPDATA, 'Microsoft', 'WinGet', 'Links')]
|
|
173
|
+
: macosExtraDirectories;
|
|
174
|
+
path = findOnPath(tool, extraDirectories);
|
|
156
175
|
}
|
|
157
176
|
return path;
|
|
158
177
|
}
|
package/dist/media.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import type { MediaProperties } from './contracts.js';
|
|
3
|
-
export
|
|
3
|
+
export type ExecutionContext = {
|
|
4
|
+
signal: AbortSignal;
|
|
5
|
+
bounded: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare const executionScope: AsyncLocalStorage<ExecutionContext>;
|
|
8
|
+
export declare function executionSignal(): AbortSignal | undefined;
|
|
9
|
+
export declare function hasStageDeadline(): boolean;
|
|
4
10
|
export declare function execute(command: string, args: string[], timeout?: number, env?: NodeJS.ProcessEnv): Promise<Buffer>;
|
|
5
11
|
export declare const digest: (value: string | Buffer) => string;
|
|
6
12
|
export declare function hashFile(path: string): Promise<string>;
|
package/dist/media.js
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
2
|
import { spawn } from 'node:child_process';
|
|
3
3
|
import { createHash } from 'node:crypto';
|
|
4
|
+
import { createReadStream } from 'node:fs';
|
|
4
5
|
import { readFile, mkdir, writeFile, rename } from 'node:fs/promises';
|
|
5
6
|
import { dirname } from 'node:path';
|
|
6
7
|
import { ProductionError } from './errors.js';
|
|
7
8
|
import { executable } from './executables.js';
|
|
8
9
|
export const executionScope = new AsyncLocalStorage();
|
|
9
|
-
export
|
|
10
|
+
export function executionSignal() { return executionScope.getStore()?.signal; }
|
|
11
|
+
export function hasStageDeadline() { return executionScope.getStore()?.bounded === true; }
|
|
12
|
+
export async function execute(command, args, timeout, env = process.env) {
|
|
10
13
|
if (command === 'ffmpeg' || command === 'ffprobe')
|
|
11
14
|
command = executable(command);
|
|
12
15
|
return new Promise((resolve, reject) => {
|
|
13
|
-
const
|
|
16
|
+
const context = executionScope.getStore();
|
|
17
|
+
const signal = context?.signal;
|
|
14
18
|
signal?.throwIfAborted();
|
|
15
19
|
const child = spawn(command, args, { stdio: ['ignore', 'pipe', 'pipe'], env, signal, killSignal: 'SIGKILL', windowsHide: true });
|
|
16
20
|
const out = [];
|
|
17
21
|
const err = [];
|
|
18
|
-
const
|
|
22
|
+
const limit = timeout ?? (context?.bounded ? undefined : 120000);
|
|
23
|
+
const timer = limit !== undefined ? setTimeout(() => { child.kill('SIGKILL'); }, limit) : undefined;
|
|
19
24
|
child.stdout.on('data', data => out.push(data));
|
|
20
25
|
child.stderr.on('data', data => err.push(data));
|
|
21
26
|
child.on('error', error => { clearTimeout(timer); reject(new ProductionError('DEPENDENCY', `${command}: ${error.message}`, 3)); });
|
|
@@ -29,7 +34,21 @@ export async function execute(command, args, timeout = 120000, env = process.env
|
|
|
29
34
|
});
|
|
30
35
|
}
|
|
31
36
|
export const digest = (value) => createHash('sha256').update(value).digest('hex');
|
|
32
|
-
export async function hashFile(path) {
|
|
37
|
+
export async function hashFile(path) {
|
|
38
|
+
executionSignal()?.throwIfAborted();
|
|
39
|
+
const hash = createHash('sha256');
|
|
40
|
+
const stream = createReadStream(path);
|
|
41
|
+
try {
|
|
42
|
+
for await (const chunk of stream) {
|
|
43
|
+
executionSignal()?.throwIfAborted();
|
|
44
|
+
hash.update(chunk);
|
|
45
|
+
}
|
|
46
|
+
return hash.digest('hex');
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
stream.destroy();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
33
52
|
export async function json(path) { return JSON.parse(await readFile(path, 'utf8')); }
|
|
34
53
|
export async function saveJson(path, value) {
|
|
35
54
|
await mkdir(dirname(path), { recursive: true });
|
package/dist/pipeline.d.ts
CHANGED