@celljs/ta-moves 4.34.0 → 4.35.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/host/index.mjs +89 -30
- package/package.json +4 -3
package/host/index.mjs
CHANGED
|
@@ -1,11 +1,73 @@
|
|
|
1
1
|
// web-src/host.ts
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { randomBytes } from "node:crypto";
|
|
4
|
-
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
5
|
-
import { delimiter, join } from "node:path";
|
|
4
|
+
import { appendFileSync, existsSync, mkdirSync as mkdirSync2, readFileSync, renameSync as renameSync2, rmSync as rmSync2, statSync, writeFileSync as writeFileSync2 } from "node:fs";
|
|
5
|
+
import { delimiter, join as join2 } from "node:path";
|
|
6
6
|
|
|
7
|
+
// ../../packages/core/esm/node/fs/file-util.js
|
|
8
|
+
import { chmodSync, mkdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { chmod, mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
10
|
+
import { basename, dirname, join } from "node:path";
|
|
11
|
+
var written = 0;
|
|
12
|
+
var FileUtil;
|
|
13
|
+
(function(FileUtil2) {
|
|
14
|
+
function temporary(file, hidden = false) {
|
|
15
|
+
const n = `${process.pid}.${++written}`;
|
|
16
|
+
return hidden ? join(dirname(file), `.${basename(file)}.${n}.tmp`) : `${file}.${n}.tmp`;
|
|
17
|
+
}
|
|
18
|
+
FileUtil2.temporary = temporary;
|
|
19
|
+
function ownTemporary(name) {
|
|
20
|
+
return new RegExp(`\\.${process.pid}\\.\\d+\\.tmp$`).test(name);
|
|
21
|
+
}
|
|
22
|
+
FileUtil2.ownTemporary = ownTemporary;
|
|
23
|
+
function write(file, data, options = {}) {
|
|
24
|
+
if (options.mkdir !== false) {
|
|
25
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
26
|
+
}
|
|
27
|
+
const draft = temporary(file, options.hidden);
|
|
28
|
+
try {
|
|
29
|
+
writeFileSync(draft, data, options.mode === undefined ? undefined : { mode: options.mode });
|
|
30
|
+
if (options.mode !== undefined) {
|
|
31
|
+
chmodSync(draft, options.mode);
|
|
32
|
+
}
|
|
33
|
+
renameSync(draft, file);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
rmSync(draft, { force: true });
|
|
36
|
+
throw error;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
FileUtil2.write = write;
|
|
40
|
+
async function writeAsync(file, data, options = {}) {
|
|
41
|
+
if (options.mkdir !== false) {
|
|
42
|
+
await mkdir(dirname(file), { recursive: true });
|
|
43
|
+
}
|
|
44
|
+
const draft = temporary(file, options.hidden);
|
|
45
|
+
try {
|
|
46
|
+
await writeFile(draft, data, options.mode === undefined ? undefined : { mode: options.mode });
|
|
47
|
+
if (options.mode !== undefined) {
|
|
48
|
+
await chmod(draft, options.mode);
|
|
49
|
+
}
|
|
50
|
+
await rename(draft, file);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
await rm(draft, { force: true });
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
FileUtil2.writeAsync = writeAsync;
|
|
57
|
+
function writeJson(file, value, options = {}) {
|
|
58
|
+
write(file, json(value, options.pretty), options);
|
|
59
|
+
}
|
|
60
|
+
FileUtil2.writeJson = writeJson;
|
|
61
|
+
function writeJsonAsync(file, value, options = {}) {
|
|
62
|
+
return writeAsync(file, json(value, options.pretty), options);
|
|
63
|
+
}
|
|
64
|
+
FileUtil2.writeJsonAsync = writeJsonAsync;
|
|
65
|
+
function json(value, pretty = false) {
|
|
66
|
+
return pretty ? `${JSON.stringify(value, undefined, 2)}
|
|
67
|
+
` : JSON.stringify(value);
|
|
68
|
+
}
|
|
69
|
+
})(FileUtil || (FileUtil = {}));
|
|
7
70
|
// web-src/moves-protocol.ts
|
|
8
|
-
var NAME = "@celljs/ta-moves";
|
|
9
71
|
var WIDTH = 720;
|
|
10
72
|
var HEIGHT = 1178;
|
|
11
73
|
var FPS = 24;
|
|
@@ -145,7 +207,7 @@ class MovesHost {
|
|
|
145
207
|
}
|
|
146
208
|
}
|
|
147
209
|
if (!this.uploads.size) {
|
|
148
|
-
|
|
210
|
+
rmSync2(join2(this.dir, "incoming"), { recursive: true, force: true });
|
|
149
211
|
}
|
|
150
212
|
}
|
|
151
213
|
static UPLOAD_IDLE_MS = 30 * 60 * 1000;
|
|
@@ -172,10 +234,10 @@ class MovesHost {
|
|
|
172
234
|
}
|
|
173
235
|
this.sweep();
|
|
174
236
|
const id = randomBytes(8).toString("hex");
|
|
175
|
-
const incoming =
|
|
176
|
-
|
|
177
|
-
const file =
|
|
178
|
-
|
|
237
|
+
const incoming = join2(this.dir, "incoming");
|
|
238
|
+
mkdirSync2(incoming, { recursive: true });
|
|
239
|
+
const file = join2(incoming, id);
|
|
240
|
+
writeFileSync2(file, "");
|
|
179
241
|
this.uploads.set(id, { draft: { title, kind, words, replace, size: draft.size }, file, received: 0, at: this.now() });
|
|
180
242
|
return { id };
|
|
181
243
|
}
|
|
@@ -204,16 +266,16 @@ class MovesHost {
|
|
|
204
266
|
if (!move) {
|
|
205
267
|
throw new Error(`No move ${name}`);
|
|
206
268
|
}
|
|
207
|
-
return { data: readFileSync(
|
|
269
|
+
return { data: readFileSync(join2(this.dir, move.file)).toString("base64") };
|
|
208
270
|
}
|
|
209
271
|
clips() {
|
|
210
|
-
return this.read().filter((move) => !move.problem).map((move) => ({ clip: `own:${move.name}`, path:
|
|
272
|
+
return this.read().filter((move) => !move.problem).map((move) => ({ clip: `own:${move.name}`, path: join2(this.dir, move.file) }));
|
|
211
273
|
}
|
|
212
274
|
remove(name) {
|
|
213
275
|
const moves = this.read();
|
|
214
276
|
const move = moves.find((one) => one.name === name);
|
|
215
277
|
if (move) {
|
|
216
|
-
|
|
278
|
+
rmSync2(join2(this.dir, move.file), { force: true });
|
|
217
279
|
}
|
|
218
280
|
return this.write(moves.filter((one) => one.name !== name));
|
|
219
281
|
}
|
|
@@ -234,7 +296,7 @@ class MovesHost {
|
|
|
234
296
|
const work = `${input}.mp4`;
|
|
235
297
|
const fit = `scale=${WIDTH}:${HEIGHT}:force_original_aspect_ratio=increase,crop=${WIDTH}:${HEIGHT},fps=${FPS},format=yuv420p,setsar=1`;
|
|
236
298
|
await this.encode(["-i", input, "-an", "-vf", fit], work);
|
|
237
|
-
const seated = this.faces && existsSync(
|
|
299
|
+
const seated = this.faces && existsSync(join2(this.faces, "poster.jpg")) ? join2(this.faces, "poster.jpg") : undefined;
|
|
238
300
|
const seat = seated ? ClipCheck.split(await this.run(this.ffmpeg, ["-v", "error", "-i", seated, "-vf", `${fit},${MovesHost.SAMPLE}`, "-f", "rawvideo", "pipe:1"]))[0] : undefined;
|
|
239
301
|
let samples = await this.samples(work);
|
|
240
302
|
const far = (frame) => seat && frame ? ClipCheck.distance(frame, seat) : 0;
|
|
@@ -246,19 +308,19 @@ class MovesHost {
|
|
|
246
308
|
}
|
|
247
309
|
const name = draft.replace ?? `m${Date.now().toString(36)}`;
|
|
248
310
|
const file = fileOf(name, draft.kind);
|
|
249
|
-
|
|
311
|
+
mkdirSync2(join2(this.dir, file, ".."), { recursive: true });
|
|
250
312
|
const moves = this.read();
|
|
251
313
|
const old = moves.find((one) => one.name === name);
|
|
252
314
|
if (old) {
|
|
253
|
-
|
|
315
|
+
rmSync2(join2(this.dir, old.file), { force: true });
|
|
254
316
|
}
|
|
255
|
-
|
|
317
|
+
renameSync2(work, join2(this.dir, file));
|
|
256
318
|
const move = {
|
|
257
319
|
name,
|
|
258
320
|
title: draft.title,
|
|
259
321
|
kind: draft.kind,
|
|
260
322
|
words: draft.words,
|
|
261
|
-
frames: await this.frames(
|
|
323
|
+
frames: await this.frames(join2(this.dir, file)),
|
|
262
324
|
file,
|
|
263
325
|
seat: was,
|
|
264
326
|
blended,
|
|
@@ -303,7 +365,7 @@ class MovesHost {
|
|
|
303
365
|
const still = ["-loop", "1", "-t", String(BLEND_S), "-i", seated];
|
|
304
366
|
const out = `${work}.blend.mp4`;
|
|
305
367
|
await this.encode(["-i", work, ...still, ...still, "-filter_complex", parts.join(";"), "-map", `[${at}]`], out);
|
|
306
|
-
|
|
368
|
+
renameSync2(out, work);
|
|
307
369
|
}
|
|
308
370
|
async encode(args, out) {
|
|
309
371
|
await this.run(this.ffmpeg, [
|
|
@@ -321,7 +383,7 @@ class MovesHost {
|
|
|
321
383
|
"+faststart",
|
|
322
384
|
out
|
|
323
385
|
]).catch((error) => {
|
|
324
|
-
|
|
386
|
+
rmSync2(out, { force: true });
|
|
325
387
|
throw MoveErrors.error("not-video", String(error.message).split(`
|
|
326
388
|
`)[0]);
|
|
327
389
|
});
|
|
@@ -390,36 +452,33 @@ class MovesHost {
|
|
|
390
452
|
const upload = this.uploads.get(id);
|
|
391
453
|
this.uploads.delete(id);
|
|
392
454
|
if (upload) {
|
|
393
|
-
|
|
394
|
-
|
|
455
|
+
rmSync2(upload.file, { force: true });
|
|
456
|
+
rmSync2(`${upload.file}.mp4`, { force: true });
|
|
395
457
|
}
|
|
396
458
|
}
|
|
397
459
|
read() {
|
|
398
460
|
try {
|
|
399
|
-
const file = JSON.parse(readFileSync(
|
|
461
|
+
const file = JSON.parse(readFileSync(join2(this.dir, "moves.json"), "utf8"));
|
|
400
462
|
return Array.isArray(file.moves) ? file.moves : [];
|
|
401
463
|
} catch {
|
|
402
464
|
return [];
|
|
403
465
|
}
|
|
404
466
|
}
|
|
405
467
|
write(moves) {
|
|
406
|
-
|
|
407
|
-
const file = join(this.dir, "moves.json");
|
|
408
|
-
writeFileSync(`${file}.tmp`, JSON.stringify({ version: 1, moves }, null, 1));
|
|
409
|
-
renameSync(`${file}.tmp`, file);
|
|
468
|
+
FileUtil.write(join2(this.dir, "moves.json"), JSON.stringify({ version: 1, moves }, null, 1));
|
|
410
469
|
return moves;
|
|
411
470
|
}
|
|
412
471
|
static find(name, path = process.env.PATH ?? "") {
|
|
413
472
|
const exe = process.platform === "win32" ? `${name}.exe` : name;
|
|
414
473
|
const dirs = [...path.split(delimiter), "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin"];
|
|
415
|
-
return dirs.map((dir) =>
|
|
474
|
+
return dirs.map((dir) => join2(dir, exe)).find(isFile);
|
|
416
475
|
}
|
|
417
476
|
static faces(root) {
|
|
418
477
|
if (!root) {
|
|
419
478
|
return;
|
|
420
479
|
}
|
|
421
|
-
const built =
|
|
422
|
-
return existsSync(
|
|
480
|
+
const built = join2(root, "..", "..", "..", "public", "faces");
|
|
481
|
+
return existsSync(join2(built, "poster.jpg")) ? built : join2(root, "..", "ta-web", "public", "faces");
|
|
423
482
|
}
|
|
424
483
|
}
|
|
425
484
|
function isFile(file) {
|
|
@@ -430,8 +489,8 @@ function isFile(file) {
|
|
|
430
489
|
}
|
|
431
490
|
}
|
|
432
491
|
async function activate(host) {
|
|
433
|
-
const root =
|
|
434
|
-
const moves = new MovesHost(
|
|
492
|
+
const root = host.root;
|
|
493
|
+
const moves = new MovesHost(join2(host.agentDir, "call-moves"), MovesHost.faces(root));
|
|
435
494
|
moves.sweep();
|
|
436
495
|
return {
|
|
437
496
|
list: () => moves.list(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@celljs/ta-moves",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.35.0",
|
|
4
4
|
"description": "A pi package for Ta: the user's own clips of the person of video calls, checked, made like Ta's own and played with her moves",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package"
|
|
@@ -26,8 +26,9 @@
|
|
|
26
26
|
"watch": "tsc -b -w --preserveWatchOutput"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@celljs/
|
|
30
|
-
"@celljs/ta-
|
|
29
|
+
"@celljs/core": "4.35.0",
|
|
30
|
+
"@celljs/ta-protocol": "4.35.0",
|
|
31
|
+
"@celljs/ta-web": "4.35.0",
|
|
31
32
|
"@types/react": "^19.3.0"
|
|
32
33
|
},
|
|
33
34
|
"publishConfig": {
|