@celljs/ta-creator 0.0.0-stage → 4.31.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/README.en.md ADDED
@@ -0,0 +1,14 @@
1
+ # Cell - Ta Creator
2
+
3
+ The content creation package of Ta (built in and off by default, `pi.offByDefault`: turned on from Industries in the market or in Settings → Extensions): a channel without showing your face. Design and research: [docs/design/ta-creator.md](../../docs/design/ta-creator.md).
4
+
5
+ - **The Creator page**: a row of the double's list opens it, five columns: topics, making, to review, published, numbers. One at a time on a phone, a board on a computer. The first time you say what the channel is about and where you publish (Bilibili, Xiaohongshu, Channels, Douyin, Kuaishou, YouTube and Official Accounts to start from; change or add any), and may start a 30-day goal.
6
+ - **Hot topics** (scheduled tasks the server of the package makes, at 8, 12 and 18 each day): news of the field while it is hot, how-tos, and good work abroad explained; you are told of one of heat 85 or more. A work explained names and links its source and quotes it shortly; it is translated whole only when its licence allows it.
7
+ - **Making** (creator-make): topic → script → `episode.json` → `bin/render.mjs`: code typed in, titles and points, the voice of this computer's speech, captions burned in, the label "AI 合成" on every picture, in 16:9, 9:16 and 3:4 with covers, or the pictures of a post; ffmpeg alone, no dependency added.
8
+ - **The review card** (```ta-creator-review`): each platform's version, its title and words, and the checks, in one card on your phone; pass it or ask for a change.
9
+ - **Filled in up to Publish** (creator-publish): once passed, Ta opens each platform's page for creators in your browser, uploads the files, fills in the title, words and tags, ticks the declaration of AI content, and stops before Publish for you to press it. It never signs in for you, publishes, answers comments or inflates numbers.
10
+ - **The review each Monday**: each platform against the week before, what worked, the time it took you (past your cap, fewer topics are offered), the goal, and three topics for the week.
11
+
12
+ ## Data
13
+
14
+ The data of the package (`pi.storage`, written by its server alone): `settings` (niche, platforms, sources, goal, weekly minutes cap, voice), `items` (each piece from topic to published; at most 200 topics never made are kept), `weeks` (each platform's numbers and your minutes, 26 weeks kept), `tasks` (the scheduled tasks made; one removed is not made again). Ta and the tasks change them with `ta call @celljs/ta-creator <method>`.
package/README.md CHANGED
@@ -1,3 +1,14 @@
1
- # Temporary Holding Version
1
+ # Cell - Ta Creator
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Ta 的内容创作行业包(随 Ta 内置、默认关闭:`pi.offByDefault`;在扩展市场的「行业」或 设置 → 扩展 里开启):不出镜也能做内容号。设计与调研见 [docs/design/ta-creator.md](../../docs/design/ta-creator.md)。
4
+
5
+ - **创作者页**:分身列表里的「创作者」一行打开,五栏:选题、制作中、待审、已发布、数据。手机上分段切换,电脑上是看板。首次打开先写内容号做什么、选发在哪些平台(内置 B站、小红书、视频号、抖音、快手、YouTube、公众号,可改可加),可开启 30 天目标。
6
+ - **热点选题**(`pi.host` 建的定时任务,每天 8、12、18 点):按领域看信息源与当天新闻,找热点、实操、国外好内容的解读三类选题;热度 ≥ 85 时提醒你。解读注明出处并附链接、只短引用,许可允许才全文翻译。
7
+ - **出片**(creator-make):选题 → 脚本 → `episode.json` → `bin/render.mjs`:代码逐行打出、标题与要点、本机系统语音配音、字幕烧进画面、每个画面带「AI 合成」标识,按平台出 16:9 / 9:16 / 3:4 视频与封面,或图文图片;只用本机 ffmpeg,不新增依赖。
8
+ - **审稿卡**(```ta-creator-review`):手机上一张卡看各平台版本、标题文案、检查项;「通过」或「改一句」。
9
+ - **填到发布前**(creator-publish):通过后 Ta 在你的浏览器里打开各平台创作者中心,上传文件、填标题文案话题、勾选 AI 生成声明,停在发布按钮前,由你来点。不替你登录、不点发布、不回评论、不刷量。
10
+ - **每周一复盘**:各平台数据对比上周、什么有效、本周花了你多少时间(超过上限就少给选题)、目标进度、本周三个选题。
11
+
12
+ ## 数据
13
+
14
+ 包数据(`pi.storage`,只由服务端写):`settings`(领域、平台、信息源、目标、每周时间上限、配音)、`items`(选题到已发布的每条内容,最多保留 200 条未做的选题)、`weeks`(每周各平台数据与你花的时间,保留 26 周)、`tasks`(建过的定时任务,删掉的不再重建)。Ta 与定时任务用 `ta call @celljs/ta-creator <方法>` 改它们。
package/bin/render.mjs ADDED
@@ -0,0 +1,380 @@
1
+ // web-src/render.ts
2
+ import { execFile } from "node:child_process";
3
+ import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
4
+ import { homedir, tmpdir } from "node:os";
5
+ import { join, resolve } from "node:path";
6
+
7
+ // web-src/episode.ts
8
+ var SIZES = { "16:9": [1920, 1080], "9:16": [1080, 1920], "3:4": [1080, 1440], "1:1": [1080, 1080] };
9
+ var KEYWORDS = new Set("as async await break case catch class const continue def default do elif else except export extends false finally for from function if import in interface let lambda new None null of pass return self static super switch this throw True False true try type typeof undefined var void while with yield".split(" "));
10
+ var COLOURS = { text: "&HDCD3CF&", keyword: "&HEA92C7&", string: "&H6ACE9E&", comment: "&H70635C&", number: "&H64AAFF&", name: "&HF7A27A&" };
11
+ var TOKENS = /(\/\/.*$|#.*$|"(?:[^"\\]|\\.)*"?|'(?:[^'\\]|\\.)*'?|`(?:[^`\\]|\\.)*`?|\b\d+(?:\.\d+)?\b|[A-Za-z_$][\w$]*)/g;
12
+ var EpisodeAss;
13
+ ((EpisodeAss) => {
14
+ function size(aspect) {
15
+ return SIZES[aspect];
16
+ }
17
+ EpisodeAss.size = size;
18
+ function plain(text) {
19
+ return text.replace(/\\/g, "\\​").replace(/\{/g, "\\{").replace(/\}/g, "\\}").replace(/\r?\n/g, " ");
20
+ }
21
+ EpisodeAss.plain = plain;
22
+ function highlight(line) {
23
+ let out = "";
24
+ let at = 0;
25
+ for (const match of line.matchAll(TOKENS)) {
26
+ const token = match[0];
27
+ const index = match.index ?? 0;
28
+ out += plain(line.slice(at, index));
29
+ const colour = /^(\/\/|#)/.test(token) ? COLOURS.comment : /^["'`]/.test(token) ? COLOURS.string : /^\d/.test(token) ? COLOURS.number : KEYWORDS.has(token) ? COLOURS.keyword : /^\s*\(/.test(line.slice(index + token.length)) ? COLOURS.name : undefined;
30
+ out += colour ? `{\\c${colour}}${plain(token)}{\\c${COLOURS.text}}` : plain(token);
31
+ at = index + token.length;
32
+ }
33
+ return (out + plain(line.slice(at))).replace(/ /g, "\\h");
34
+ }
35
+ EpisodeAss.highlight = highlight;
36
+ function captions(text, start, end, max) {
37
+ const parts = [];
38
+ for (const sentence of text.split(/(?<=[。!?!?;;,,、::])/)) {
39
+ let rest = sentence.replace(/[。,、;;,]$/, "").trim();
40
+ while (rest.length > max) {
41
+ parts.push(rest.slice(0, max));
42
+ rest = rest.slice(max);
43
+ }
44
+ if (rest) {
45
+ parts.push(rest);
46
+ }
47
+ }
48
+ const total = parts.reduce((all, one) => all + one.length, 0) || 1;
49
+ let at = start;
50
+ return parts.map((one) => {
51
+ const from = at;
52
+ at += (end - start) * one.length / total;
53
+ return { text: one, start: from, end: at };
54
+ });
55
+ }
56
+ EpisodeAss.captions = captions;
57
+ function time(seconds) {
58
+ const cs = Math.max(0, Math.round(seconds * 100));
59
+ const two = (n) => String(n).padStart(2, "0");
60
+ return `${Math.floor(cs / 360000)}:${two(Math.floor(cs / 6000) % 60)}:${two(Math.floor(cs / 100) % 60)}.${two(cs % 100)}`;
61
+ }
62
+ EpisodeAss.time = time;
63
+ function columns(line) {
64
+ return [...line].reduce((all, ch) => all + ((ch.codePointAt(0) ?? 0) > 11904 ? 2 : 1), 0);
65
+ }
66
+ EpisodeAss.columns = columns;
67
+ function build(episode, timed, aspect, options = {}) {
68
+ const [width, height] = SIZES[aspect];
69
+ const unit = Math.min(width, height) / 1080;
70
+ const tall = height > width;
71
+ const events = [];
72
+ const add = (layer, start, end, style, text) => events.push(`Dialogue: ${layer},${time(start)},${time(end)},${style},,0,0,0,,${text}`);
73
+ const box = (x, y, w, h, colour, r) => `{\\an7\\pos(${Math.round(x)},${Math.round(y)})\\bord0\\shad0\\c${colour}\\p1}${rounded(w, h, r)}{\\p0}`;
74
+ const margin = Math.round(64 * unit);
75
+ const captionSize = Math.round((tall ? 54 : 46) * unit);
76
+ const captionBottom = Math.round((tall ? 300 : 70) * unit);
77
+ for (const { scene, start, end } of timed) {
78
+ if (scene.code?.lines.length) {
79
+ const lines = scene.code.lines.slice(0, tall ? 22 : 14);
80
+ const panelW = width - margin * 2;
81
+ const longest = Math.max(24, ...lines.map(columns));
82
+ const size2 = Math.min(Math.round((tall ? 40 : 44) * unit), Math.floor((panelW - 64 * unit) / (longest * 0.61)));
83
+ const lineH = Math.round(size2 * 1.55);
84
+ const bar = Math.round(52 * unit);
85
+ const panelH = bar + lineH * lines.length + Math.round(40 * unit);
86
+ const top = Math.round(tall ? Math.max(height * 0.14, height * 0.42 - panelH / 2) : Math.max(margin, (height - captionBottom - captionSize - panelH) / 2));
87
+ add(0, start, end, "Code", box(margin, top, panelW, panelH, "&H241E1C&", 18 * unit));
88
+ for (const [i, colour] of ["&H5F57FF&", "&H2EBDFE&", "&H41C928&"].entries()) {
89
+ add(1, start, end, "Code", box(margin + (24 + i * 26) * unit, top + 20 * unit, 13 * unit, 13 * unit, colour, 6.5 * unit));
90
+ }
91
+ if (scene.code.file) {
92
+ add(1, start, end, "Code", `{\\an8\\pos(${Math.round(width / 2)},${Math.round(top + 13 * unit)})\\fs${Math.round(24 * unit)}\\c&H8E8A87&}${plain(scene.code.file)}`);
93
+ }
94
+ const typing = (end - start) * 0.6;
95
+ lines.forEach((line, i) => {
96
+ const from = start + typing * i / lines.length;
97
+ add(2, from, end, "Code", `{\\an7\\pos(${Math.round(margin + 32 * unit)},${top + bar + Math.round(12 * unit) + lineH * i})\\fs${size2}\\fad(120,0)}${highlight(line)}`);
98
+ });
99
+ } else if (scene.title) {
100
+ const size2 = Math.round((tall ? 84 : 92) * unit);
101
+ const y = Math.round(height * (tall ? 0.36 : 0.4));
102
+ add(2, start, end, "Title", `{\\an5\\pos(${width / 2},${y})\\fs${size2}\\fad(250,0)}${plain(scene.title)}`);
103
+ if (scene.sub) {
104
+ add(2, start + 0.3, end, "Title", `{\\an5\\pos(${width / 2},${y + Math.round(size2 * 1.2)})\\fs${Math.round(size2 * 0.45)}\\b0\\c&HA3A3A3&\\fad(250,0)}${plain(scene.sub)}`);
105
+ }
106
+ }
107
+ if (scene.points?.length && !scene.code?.lines.length) {
108
+ const size2 = Math.round((tall ? 50 : 52) * unit);
109
+ const gap = Math.round(size2 * 1.9);
110
+ const first = Math.round(scene.title ? height * (tall ? 0.36 : 0.4) + size2 * 3 : height * (tall ? 0.28 : 0.22));
111
+ const step = (end - start) * 0.7 / scene.points.length;
112
+ scene.points.forEach((point, i) => {
113
+ add(2, start + step * i, end, "Point", `{\\an7\\pos(${margin * 2},${first + gap * i})\\fs${size2}\\fad(200,0)}{\\c&H6ACE9E&}${i + 1}{\\c&HFFFFFF&} ${plain(point)}`);
114
+ });
115
+ }
116
+ if (options.post) {
117
+ add(5, start, end, "Body", `{\\an2\\q0\\fs${Math.round(40 * unit)}}${plain(scene.say)}`);
118
+ continue;
119
+ }
120
+ for (const caption of captions(scene.say, start, end, tall ? 14 : 22)) {
121
+ add(5, caption.start, caption.end, "Caption", `{\\an2\\pos(${width / 2},${height - captionBottom})\\fs${captionSize}}${plain(caption.text)}`);
122
+ }
123
+ }
124
+ const total = timed.length ? timed[timed.length - 1].end : 0;
125
+ add(9, 0, total, "Label", `{\\an9\\pos(${width - margin / 2},${Math.round(margin / 2 + (tall ? 90 * unit : 0))})\\fs${Math.round(26 * unit)}}${plain(episode.label ?? "AI 合成")}`);
126
+ return [
127
+ "[Script Info]",
128
+ "ScriptType: v4.00+",
129
+ `PlayResX: ${width}`,
130
+ `PlayResY: ${height}`,
131
+ "WrapStyle: 2",
132
+ "ScaledBorderAndShadow: yes",
133
+ "",
134
+ "[V4+ Styles]",
135
+ "Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding",
136
+ "Style: Code,Menlo,40,&H00DCD3CF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1",
137
+ "Style: Title,PingFang SC,90,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,0,5,0,0,0,1",
138
+ "Style: Point,PingFang SC,50,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,-1,0,0,0,100,100,0,0,1,0,0,7,0,0,0,1",
139
+ `Style: Caption,PingFang SC,46,&H00FFFFFF,&H000000FF,&H00000000,&H64000000,-1,0,0,0,100,100,0,0,1,${Math.max(2, Math.round(3 * unit))},0,2,0,0,0,1`,
140
+ `Style: Body,PingFang SC,40,&H00E6E6E6,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,2,${margin},${margin},${Math.round(90 * unit)},1`,
141
+ "Style: Label,PingFang SC,26,&H40FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0,0,9,0,0,0,1",
142
+ "",
143
+ "[Events]",
144
+ "Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text",
145
+ ...events,
146
+ ""
147
+ ].join(`
148
+ `);
149
+ }
150
+ EpisodeAss.build = build;
151
+ function rounded(w, h, r) {
152
+ const [W, H, R] = [w, h, Math.min(r, w / 2, h / 2)].map((n) => Math.round(n));
153
+ const k = Math.round(R * 0.45);
154
+ return `m ${R} 0 l ${W - R} 0 b ${W - k} 0 ${W} ${k} ${W} ${R} l ${W} ${H - R} b ${W} ${H - k} ${W - k} ${H} ${W - R} ${H} l ${R} ${H} b ${k} ${H} 0 ${H - k} 0 ${H - R} l 0 ${R} b 0 ${k} ${k} 0 ${R} 0`;
155
+ }
156
+ })(EpisodeAss ||= {});
157
+
158
+ // web-src/render.ts
159
+ var EpisodeRender;
160
+ ((EpisodeRender) => {
161
+ const GAP = 0.6;
162
+ const RATE = 185;
163
+ const BACKGROUND = "0x16171c";
164
+ EpisodeRender.VOICE = "zh-CN-XiaoxiaoNeural";
165
+ const NEURAL = /^[a-z]{2,3}-[A-Z]{2}-\w+Neural$/;
166
+ async function run(file, options) {
167
+ const episode = JSON.parse(await readFile(file, "utf8"));
168
+ if (!episode?.title || !Array.isArray(episode.scenes) || !episode.scenes.length) {
169
+ throw new Error("An episode is { title, scenes: [{ say, code?, title?, sub?, points? }] }.");
170
+ }
171
+ await mkdir(options.out, { recursive: true });
172
+ return options.post ? post(episode, options) : video(episode, options);
173
+ }
174
+ EpisodeRender.run = run;
175
+ async function video(episode, options) {
176
+ const work = await mkdtemp(join(tmpdir(), "ta-creator-"));
177
+ try {
178
+ const wanted = episode.voice ?? EpisodeRender.VOICE;
179
+ const python = NEURAL.test(wanted) ? await edgePython() : undefined;
180
+ if (NEURAL.test(wanted) && !python) {
181
+ console.error(`No Python with edge-tts here (set TA_CREATOR_PYTHON): read in this computer's speech instead of ${wanted}.`);
182
+ }
183
+ const speaker = python ? wanted : pickVoice(await exec("say", ["-v", "?"]), NEURAL.test(wanted) ? undefined : wanted);
184
+ const timed = [];
185
+ const parts = [];
186
+ let at = 0;
187
+ for (const [i, scene] of episode.scenes.entries()) {
188
+ const spoken = join(work, python ? `${i}.mp3` : `${i}.aiff`);
189
+ const said = scene.say.replace(/`/g, "");
190
+ if (python) {
191
+ await exec(python, ["-m", "edge_tts", "--voice", speaker, "--rate", neuralRate(episode.rate), "--text", said, "--write-media", spoken]);
192
+ } else {
193
+ await exec("say", ["-v", speaker, "-r", String(episode.rate ?? RATE), "-o", spoken, paced(said)]);
194
+ }
195
+ const seconds = await length(spoken) + GAP;
196
+ const padded = join(work, `${i}.wav`);
197
+ await exec("ffmpeg", [
198
+ "-y",
199
+ "-loglevel",
200
+ "error",
201
+ "-i",
202
+ spoken,
203
+ "-af",
204
+ `apad=whole_dur=${seconds.toFixed(3)}`,
205
+ "-ar",
206
+ "44100",
207
+ "-ac",
208
+ "1",
209
+ padded
210
+ ]);
211
+ timed.push({ scene, start: at, end: at + seconds });
212
+ parts.push(padded);
213
+ at += seconds;
214
+ }
215
+ const list = join(work, "list.txt");
216
+ await writeFile(list, parts.map((one) => `file '${one.replace(/'/g, "'\\''")}'`).join(`
217
+ `));
218
+ const voice = join(options.out, "voice.m4a");
219
+ await exec("ffmpeg", ["-y", "-loglevel", "error", "-f", "concat", "-safe", "0", "-i", list, "-c:a", "aac", "-b:a", "128k", voice]);
220
+ await writeFile(join(options.out, "captions.srt"), srt(timed));
221
+ const made = [voice, join(options.out, "captions.srt")];
222
+ for (const aspect of options.aspects) {
223
+ const [width, height] = EpisodeAss.size(aspect);
224
+ const name = aspect.replace(":", "x");
225
+ const ass = join(work, `${name}.ass`);
226
+ await writeFile(ass, EpisodeAss.build(episode, timed, aspect));
227
+ const mp4 = join(options.out, `${name}.mp4`);
228
+ await exec("ffmpeg", [
229
+ "-y",
230
+ "-loglevel",
231
+ "error",
232
+ "-f",
233
+ "lavfi",
234
+ "-i",
235
+ `color=c=${BACKGROUND}:s=${width}x${height}:r=30:d=${at.toFixed(3)}`,
236
+ "-i",
237
+ voice,
238
+ "-vf",
239
+ `ass=${filterPath(ass)}`,
240
+ "-c:v",
241
+ "libx264",
242
+ "-preset",
243
+ "medium",
244
+ "-crf",
245
+ "20",
246
+ "-pix_fmt",
247
+ "yuv420p",
248
+ "-c:a",
249
+ "copy",
250
+ "-shortest",
251
+ "-movflags",
252
+ "+faststart",
253
+ "-metadata",
254
+ `title=${episode.title}`,
255
+ "-metadata",
256
+ "comment=AIGC: made with AI (picture, voice and captions)",
257
+ mp4
258
+ ]);
259
+ const first = timed.find((one) => one.scene.title) ?? timed[0];
260
+ const cover = join(options.out, `cover-${name}.png`);
261
+ await exec("ffmpeg", ["-y", "-loglevel", "error", "-ss", String(Math.max(0.1, first.end - 0.2)), "-i", mp4, "-frames:v", "1", cover]);
262
+ made.push(mp4, cover);
263
+ }
264
+ return made;
265
+ } finally {
266
+ await rm(work, { recursive: true, force: true });
267
+ }
268
+ }
269
+ async function post(episode, options) {
270
+ const work = await mkdtemp(join(tmpdir(), "ta-creator-"));
271
+ try {
272
+ const made = [];
273
+ for (const aspect of options.aspects) {
274
+ const [width, height] = EpisodeAss.size(aspect);
275
+ const name = aspect.replace(":", "x");
276
+ for (const [i, scene] of episode.scenes.entries()) {
277
+ const ass = join(work, `${name}-${i}.ass`);
278
+ await writeFile(ass, EpisodeAss.build(episode, [{ scene, start: 0, end: 10 }], aspect, { post: true }));
279
+ const png = join(options.out, `post-${name}-${String(i + 1).padStart(2, "0")}.png`);
280
+ await exec("ffmpeg", [
281
+ "-y",
282
+ "-loglevel",
283
+ "error",
284
+ "-f",
285
+ "lavfi",
286
+ "-i",
287
+ `color=c=${BACKGROUND}:s=${width}x${height}:d=10`,
288
+ "-ss",
289
+ "9.9",
290
+ "-vf",
291
+ `ass=${filterPath(ass)}`,
292
+ "-frames:v",
293
+ "1",
294
+ png
295
+ ]);
296
+ made.push(png);
297
+ }
298
+ }
299
+ return made;
300
+ } finally {
301
+ await rm(work, { recursive: true, force: true });
302
+ }
303
+ }
304
+ function pickVoice(list, wanted) {
305
+ const voices = list.split(`
306
+ `).map((line) => /^(.+?)\s{2,}(zh_CN)\s/.exec(line)?.[1].trim()).filter((one) => !!one);
307
+ const rank = (name) => /高品质|Premium/i.test(name) ? 3 : /增强|Enhanced/i.test(name) ? 2 : /^(Tingting|Lili|Yue)\b/.test(name) ? 1 : 0;
308
+ const best = (names) => [...names].sort((a, b) => rank(b) - rank(a))[0];
309
+ const base = wanted?.replace(/\s*[((].*$/, "");
310
+ return base && best(voices.filter((one) => one.startsWith(base))) || best(voices) || wanted || "Tingting";
311
+ }
312
+ EpisodeRender.pickVoice = pickVoice;
313
+ function paced(text) {
314
+ return text.replace(/`/g, "").replace(/([,、;:,;:])\s*/g, "$1[[slnc 150]]").replace(/([。!?!?…])\s*/g, "$1[[slnc 300]]");
315
+ }
316
+ EpisodeRender.paced = paced;
317
+ function neuralRate(rate) {
318
+ const percent = rate ? Math.round((rate / RATE - 1) * 100) : 0;
319
+ return `${percent >= 0 ? "+" : ""}${Math.max(-50, Math.min(100, percent))}%`;
320
+ }
321
+ EpisodeRender.neuralRate = neuralRate;
322
+ async function edgePython() {
323
+ const candidates = [process.env.TA_CREATOR_PYTHON, join(homedir(), "lemo-opuscar/.venv/bin/python"), "python3"].filter((one) => !!one);
324
+ for (const one of candidates) {
325
+ if (await exec(one, ["-c", "import edge_tts"]).then(() => true, () => false)) {
326
+ return one;
327
+ }
328
+ }
329
+ return;
330
+ }
331
+ function srt(timed) {
332
+ const stamp = (s) => EpisodeAss.time(s).replace(/^(\d+):/, (_all, h) => `${h.padStart(2, "0")}:`).replace(".", ",") + "0";
333
+ return timed.flatMap((one) => EpisodeAss.captions(one.scene.say, one.start, one.end, 22)).map((one, i) => `${i + 1}
334
+ ${stamp(one.start)} --> ${stamp(one.end)}
335
+ ${one.text}
336
+ `).join(`
337
+ `);
338
+ }
339
+ EpisodeRender.srt = srt;
340
+ function filterPath(path) {
341
+ return path.replace(/\\/g, "/").replace(/[:',[\]]/g, (char) => `\\${char}`);
342
+ }
343
+ async function length(file) {
344
+ const out = await exec("ffprobe", ["-v", "error", "-show_entries", "format=duration", "-of", "csv=p=0", file]);
345
+ return Number.parseFloat(out) || 1;
346
+ }
347
+ function exec(command, args) {
348
+ return new Promise((done, fail) => execFile(command, args, { maxBuffer: 16 * 1024 * 1024 }, (error, stdout, stderr) => {
349
+ if (error) {
350
+ const missing = error.code === "ENOENT";
351
+ fail(new Error(missing ? `${command} is not on this computer${command.startsWith("ff") ? " (brew install ffmpeg)" : ""}.` : `${command} failed: ${stderr || error.message}`));
352
+ } else {
353
+ done(String(stdout));
354
+ }
355
+ }));
356
+ }
357
+ })(EpisodeRender ||= {});
358
+ if (process.argv[1]?.endsWith("render.mjs")) {
359
+ const args = process.argv.slice(2);
360
+ const flag = (name) => {
361
+ const at = args.indexOf(name);
362
+ return at >= 0 ? args.splice(at, 2)[1] : undefined;
363
+ };
364
+ const post = args.includes("--post");
365
+ const aspects = (flag("--aspects") ?? (post ? "3:4" : "16:9,9:16,3:4")).split(",");
366
+ const out = flag("--out");
367
+ const file = args.find((one) => !one.startsWith("--"));
368
+ if (!file || aspects.some((one) => !EpisodeAss.size(one))) {
369
+ console.error("node render.mjs <episode.json> [--aspects 16:9,9:16,3:4,1:1] [--post] [--out <dir>]");
370
+ process.exit(2);
371
+ }
372
+ EpisodeRender.run(resolve(file), { aspects, post, out: resolve(out ?? join(file, "..")) }).then((made) => console.log(made.join(`
373
+ `)), (error) => {
374
+ console.error(error instanceof Error ? error.message : String(error));
375
+ process.exit(1);
376
+ });
377
+ }
378
+ export {
379
+ EpisodeRender
380
+ };