@gentbajko/slopify 4.5.1 → 4.5.2
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/dist/edge/mcp/tools-runs.js +1 -1
- package/dist/extension/slopify-studio-chrome.zip +0 -0
- package/dist/extension/slopify-studio-firefox.zip +0 -0
- package/dist/patch-notes/4.5.2.md +17 -0
- package/dist/patch-notes/index.json +6 -0
- package/dist/slices/article/production-note.js +75 -0
- package/dist/slices/rebuild/recipe-audio.js +6 -0
- package/dist/slices/rebuild/recipe-build.js +6 -2
- package/dist/slices/rebuild/recipe-save.js +16 -3
- package/dist/slices/rebuild/recipe-shorts.js +195 -8
- package/dist/slices/rebuild/runtime-provider.js +11 -4
- package/dist/slices/rebuild/runtime-shorts.js +53 -13
- package/dist/slices/revisions/schema.js +1 -0
- package/dist/slices/shorts/keep.js +37 -17
- package/dist/web/assets/{index-C0n0zeuZ.js → index-C8aMp7m3.js} +2 -2
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
|
@@ -8,7 +8,7 @@ import { assetPathOrUndefined } from "../revisions/mutation-assets.js";
|
|
|
8
8
|
import { readyOutput } from "../revisions/view.js";
|
|
9
9
|
import { clipWords } from "../shorts/captions.js";
|
|
10
10
|
import { effectiveClips, pickedShortsOf } from "../shorts/clips.js";
|
|
11
|
-
import { anchorKept,
|
|
11
|
+
import { anchorKept, locateClip, withNewPicks } from "../shorts/keep.js";
|
|
12
12
|
import { defaultShortsPrompt, musicVolumeOf, shortImageCount, shortsSpeedOf, } from "../shorts/model.js";
|
|
13
13
|
import { checkPicks, keepNumbers, noPicksMessage, pickMessages, pickRetryMessages, } from "../shorts/pick.js";
|
|
14
14
|
import { checkImagePrompts } from "../shorts/prompts.js";
|
|
@@ -18,7 +18,7 @@ import { outputPath, projectDir } from "../storage/layout.js";
|
|
|
18
18
|
import { probeDurationMs } from "../video/ffmpeg.js";
|
|
19
19
|
import { usesVoices } from "../voices/model.js";
|
|
20
20
|
import { sentencesText, transcriptSentences } from "../youtube/transcript.js";
|
|
21
|
-
import { shortsPickKey } from "./recipe-shorts.js";
|
|
21
|
+
import { onBodyClock, shortsPickKey } from "./recipe-shorts.js";
|
|
22
22
|
import { exportMachine, warningsOf } from "./runtime-export.js";
|
|
23
23
|
import { figureShots } from "./runtime-export-edit.js";
|
|
24
24
|
import { exportSnapshot, revisionAudio } from "./runtime-export-inputs.js";
|
|
@@ -68,18 +68,21 @@ async function pick(deps, context, providers, piece, snapshot) {
|
|
|
68
68
|
const llm = config.llm;
|
|
69
69
|
if (llm === undefined || llm.provider.trim() === "" || llm.model.trim() === "")
|
|
70
70
|
throw new Error(`Shorts need an AI model to pick the clips, and none is chosen. Choose a Service and a Model in ${editSettings.writer}, then Try again.`);
|
|
71
|
-
const
|
|
71
|
+
const audio = await revisionAudio(deps, context, view);
|
|
72
|
+
const words = readTimingWords(deps, context, view, shortsTimingPurpose).words;
|
|
73
|
+
// On the body's clock the moments are picked from the body alone, timed from its start, so
|
|
74
|
+
// a new intro or outro leaves them where they are (`recipe-shorts.ts`).
|
|
75
|
+
const body = onBodyClock(input.values) ? bodyWindow(audio) : undefined;
|
|
76
|
+
const sentences = transcriptSentences(body === undefined ? words : bodyWords(words, body));
|
|
72
77
|
if (sentences.length === 0)
|
|
73
78
|
throw new Error("The narration's word timing holds no words, so there is nothing to cut shorts from. Press Make the video again in the project's Video section, then Try again.");
|
|
74
|
-
const
|
|
75
|
-
const durationSeconds = audio.reduce((sum, segment) => sum + segment.seconds, 0);
|
|
79
|
+
const durationSeconds = body?.seconds ?? audio.reduce((sum, segment) => sum + segment.seconds, 0);
|
|
76
80
|
// Kept shorts are found again in this timing; the model is asked only for the rest.
|
|
77
81
|
const keep = view.revision.content.shortsKeep;
|
|
78
82
|
const anchored = keep === undefined
|
|
79
83
|
? undefined
|
|
80
84
|
: anchorKept(keep.slice(0, shorts.count), sentences, durationSeconds);
|
|
81
|
-
|
|
82
|
-
throw new Error(lostMessage(anchored.lost, keep ?? []));
|
|
85
|
+
// A kept short whose own words changed is picked anew in its place; the others stay.
|
|
83
86
|
const keptPicks = anchored?.picks ?? [];
|
|
84
87
|
const wanted = shorts.count - keptPicks.length;
|
|
85
88
|
const taken = keptPicks.map(({ first, last }) => ({ first, last }));
|
|
@@ -243,16 +246,30 @@ async function render(deps, context, piece, snapshot, clip) {
|
|
|
243
246
|
return outputPath(deps.paths, context.work.projectId, row.output.path);
|
|
244
247
|
});
|
|
245
248
|
const allWords = readTimingWords(deps, context, view, shortsTimingPurpose).words;
|
|
246
|
-
|
|
249
|
+
// A clip on the body's clock is found by its sentences in the body as it is now, which
|
|
250
|
+
// starts after whatever intro: other chunks voiced again or words added before it may have
|
|
251
|
+
// moved it since it was picked.
|
|
252
|
+
const input = piece.input;
|
|
253
|
+
let start = clip.start;
|
|
254
|
+
let end = clip.end;
|
|
255
|
+
if (input.kind === "local" && onBodyClock(input.values)) {
|
|
256
|
+
const body = bodyWindow(await revisionAudio(deps, context, view));
|
|
257
|
+
const found = locateClip(transcriptSentences(bodyWords(allWords, body)), clip, body.seconds);
|
|
258
|
+
if (found === undefined)
|
|
259
|
+
throw new Error(`The words short ${String(clip.number)} was cut from are no longer in the narration. Use Pick different moments in ${editSettings.shorts}, then Try again.`);
|
|
260
|
+
start = found.start + body.start;
|
|
261
|
+
end = found.end + body.start;
|
|
262
|
+
}
|
|
263
|
+
const words = clipWords(allWords, start, end);
|
|
247
264
|
// The upright cards whose descriptions fall in the clip, on the clip's own timeline.
|
|
248
265
|
const figures = usesFigureCards(config)
|
|
249
|
-
? figureShots(deps, context, view, "9:16", allWords).flatMap((figure) => figure.end <=
|
|
266
|
+
? figureShots(deps, context, view, "9:16", allWords).flatMap((figure) => figure.end <= start || figure.start >= end
|
|
250
267
|
? []
|
|
251
268
|
: [
|
|
252
269
|
{
|
|
253
270
|
path: figure.path,
|
|
254
|
-
start: Math.max(0, figure.start -
|
|
255
|
-
end: Math.min(
|
|
271
|
+
start: Math.max(0, figure.start - start),
|
|
272
|
+
end: Math.min(end, figure.end) - start,
|
|
256
273
|
},
|
|
257
274
|
])
|
|
258
275
|
: [];
|
|
@@ -276,8 +293,8 @@ async function render(deps, context, piece, snapshot, clip) {
|
|
|
276
293
|
notice: machine.notice,
|
|
277
294
|
master: masterGoal(config, "video"),
|
|
278
295
|
timeline,
|
|
279
|
-
start
|
|
280
|
-
end
|
|
296
|
+
start,
|
|
297
|
+
end,
|
|
281
298
|
images,
|
|
282
299
|
imageSeconds: config.imageSeconds,
|
|
283
300
|
motionStyle: config.motionStyle,
|
|
@@ -362,6 +379,29 @@ async function backgroundMusic(deps, context, view) {
|
|
|
362
379
|
throw new Error(`The shorts' background music file holds no sound. ${fix}`);
|
|
363
380
|
return { path, volume: musicVolumeOf(shorts) };
|
|
364
381
|
}
|
|
382
|
+
// Where the body sits on the video's timeline: after the edge silence, the intro and the gap
|
|
383
|
+
// after it. The word timing is on this clock (`runtime-subtitles.ts`).
|
|
384
|
+
export function bodyWindow(audio) {
|
|
385
|
+
const at = audio.findIndex((segment) => segment.kind === "body");
|
|
386
|
+
const body = audio[at];
|
|
387
|
+
if (body === undefined)
|
|
388
|
+
throw setupError();
|
|
389
|
+
return {
|
|
390
|
+
start: audio.slice(0, at).reduce((sum, segment) => sum + segment.seconds, 0),
|
|
391
|
+
seconds: body.seconds,
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
// The body's words, timed from the body's start (to the microsecond, so the same body reads
|
|
395
|
+
// the same times after any intro).
|
|
396
|
+
export function bodyWords(words, body) {
|
|
397
|
+
const from = (seconds) => Math.max(0, Math.round((seconds - body.start) * 1e6) / 1e6);
|
|
398
|
+
return words.flatMap((word) => {
|
|
399
|
+
const middle = (word.start + word.end) / 2 - body.start;
|
|
400
|
+
return middle < 0 || middle > body.seconds
|
|
401
|
+
? []
|
|
402
|
+
: [{ ...word, start: from(word.start), end: from(word.end) }];
|
|
403
|
+
});
|
|
404
|
+
}
|
|
365
405
|
// What the shorts read the narration's word timing for, in the sentence a missing one fails with.
|
|
366
406
|
const shortsTimingPurpose = "the shorts are cut and captioned from";
|
|
367
407
|
// The project's text model, with the thinking settings saved for this step's catalogue.
|
|
@@ -41,6 +41,7 @@ const keptShortSchema = z
|
|
|
41
41
|
hashtags: z.array(z.string().max(100)).max(30),
|
|
42
42
|
why: z.string().max(2000),
|
|
43
43
|
seed: z.string().max(128).nullable().optional(),
|
|
44
|
+
text: z.string().max(100000).optional(),
|
|
44
45
|
})
|
|
45
46
|
.strict();
|
|
46
47
|
export const revisionContentSchema = z
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { editSettings } from "../../kernel/ports/settings-places.js";
|
|
2
1
|
import { clipBounds } from "./pick.js";
|
|
3
2
|
// Shorts kept through a change of their moments: a count raised or lowered, a new intro or a
|
|
4
3
|
// narration edit that moves the timing. A kept short is remembered by its sentences' text, so
|
|
@@ -21,6 +20,10 @@ export function keptOf(clip, sentences) {
|
|
|
21
20
|
hashtags: clip.hashtags,
|
|
22
21
|
why: clip.why,
|
|
23
22
|
...(clip.seed === undefined ? {} : { seed: clip.seed }),
|
|
23
|
+
text: sentences
|
|
24
|
+
.slice(clip.first - 1, clip.last)
|
|
25
|
+
.map((sentence) => sentence.text)
|
|
26
|
+
.join(" "),
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
29
|
const same = (left, right) => left.replace(/\s+/g, " ").trim() === right.replace(/\s+/g, " ").trim();
|
|
@@ -41,6 +44,12 @@ export function anchorKept(kept, sentences, durationSeconds) {
|
|
|
41
44
|
continue;
|
|
42
45
|
if (!same(opening.text, short.opening) || !same(closing.text, short.closing))
|
|
43
46
|
continue;
|
|
47
|
+
const text = sentences
|
|
48
|
+
.slice(first - 1, last)
|
|
49
|
+
.map((sentence) => sentence.text)
|
|
50
|
+
.join(" ");
|
|
51
|
+
if (short.text !== undefined && !same(text, short.text))
|
|
52
|
+
continue;
|
|
44
53
|
if (taken(first, last))
|
|
45
54
|
continue;
|
|
46
55
|
const bounds = clipBounds(sentences, first, last, durationSeconds);
|
|
@@ -56,10 +65,7 @@ export function anchorKept(kept, sentences, durationSeconds) {
|
|
|
56
65
|
description: short.description,
|
|
57
66
|
hashtags: short.hashtags,
|
|
58
67
|
why: short.why,
|
|
59
|
-
text
|
|
60
|
-
.slice(first - 1, last)
|
|
61
|
-
.map((sentence) => sentence.text)
|
|
62
|
-
.join(" "),
|
|
68
|
+
text,
|
|
63
69
|
...(short.seed === undefined ? {} : { seed: short.seed }),
|
|
64
70
|
};
|
|
65
71
|
}
|
|
@@ -70,23 +76,37 @@ export function anchorKept(kept, sentences, durationSeconds) {
|
|
|
70
76
|
}
|
|
71
77
|
return { picks, lost };
|
|
72
78
|
}
|
|
73
|
-
// The kept shorts and the new ones together: kept
|
|
79
|
+
// The kept shorts and the new ones together: each kept short keeps its number; the new ones
|
|
80
|
+
// take the free numbers (a kept short's whose words changed first, then k+1…) in the order
|
|
74
81
|
// they play, carrying `seed` (the pick's token).
|
|
75
82
|
export function withNewPicks(kept, fresh, seed) {
|
|
83
|
+
const taken = new Set(kept.map((one) => one.number));
|
|
84
|
+
const free = Array.from({ length: kept.length + fresh.length }, (_value, at) => at + 1).filter((number) => !taken.has(number));
|
|
76
85
|
return [
|
|
77
86
|
...kept,
|
|
78
87
|
...fresh
|
|
79
88
|
.toSorted((left, right) => left.start - right.start)
|
|
80
|
-
.map((pick, index) => ({ ...pick, number:
|
|
81
|
-
];
|
|
89
|
+
.map((pick, index) => ({ ...pick, number: free[index] ?? taken.size + index + 1, seed })),
|
|
90
|
+
].toSorted((left, right) => left.number - right.number);
|
|
82
91
|
}
|
|
83
|
-
//
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
+
// Where a clip's sentences are in the narration as it is now: at the same numbers when they
|
|
93
|
+
// still say the same, else wherever the same run of sentences is found once. Undefined when
|
|
94
|
+
// its words are not in the narration any more.
|
|
95
|
+
export function locateClip(sentences, clip, durationSeconds) {
|
|
96
|
+
const count = clip.last - clip.first + 1;
|
|
97
|
+
const says = (first) => same(sentences
|
|
98
|
+
.slice(first - 1, first - 1 + count)
|
|
99
|
+
.map((sentence) => sentence.text)
|
|
100
|
+
.join(" "), clip.text);
|
|
101
|
+
const at = (first) => {
|
|
102
|
+
const bounds = clipBounds(sentences, first, first + count - 1, durationSeconds);
|
|
103
|
+
return bounds === undefined ? undefined : { first, last: first + count - 1, ...bounds };
|
|
104
|
+
};
|
|
105
|
+
if (count >= 1 && clip.last <= sentences.length && says(clip.first))
|
|
106
|
+
return at(clip.first);
|
|
107
|
+
const found = [];
|
|
108
|
+
for (let first = 1; first + count - 1 <= sentences.length; first++)
|
|
109
|
+
if (says(first))
|
|
110
|
+
found.push(first);
|
|
111
|
+
return found.length === 1 && found[0] !== undefined ? at(found[0]) : undefined;
|
|
92
112
|
}
|