@mcut/cli 0.1.0-alpha.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/LICENSE +187 -0
- package/README.md +11 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +279 -0
- package/dist/index.d.ts +128 -0
- package/dist/index.js +2 -0
- package/dist/io-BcGV4lKK.js +328 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the
|
|
13
|
+
copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other
|
|
16
|
+
entities that control, are controlled by, or are under common control with
|
|
17
|
+
that entity. For the purposes of this definition, "control" means (i) the
|
|
18
|
+
power, direct or indirect, to cause the direction or management of such
|
|
19
|
+
entity, whether by contract or otherwise, or (ii) ownership of fifty percent
|
|
20
|
+
(50%) or more of the outstanding shares, or (iii) beneficial ownership of
|
|
21
|
+
such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
24
|
+
permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation source, and
|
|
28
|
+
configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical transformation
|
|
31
|
+
or translation of a Source form, including but not limited to compiled object
|
|
32
|
+
code, generated documentation, and conversions to other media types.
|
|
33
|
+
|
|
34
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
35
|
+
made available under the License, as indicated by a copyright notice that is
|
|
36
|
+
included in or attached to the work (an example is provided in the Appendix
|
|
37
|
+
below).
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object form,
|
|
40
|
+
that is based on (or derived from) the Work and for which the editorial
|
|
41
|
+
revisions, annotations, elaborations, or other modifications represent, as a
|
|
42
|
+
whole, an original work of authorship. For the purposes of this License,
|
|
43
|
+
Derivative Works shall not include works that remain separable from, or
|
|
44
|
+
merely link (or bind by name) to the interfaces of, the Work and Derivative
|
|
45
|
+
Works thereof.
|
|
46
|
+
|
|
47
|
+
"Contribution" shall mean any work of authorship, including the original
|
|
48
|
+
version of the Work and any modifications or additions to that Work or
|
|
49
|
+
Derivative Works thereof, that is intentionally submitted to Licensor for
|
|
50
|
+
inclusion in the Work by the copyright owner or by an individual or Legal
|
|
51
|
+
Entity authorized to submit on behalf of the copyright owner. For the
|
|
52
|
+
purposes of this definition, "submitted" means any form of electronic,
|
|
53
|
+
verbal, or written communication sent to the Licensor or its representatives,
|
|
54
|
+
including but not limited to communication on electronic mailing lists,
|
|
55
|
+
source code control systems, and issue tracking systems that are managed by,
|
|
56
|
+
or on behalf of, the Licensor for the purpose of discussing and improving the
|
|
57
|
+
Work, but excluding communication that is conspicuously marked or otherwise
|
|
58
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
59
|
+
|
|
60
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on
|
|
61
|
+
behalf of whom a Contribution has been received by Licensor and subsequently
|
|
62
|
+
incorporated within the Work.
|
|
63
|
+
|
|
64
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
65
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
66
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
67
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
68
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
69
|
+
Object form.
|
|
70
|
+
|
|
71
|
+
3. Grant of Patent License. Subject to the terms and conditions of this
|
|
72
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
73
|
+
non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this
|
|
74
|
+
section) patent license to make, have made, use, offer to sell, sell, import,
|
|
75
|
+
and otherwise transfer the Work, where such license applies only to those
|
|
76
|
+
patent claims licensable by such Contributor that are necessarily infringed
|
|
77
|
+
by their Contribution(s) alone or by combination of their Contribution(s)
|
|
78
|
+
with the Work to which such Contribution(s) was submitted. If You institute
|
|
79
|
+
patent litigation against any entity (including a cross-claim or counterclaim
|
|
80
|
+
in a lawsuit) alleging that the Work or a Contribution incorporated within
|
|
81
|
+
the Work constitutes direct or contributory patent infringement, then any
|
|
82
|
+
patent licenses granted to You under this License for that Work shall
|
|
83
|
+
terminate as of the date such litigation is filed.
|
|
84
|
+
|
|
85
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
86
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
87
|
+
Source or Object form, provided that You meet the following conditions:
|
|
88
|
+
|
|
89
|
+
(a) You must give any other recipients of the Work or Derivative Works a
|
|
90
|
+
copy of this License; and
|
|
91
|
+
|
|
92
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
93
|
+
You changed the files; and
|
|
94
|
+
|
|
95
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
96
|
+
distribute, all copyright, patent, trademark, and attribution notices from
|
|
97
|
+
the Source form of the Work, excluding those notices that do not pertain to
|
|
98
|
+
any part of the Derivative Works; and
|
|
99
|
+
|
|
100
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution,
|
|
101
|
+
then any Derivative Works that You distribute must include a readable copy of
|
|
102
|
+
the attribution notices contained within such NOTICE file, excluding those
|
|
103
|
+
notices that do not pertain to any part of the Derivative Works, in at least
|
|
104
|
+
one of the following places: within a NOTICE text file distributed as part of
|
|
105
|
+
the Derivative Works; within the Source form or documentation, if provided
|
|
106
|
+
along with the Derivative Works; or, within a display generated by the
|
|
107
|
+
Derivative Works, if and wherever such third-party notices normally appear.
|
|
108
|
+
The contents of the NOTICE file are for informational purposes only and do
|
|
109
|
+
not modify the License. You may add Your own attribution notices within
|
|
110
|
+
Derivative Works that You distribute, alongside or as an addendum to the
|
|
111
|
+
NOTICE text from the Work, provided that such additional attribution notices
|
|
112
|
+
cannot be construed as modifying the License.
|
|
113
|
+
|
|
114
|
+
You may add Your own copyright statement to Your modifications and may
|
|
115
|
+
provide additional or different license terms and conditions for use,
|
|
116
|
+
reproduction, or distribution of Your modifications, or for any such
|
|
117
|
+
Derivative Works as a whole, provided Your use, reproduction, and
|
|
118
|
+
distribution of the Work otherwise complies with the conditions stated in
|
|
119
|
+
this License.
|
|
120
|
+
|
|
121
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
122
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
123
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
124
|
+
additional terms or conditions. Notwithstanding the above, nothing herein
|
|
125
|
+
shall supersede or modify the terms of any separate license agreement you may
|
|
126
|
+
have executed with Licensor regarding such Contributions.
|
|
127
|
+
|
|
128
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
129
|
+
trademarks, service marks, or product names of the Licensor, except as
|
|
130
|
+
required for reasonable and customary use in describing the origin of the
|
|
131
|
+
Work and reproducing the content of the NOTICE file.
|
|
132
|
+
|
|
133
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
134
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
135
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
136
|
+
KIND, either express or implied, including, without limitation, any warranties
|
|
137
|
+
or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
138
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
139
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
140
|
+
associated with Your exercise of permissions under this License.
|
|
141
|
+
|
|
142
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
143
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
144
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to
|
|
145
|
+
in writing, shall any Contributor be liable to You for damages, including any
|
|
146
|
+
direct, indirect, special, incidental, or consequential damages of any
|
|
147
|
+
character arising as a result of this License or out of the use or inability
|
|
148
|
+
to use the Work (including but not limited to damages for loss of goodwill,
|
|
149
|
+
work stoppage, computer failure or malfunction, or any and all other
|
|
150
|
+
commercial damages or losses), even if such Contributor has been advised of
|
|
151
|
+
the possibility of such damages.
|
|
152
|
+
|
|
153
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work
|
|
154
|
+
or Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
155
|
+
acceptance of support, warranty, indemnity, or other liability obligations
|
|
156
|
+
and/or rights consistent with this License. However, in accepting such
|
|
157
|
+
obligations, You may act only on Your own behalf and on Your sole
|
|
158
|
+
responsibility, not on behalf of any other Contributor, and only if You agree
|
|
159
|
+
to indemnify, defend, and hold each Contributor harmless for any liability
|
|
160
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
161
|
+
accepting any such warranty or additional liability.
|
|
162
|
+
|
|
163
|
+
END OF TERMS AND CONDITIONS
|
|
164
|
+
|
|
165
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
166
|
+
|
|
167
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
168
|
+
notice, with the fields enclosed by brackets "[]" replaced with your own
|
|
169
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
170
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
171
|
+
recommend that a file or class name and description of purpose be included on
|
|
172
|
+
the same "printed page" as the copyright notice for easier identification
|
|
173
|
+
within third-party archives.
|
|
174
|
+
|
|
175
|
+
Copyright [yyyy] [name of copyright owner]
|
|
176
|
+
|
|
177
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
178
|
+
you may not use this file except in compliance with the License.
|
|
179
|
+
You may obtain a copy of the License at
|
|
180
|
+
|
|
181
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
182
|
+
|
|
183
|
+
Unless required by applicable law or agreed to in writing, software
|
|
184
|
+
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
185
|
+
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
186
|
+
See the License for the specific language governing permissions and
|
|
187
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @mcut/cli
|
|
2
|
+
|
|
3
|
+
Headless command-line tools for mcut project documents.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
bunx @mcut/cli --help
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The CLI can scaffold, validate, summarize, lint, and batch-edit mcut project
|
|
10
|
+
JSON files. Browser-only export remains in `@mcut/media`; this package focuses
|
|
11
|
+
on project document operations that can run in Node-compatible environments.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { a as PLATFORM_PRESETS, c as planSilenceCuts, i as writeProjectFile, l as lintProject, n as readTranscriptFile, o as getPlatformPreset, s as buildCaptionsCommand, t as readProjectFile } from "./io-BcGV4lKK.js";
|
|
3
|
+
import { CommandError, EditorEngine, ProjectFormatError, createProject, listToolDefinitions, summarizeProject } from "@mcut/timeline";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import { existsSync } from "node:fs";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
//#region src/cli.ts
|
|
8
|
+
/**
|
|
9
|
+
* mcut on the command line. Every subcommand operates on a project document
|
|
10
|
+
* (JSON) the way the editor does: parse → dispatch commands → persist. Export
|
|
11
|
+
* stays in the browser (WebCodecs); this tool edits the document.
|
|
12
|
+
*/
|
|
13
|
+
const HELP = `mcut — headless tools for mcut project documents
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
mcut new [file] [--preset <id>] [--name <name>] [--force]
|
|
17
|
+
mcut validate <file> [--strict]
|
|
18
|
+
mcut summarize <file>
|
|
19
|
+
mcut apply <file> [commands.json] [--dry-run] (or pipe commands on stdin)
|
|
20
|
+
mcut captions <file> --transcript <t.json> [--element <id>] [--style <id>]
|
|
21
|
+
[--max-chars <n>] [--replace] [--dry-run]
|
|
22
|
+
mcut silence-cuts <file> --transcript <t.json> --element <id>
|
|
23
|
+
[--min-gap <ms>] [--padding <ms>] [--keep-ends] [--dry-run]
|
|
24
|
+
mcut commands [--json] [--name <command>]
|
|
25
|
+
mcut presets [--json]
|
|
26
|
+
|
|
27
|
+
Commands:
|
|
28
|
+
new Scaffold a project document from a platform preset (default: youtube).
|
|
29
|
+
validate Parse + lint a project; exits 1 on errors (--strict: warnings too).
|
|
30
|
+
summarize Print the compact textual rendering of a project (read this before editing).
|
|
31
|
+
apply Dispatch a JSON command batch (object or array) as one undo step, then save.
|
|
32
|
+
captions Add captions from a transcript JSON ({ words: [{ text, startMs, endMs }] }).
|
|
33
|
+
silence-cuts Cut transcript silence out of one element (splits + ripple deletes + edge trims).
|
|
34
|
+
commands List every editing command; --name prints one command's JSON schema.
|
|
35
|
+
presets List platform presets (dimensions, fps, safe areas).
|
|
36
|
+
`;
|
|
37
|
+
var CliError = class extends Error {};
|
|
38
|
+
function fail(message) {
|
|
39
|
+
throw new CliError(message);
|
|
40
|
+
}
|
|
41
|
+
async function readStdin() {
|
|
42
|
+
const chunks = [];
|
|
43
|
+
for await (const chunk of process.stdin) chunks.push(chunk);
|
|
44
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
45
|
+
}
|
|
46
|
+
function parseCommandBatch(raw) {
|
|
47
|
+
let parsed;
|
|
48
|
+
try {
|
|
49
|
+
parsed = JSON.parse(raw);
|
|
50
|
+
} catch {
|
|
51
|
+
fail("commands input is not valid JSON");
|
|
52
|
+
}
|
|
53
|
+
const list = Array.isArray(parsed) ? parsed : [parsed];
|
|
54
|
+
for (const item of list) if (typeof item !== "object" || item === null || typeof item.type !== "string") fail("each command must be an object with a string \"type\"");
|
|
55
|
+
return list;
|
|
56
|
+
}
|
|
57
|
+
async function cmdNew(argv) {
|
|
58
|
+
const { values, positionals } = parseArgs({
|
|
59
|
+
args: argv,
|
|
60
|
+
allowPositionals: true,
|
|
61
|
+
options: {
|
|
62
|
+
preset: {
|
|
63
|
+
type: "string",
|
|
64
|
+
default: "youtube"
|
|
65
|
+
},
|
|
66
|
+
name: { type: "string" },
|
|
67
|
+
force: {
|
|
68
|
+
type: "boolean",
|
|
69
|
+
default: false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const file = positionals[0] ?? "project.mcut.json";
|
|
74
|
+
const preset = getPlatformPreset(values.preset);
|
|
75
|
+
if (!preset) fail(`unknown preset "${values.preset}" (known: ${PLATFORM_PRESETS.map((p) => p.id).join(", ")})`);
|
|
76
|
+
if (existsSync(file) && !values.force) fail(`${file} already exists (use --force to overwrite)`);
|
|
77
|
+
await writeProjectFile(file, createProject({
|
|
78
|
+
name: values.name ?? "Untitled",
|
|
79
|
+
width: preset.width,
|
|
80
|
+
height: preset.height,
|
|
81
|
+
fps: preset.fps
|
|
82
|
+
}));
|
|
83
|
+
console.log(`Created ${file} — ${preset.label}, ${preset.width}x${preset.height}@${preset.fps}`);
|
|
84
|
+
}
|
|
85
|
+
async function cmdValidate(argv) {
|
|
86
|
+
const { values, positionals } = parseArgs({
|
|
87
|
+
args: argv,
|
|
88
|
+
allowPositionals: true,
|
|
89
|
+
options: { strict: {
|
|
90
|
+
type: "boolean",
|
|
91
|
+
default: false
|
|
92
|
+
} }
|
|
93
|
+
});
|
|
94
|
+
const file = positionals[0] ?? fail("validate needs a project file");
|
|
95
|
+
const issues = lintProject(await readProjectFile(file));
|
|
96
|
+
for (const issue of issues) console.log(`${issue.severity}[${issue.code}]: ${issue.message}`);
|
|
97
|
+
const errors = issues.filter((i) => i.severity === "error").length;
|
|
98
|
+
const warnings = issues.length - errors;
|
|
99
|
+
console.log(issues.length === 0 ? `OK: ${file} is valid` : `${file}: ${errors} error(s), ${warnings} warning(s)`);
|
|
100
|
+
if (errors > 0 || values.strict && warnings > 0) process.exitCode = 1;
|
|
101
|
+
}
|
|
102
|
+
async function cmdSummarize(argv) {
|
|
103
|
+
const { positionals } = parseArgs({
|
|
104
|
+
args: argv,
|
|
105
|
+
allowPositionals: true,
|
|
106
|
+
options: {}
|
|
107
|
+
});
|
|
108
|
+
const file = positionals[0] ?? fail("summarize needs a project file");
|
|
109
|
+
console.log(summarizeProject(await readProjectFile(file)));
|
|
110
|
+
}
|
|
111
|
+
async function cmdApply(argv) {
|
|
112
|
+
const { values, positionals } = parseArgs({
|
|
113
|
+
args: argv,
|
|
114
|
+
allowPositionals: true,
|
|
115
|
+
options: { "dry-run": {
|
|
116
|
+
type: "boolean",
|
|
117
|
+
default: false
|
|
118
|
+
} }
|
|
119
|
+
});
|
|
120
|
+
const file = positionals[0] ?? fail("apply needs a project file");
|
|
121
|
+
const source = positionals[1];
|
|
122
|
+
const commands = parseCommandBatch(source && source !== "-" ? await readFile(source, "utf8") : await readStdin());
|
|
123
|
+
const engine = new EditorEngine({ project: await readProjectFile(file) });
|
|
124
|
+
engine.transact(() => {
|
|
125
|
+
for (const command of commands) engine.dispatch(command);
|
|
126
|
+
});
|
|
127
|
+
if (!values["dry-run"]) await writeProjectFile(file, engine.project);
|
|
128
|
+
console.log(`${values["dry-run"] ? "(dry run) " : ""}Applied ${commands.length} command(s) to ${file}\n`);
|
|
129
|
+
console.log(summarizeProject(engine.project));
|
|
130
|
+
}
|
|
131
|
+
async function cmdCaptions(argv) {
|
|
132
|
+
const { values, positionals } = parseArgs({
|
|
133
|
+
args: argv,
|
|
134
|
+
allowPositionals: true,
|
|
135
|
+
options: {
|
|
136
|
+
transcript: { type: "string" },
|
|
137
|
+
element: { type: "string" },
|
|
138
|
+
style: { type: "string" },
|
|
139
|
+
"max-chars": { type: "string" },
|
|
140
|
+
replace: {
|
|
141
|
+
type: "boolean",
|
|
142
|
+
default: false
|
|
143
|
+
},
|
|
144
|
+
"dry-run": {
|
|
145
|
+
type: "boolean",
|
|
146
|
+
default: false
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const file = positionals[0] ?? fail("captions needs a project file");
|
|
151
|
+
if (!values.transcript) fail("captions needs --transcript <file>");
|
|
152
|
+
const project = await readProjectFile(file);
|
|
153
|
+
const command = buildCaptionsCommand(project, await readTranscriptFile(values.transcript), {
|
|
154
|
+
...values.element ? { elementId: values.element } : {},
|
|
155
|
+
...values.style ? { styleId: values.style } : {},
|
|
156
|
+
...values["max-chars"] ? { maxChars: Number(values["max-chars"]) } : {},
|
|
157
|
+
replace: values.replace
|
|
158
|
+
});
|
|
159
|
+
if (values["dry-run"]) {
|
|
160
|
+
console.log(JSON.stringify(command, null, 2));
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const engine = new EditorEngine({ project });
|
|
164
|
+
engine.dispatch(command);
|
|
165
|
+
await writeProjectFile(file, engine.project);
|
|
166
|
+
const count = command.captions.length;
|
|
167
|
+
console.log(`Added ${count} caption(s) to ${file}\n`);
|
|
168
|
+
console.log(summarizeProject(engine.project));
|
|
169
|
+
}
|
|
170
|
+
async function cmdSilenceCuts(argv) {
|
|
171
|
+
const { values, positionals } = parseArgs({
|
|
172
|
+
args: argv,
|
|
173
|
+
allowPositionals: true,
|
|
174
|
+
options: {
|
|
175
|
+
transcript: { type: "string" },
|
|
176
|
+
element: { type: "string" },
|
|
177
|
+
"min-gap": { type: "string" },
|
|
178
|
+
padding: { type: "string" },
|
|
179
|
+
"keep-ends": {
|
|
180
|
+
type: "boolean",
|
|
181
|
+
default: false
|
|
182
|
+
},
|
|
183
|
+
"dry-run": {
|
|
184
|
+
type: "boolean",
|
|
185
|
+
default: false
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
const file = positionals[0] ?? fail("silence-cuts needs a project file");
|
|
190
|
+
if (!values.transcript) fail("silence-cuts needs --transcript <file>");
|
|
191
|
+
if (!values.element) fail("silence-cuts needs --element <id>");
|
|
192
|
+
const project = await readProjectFile(file);
|
|
193
|
+
const transcript = await readTranscriptFile(values.transcript);
|
|
194
|
+
const plan = planSilenceCuts(project, values.element, transcript, {
|
|
195
|
+
...values["min-gap"] ? { minGapMs: Number(values["min-gap"]) } : {},
|
|
196
|
+
...values.padding ? { paddingMs: Number(values.padding) } : {},
|
|
197
|
+
trimEnds: !values["keep-ends"]
|
|
198
|
+
});
|
|
199
|
+
if (plan.silences.length === 0) {
|
|
200
|
+
console.log("No silences found — nothing to cut.");
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (values["dry-run"]) {
|
|
204
|
+
console.log(JSON.stringify({
|
|
205
|
+
silences: plan.silences,
|
|
206
|
+
commands: plan.commands
|
|
207
|
+
}, null, 2));
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
await writeProjectFile(file, plan.project);
|
|
211
|
+
console.log(`Cut ${plan.silences.length} silence(s), ${(plan.removedMs / 1e3).toFixed(2)}s removed\n`);
|
|
212
|
+
console.log(summarizeProject(plan.project));
|
|
213
|
+
}
|
|
214
|
+
async function cmdCommands(argv) {
|
|
215
|
+
const { values } = parseArgs({
|
|
216
|
+
args: argv,
|
|
217
|
+
options: {
|
|
218
|
+
json: {
|
|
219
|
+
type: "boolean",
|
|
220
|
+
default: false
|
|
221
|
+
},
|
|
222
|
+
name: { type: "string" }
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
const tools = listToolDefinitions();
|
|
226
|
+
if (values.name) {
|
|
227
|
+
const tool = tools.find((t) => t.name === values.name);
|
|
228
|
+
if (!tool) fail(`unknown command "${values.name}"`);
|
|
229
|
+
console.log(JSON.stringify(tool, null, 2));
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (values.json) {
|
|
233
|
+
console.log(JSON.stringify(tools, null, 2));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
for (const tool of tools) console.log(`${tool.name} — ${tool.description}`);
|
|
237
|
+
}
|
|
238
|
+
async function cmdPresets(argv) {
|
|
239
|
+
const { values } = parseArgs({
|
|
240
|
+
args: argv,
|
|
241
|
+
options: { json: {
|
|
242
|
+
type: "boolean",
|
|
243
|
+
default: false
|
|
244
|
+
} }
|
|
245
|
+
});
|
|
246
|
+
if (values.json) {
|
|
247
|
+
console.log(JSON.stringify(PLATFORM_PRESETS, null, 2));
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
for (const preset of PLATFORM_PRESETS) console.log(`${preset.id} — ${preset.label}, ${preset.width}x${preset.height}@${preset.fps}`);
|
|
251
|
+
}
|
|
252
|
+
async function main() {
|
|
253
|
+
const [command, ...rest] = process.argv.slice(2);
|
|
254
|
+
switch (command) {
|
|
255
|
+
case "new": return cmdNew(rest);
|
|
256
|
+
case "validate": return cmdValidate(rest);
|
|
257
|
+
case "summarize": return cmdSummarize(rest);
|
|
258
|
+
case "apply": return cmdApply(rest);
|
|
259
|
+
case "captions": return cmdCaptions(rest);
|
|
260
|
+
case "silence-cuts": return cmdSilenceCuts(rest);
|
|
261
|
+
case "commands": return cmdCommands(rest);
|
|
262
|
+
case "presets": return cmdPresets(rest);
|
|
263
|
+
case void 0:
|
|
264
|
+
case "help":
|
|
265
|
+
case "--help":
|
|
266
|
+
case "-h":
|
|
267
|
+
console.log(HELP);
|
|
268
|
+
return;
|
|
269
|
+
default: fail(`unknown command "${command}" — run \`mcut help\``);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
main().catch((error) => {
|
|
273
|
+
if (error instanceof CommandError || error instanceof ProjectFormatError) console.error(`${error.name} (${error.code}): ${error.message}`);
|
|
274
|
+
else if (error instanceof CliError) console.error(`mcut: ${error.message}`);
|
|
275
|
+
else console.error(error instanceof Error ? error.message : String(error));
|
|
276
|
+
process.exitCode = 1;
|
|
277
|
+
});
|
|
278
|
+
//#endregion
|
|
279
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { AnyCommand, Project } from "@mcut/timeline";
|
|
2
|
+
import { TranscriptResult } from "@mcut/transcription";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
|
|
5
|
+
//#region src/lint.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Things `parseProject` cannot reject (it validates shape, not cross-entity
|
|
8
|
+
* invariants) but that make a project render wrong or export badly. Commands
|
|
9
|
+
* maintain these invariants; hand-edited or generated JSON may not.
|
|
10
|
+
*/
|
|
11
|
+
interface LintIssue {
|
|
12
|
+
severity: 'error' | 'warning';
|
|
13
|
+
code: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}
|
|
16
|
+
declare function lintProject(project: Project): LintIssue[];
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/silence.d.ts
|
|
19
|
+
interface SilenceCutOptions {
|
|
20
|
+
/** Word gaps shorter than this are speech rhythm, not silence. Default 600. */
|
|
21
|
+
minGapMs?: number;
|
|
22
|
+
/** Breathing room kept on each side of a cut. Default 120. */
|
|
23
|
+
paddingMs?: number;
|
|
24
|
+
/** Speech chunks shorter than this merge into the surrounding cut. Default 250. */
|
|
25
|
+
minKeepMs?: number;
|
|
26
|
+
/** Also cut silence before the first and after the last word. Default true. */
|
|
27
|
+
trimEnds?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/** A window of source-media time (same clock as the transcript). */
|
|
30
|
+
interface SilenceWindow {
|
|
31
|
+
startMs: number;
|
|
32
|
+
endMs: number;
|
|
33
|
+
}
|
|
34
|
+
interface SilenceCutPlan {
|
|
35
|
+
/** The cuts, in source-media time, padding already applied. */
|
|
36
|
+
silences: SilenceWindow[];
|
|
37
|
+
/** Every command dispatched, in order — replayable on the input project. */
|
|
38
|
+
commands: AnyCommand[];
|
|
39
|
+
removedMs: number;
|
|
40
|
+
/** The project with all cuts applied. */
|
|
41
|
+
project: Project;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Plan and apply silence cuts on one video/audio element from its transcript.
|
|
45
|
+
*
|
|
46
|
+
* Word timings are source-media times, so the element must play at 1x (no
|
|
47
|
+
* timeMap). Interior and leading silences become split + rippleDelete (later
|
|
48
|
+
* clips on the track shift left — cutting leading silence replaces the
|
|
49
|
+
* element id with a fresh one); trailing silence becomes a trim. Cuts are
|
|
50
|
+
* applied last-to-first so earlier timeline positions stay valid throughout.
|
|
51
|
+
*/
|
|
52
|
+
declare function planSilenceCuts(project: Project, elementId: string, transcript: TranscriptResult, options?: SilenceCutOptions): SilenceCutPlan;
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/captions.d.ts
|
|
55
|
+
interface CaptionsCommandOptions {
|
|
56
|
+
/**
|
|
57
|
+
* Scope the transcript to one video/audio element: caption only the source
|
|
58
|
+
* span the clip actually plays, positioned at the clip's timeline location.
|
|
59
|
+
* Without it the transcript is applied from timeline 0.
|
|
60
|
+
*/
|
|
61
|
+
elementId?: string;
|
|
62
|
+
/** A preset id from CAPTION_STYLE_PRESETS (classic, karaoke, spotlight, ...). */
|
|
63
|
+
styleId?: string;
|
|
64
|
+
maxChars?: number;
|
|
65
|
+
maxGapMs?: number;
|
|
66
|
+
/** Clear existing captions on the target track first. */
|
|
67
|
+
replace?: boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build an `applyCaptions` command from a transcript, with element scoping
|
|
71
|
+
* and named style presets resolved. Dispatch the result (or hand it to an
|
|
72
|
+
* agent) — this does not mutate the project.
|
|
73
|
+
*/
|
|
74
|
+
declare function buildCaptionsCommand(project: Project, transcript: TranscriptResult, options?: CaptionsCommandOptions): AnyCommand;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/presets.d.ts
|
|
77
|
+
/**
|
|
78
|
+
* Platform delivery presets: the project geometry an agent (or human) should
|
|
79
|
+
* start from for a given destination. Data, not code — the skill's
|
|
80
|
+
* `platform-presets.json` asset and `mcut new --preset` both read this list.
|
|
81
|
+
*/
|
|
82
|
+
interface PlatformPreset {
|
|
83
|
+
id: string;
|
|
84
|
+
label: string;
|
|
85
|
+
width: number;
|
|
86
|
+
height: number;
|
|
87
|
+
fps: number;
|
|
88
|
+
/**
|
|
89
|
+
* Fractions of frame height covered by platform chrome (usernames,
|
|
90
|
+
* captions UI, action rails). Keep text and faces out of these bands.
|
|
91
|
+
*/
|
|
92
|
+
safeArea: {
|
|
93
|
+
top: number;
|
|
94
|
+
bottom: number;
|
|
95
|
+
};
|
|
96
|
+
notes: string;
|
|
97
|
+
}
|
|
98
|
+
declare const PLATFORM_PRESETS: PlatformPreset[];
|
|
99
|
+
declare function getPlatformPreset(id: string): PlatformPreset | undefined;
|
|
100
|
+
//#endregion
|
|
101
|
+
//#region src/io.d.ts
|
|
102
|
+
declare function readProjectFile(path: string): Promise<Project>;
|
|
103
|
+
declare function writeProjectFile(path: string, project: Project): Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Lenient validation for transcript JSON (providers normalize to
|
|
106
|
+
* TranscriptResult, but hand-made files often carry only `words`).
|
|
107
|
+
*/
|
|
108
|
+
declare const transcriptSchema: z.ZodObject<{
|
|
109
|
+
text: z.ZodDefault<z.ZodString>;
|
|
110
|
+
language: z.ZodOptional<z.ZodString>;
|
|
111
|
+
durationMs: z.ZodOptional<z.ZodNumber>;
|
|
112
|
+
words: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
113
|
+
text: z.ZodString;
|
|
114
|
+
startMs: z.ZodNumber;
|
|
115
|
+
endMs: z.ZodNumber;
|
|
116
|
+
confidence: z.ZodOptional<z.ZodNumber>;
|
|
117
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
118
|
+
}, z.core.$strip>>>;
|
|
119
|
+
segments: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
120
|
+
text: z.ZodString;
|
|
121
|
+
startMs: z.ZodNumber;
|
|
122
|
+
endMs: z.ZodNumber;
|
|
123
|
+
speaker: z.ZodOptional<z.ZodString>;
|
|
124
|
+
}, z.core.$strip>>>;
|
|
125
|
+
}, z.core.$strip>;
|
|
126
|
+
declare function readTranscriptFile(path: string): Promise<TranscriptResult>;
|
|
127
|
+
//#endregion
|
|
128
|
+
export { type CaptionsCommandOptions, type LintIssue, PLATFORM_PRESETS, type PlatformPreset, type SilenceCutOptions, type SilenceCutPlan, type SilenceWindow, buildCaptionsCommand, getPlatformPreset, lintProject, planSilenceCuts, readProjectFile, readTranscriptFile, transcriptSchema, writeProjectFile };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PLATFORM_PRESETS, c as planSilenceCuts, i as writeProjectFile, l as lintProject, n as readTranscriptFile, o as getPlatformPreset, r as transcriptSchema, s as buildCaptionsCommand, t as readProjectFile } from "./io-BcGV4lKK.js";
|
|
2
|
+
export { PLATFORM_PRESETS, buildCaptionsCommand, getPlatformPreset, lintProject, planSilenceCuts, readProjectFile, readTranscriptFile, transcriptSchema, writeProjectFile };
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { CAPTION_STYLE_PRESETS, EditorEngine, MIN_ELEMENT_DURATION_MS, createElementId, getElementLocation, getProjectDurationMs, parseProject } from "@mcut/timeline";
|
|
2
|
+
import { buildApplyCaptionsCommand } from "@mcut/transcription";
|
|
3
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/lint.ts
|
|
6
|
+
function lintProject(project) {
|
|
7
|
+
const issues = [];
|
|
8
|
+
const error = (code, message) => issues.push({
|
|
9
|
+
severity: "error",
|
|
10
|
+
code,
|
|
11
|
+
message
|
|
12
|
+
});
|
|
13
|
+
const warn = (code, message) => issues.push({
|
|
14
|
+
severity: "warning",
|
|
15
|
+
code,
|
|
16
|
+
message
|
|
17
|
+
});
|
|
18
|
+
const linkCounts = /* @__PURE__ */ new Map();
|
|
19
|
+
for (const track of project.tracks) {
|
|
20
|
+
if (track.elements.length === 0) warn("empty-track", `track "${track.name}" (${track.id}) has no elements`);
|
|
21
|
+
const sorted = [...track.elements].sort((a, b) => a.startMs - b.startMs);
|
|
22
|
+
for (let i = 0; i < sorted.length; i++) {
|
|
23
|
+
const element = sorted[i];
|
|
24
|
+
const next = sorted[i + 1];
|
|
25
|
+
if (next && next.startMs < element.startMs + element.durationMs) error("overlap", `elements "${element.id}" and "${next.id}" overlap on track "${track.name}" (${element.startMs}–${element.startMs + element.durationMs}ms vs ${next.startMs}ms)`);
|
|
26
|
+
lintElement(project, track, element, sorted, i, {
|
|
27
|
+
error,
|
|
28
|
+
warn
|
|
29
|
+
});
|
|
30
|
+
if (element.linkId) linkCounts.set(element.linkId, (linkCounts.get(element.linkId) ?? 0) + 1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
for (const [linkId, count] of linkCounts) if (count < 2) warn("broken-link", `linkId "${linkId}" is held by a single element (its partner was removed)`);
|
|
34
|
+
if (getProjectDurationMs(project) === 0) warn("empty-project", "project has no content (duration 0ms)");
|
|
35
|
+
return issues;
|
|
36
|
+
}
|
|
37
|
+
function lintElement(project, track, element, sorted, index, { error, warn }) {
|
|
38
|
+
if ("assetId" in element && !project.assets[element.assetId]) error("missing-asset", `element "${element.id}" references missing asset "${element.assetId}"`);
|
|
39
|
+
if ("keyframes" in element && element.keyframes) {
|
|
40
|
+
for (const [property, keyframes] of Object.entries(element.keyframes)) for (const keyframe of keyframes ?? []) if (keyframe.timeMs > element.durationMs) warn("keyframe-out-of-range", `element "${element.id}" has a ${property} keyframe at ${keyframe.timeMs}ms, beyond its ${element.durationMs}ms duration (it will never be reached)`);
|
|
41
|
+
}
|
|
42
|
+
if ("transition" in element && element.transition) {
|
|
43
|
+
const next = sorted[index + 1];
|
|
44
|
+
if (!next || next.startMs !== element.startMs + element.durationMs) warn("transition-without-neighbor", `element "${element.id}" has a transition but no exactly-adjacent next clip on track "${track.name}" (transitions need a butt cut)`);
|
|
45
|
+
}
|
|
46
|
+
if (element.type === "caption" && element.text.trim() === "") warn("empty-caption", `caption "${element.id}" has no text`);
|
|
47
|
+
if (element.type === "multicam") {
|
|
48
|
+
if (element.angles.length === 0 || element.angles[0].atMs !== 0) error("multicam-first-angle", `multicam "${element.id}" must have an angle cut at 0ms`);
|
|
49
|
+
for (const angle of element.angles) {
|
|
50
|
+
if (!project.layouts.some((layout) => layout.id === angle.layoutId)) error("missing-layout", `multicam "${element.id}" cuts to unknown layout "${angle.layoutId}" at ${angle.atMs}ms`);
|
|
51
|
+
if (angle.atMs >= element.durationMs) warn("angle-beyond-end", `multicam "${element.id}" has an angle cut at ${angle.atMs}ms, at or beyond its ${element.durationMs}ms duration`);
|
|
52
|
+
}
|
|
53
|
+
for (const source of element.sources) if (!project.assets[source.assetId]) error("missing-asset", `multicam "${element.id}" source "${source.key}" references missing asset "${source.assetId}"`);
|
|
54
|
+
if (element.audioSource !== void 0 && !element.sources.some((source) => source.key === element.audioSource)) error("missing-audio-source", `multicam "${element.id}" plays audio from unknown source "${element.audioSource}"`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/silence.ts
|
|
59
|
+
/**
|
|
60
|
+
* Plan and apply silence cuts on one video/audio element from its transcript.
|
|
61
|
+
*
|
|
62
|
+
* Word timings are source-media times, so the element must play at 1x (no
|
|
63
|
+
* timeMap). Interior and leading silences become split + rippleDelete (later
|
|
64
|
+
* clips on the track shift left — cutting leading silence replaces the
|
|
65
|
+
* element id with a fresh one); trailing silence becomes a trim. Cuts are
|
|
66
|
+
* applied last-to-first so earlier timeline positions stay valid throughout.
|
|
67
|
+
*/
|
|
68
|
+
function planSilenceCuts(project, elementId, transcript, options = {}) {
|
|
69
|
+
const minGapMs = options.minGapMs ?? 600;
|
|
70
|
+
const paddingMs = options.paddingMs ?? 120;
|
|
71
|
+
const minKeepMs = Math.max(options.minKeepMs ?? 250, MIN_ELEMENT_DURATION_MS);
|
|
72
|
+
const trimEnds = options.trimEnds ?? true;
|
|
73
|
+
const location = getElementLocation(project, elementId);
|
|
74
|
+
if (!location) throw new Error(`no element "${elementId}" in project`);
|
|
75
|
+
const element = location.element;
|
|
76
|
+
if (element.type !== "video" && element.type !== "audio") throw new Error(`silence cuts apply to video/audio elements, not "${element.type}"`);
|
|
77
|
+
if (element.timeMap) throw new Error(`element "${elementId}" has a time remap; silence cuts require 1x playback (clear it with setTimeMap null first)`);
|
|
78
|
+
const windowStart = element.trimStartMs;
|
|
79
|
+
const windowEnd = element.trimStartMs + element.durationMs;
|
|
80
|
+
const words = transcript.words.filter((word) => word.endMs > windowStart && word.startMs < windowEnd).sort((a, b) => a.startMs - b.startMs);
|
|
81
|
+
if (words.length === 0) throw new Error(`transcript has no words inside the element's source window (${windowStart}–${windowEnd}ms) — cutting everything is never what you want`);
|
|
82
|
+
const silences = findSilences(words, windowStart, windowEnd, {
|
|
83
|
+
minGapMs,
|
|
84
|
+
paddingMs,
|
|
85
|
+
minKeepMs,
|
|
86
|
+
trimEnds
|
|
87
|
+
});
|
|
88
|
+
const engine = new EditorEngine({ project });
|
|
89
|
+
const commands = [];
|
|
90
|
+
const dispatch = (command) => {
|
|
91
|
+
engine.dispatch(command);
|
|
92
|
+
commands.push(command);
|
|
93
|
+
};
|
|
94
|
+
const current = () => {
|
|
95
|
+
const found = getElementLocation(engine.project, elementId);
|
|
96
|
+
if (!found || found.element.type !== "video" && found.element.type !== "audio") throw new Error(`element "${elementId}" disappeared mid-plan`);
|
|
97
|
+
return found.element;
|
|
98
|
+
};
|
|
99
|
+
for (const silence of [...silences].reverse()) {
|
|
100
|
+
const el = current();
|
|
101
|
+
const toTimeline = (sourceMs) => el.startMs + (sourceMs - el.trimStartMs);
|
|
102
|
+
if (silence.endMs >= windowEnd) dispatch({
|
|
103
|
+
type: "trimElement",
|
|
104
|
+
elementId,
|
|
105
|
+
durationMs: toTimeline(silence.startMs) - el.startMs
|
|
106
|
+
});
|
|
107
|
+
else if (silence.startMs <= windowStart) {
|
|
108
|
+
dispatch({
|
|
109
|
+
type: "splitElement",
|
|
110
|
+
elementId,
|
|
111
|
+
atMs: toTimeline(silence.endMs),
|
|
112
|
+
rightElementId: createElementId()
|
|
113
|
+
});
|
|
114
|
+
dispatch({
|
|
115
|
+
type: "rippleDelete",
|
|
116
|
+
elementIds: [elementId]
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
dispatch({
|
|
120
|
+
type: "splitElement",
|
|
121
|
+
elementId,
|
|
122
|
+
atMs: toTimeline(silence.endMs)
|
|
123
|
+
});
|
|
124
|
+
dispatch({
|
|
125
|
+
type: "splitElement",
|
|
126
|
+
elementId,
|
|
127
|
+
atMs: toTimeline(silence.startMs)
|
|
128
|
+
});
|
|
129
|
+
const middle = engine.project.tracks.find((t) => t.elements.some((e) => e.id === elementId)).elements.find((e) => e.id !== elementId && e.startMs === toTimeline(silence.startMs));
|
|
130
|
+
if (!middle) throw new Error(`lost the silence chunk at ${silence.startMs}ms after splitting`);
|
|
131
|
+
dispatch({
|
|
132
|
+
type: "rippleDelete",
|
|
133
|
+
elementIds: [middle.id]
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
silences,
|
|
139
|
+
commands,
|
|
140
|
+
removedMs: silences.reduce((sum, s) => sum + (s.endMs - s.startMs), 0),
|
|
141
|
+
project: engine.project
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function findSilences(words, windowStart, windowEnd, { minGapMs, paddingMs, minKeepMs, trimEnds }) {
|
|
145
|
+
const raw = [];
|
|
146
|
+
const first = words[0];
|
|
147
|
+
if (trimEnds && first.startMs - windowStart > minGapMs) raw.push({
|
|
148
|
+
startMs: windowStart,
|
|
149
|
+
endMs: first.startMs - paddingMs
|
|
150
|
+
});
|
|
151
|
+
for (let i = 0; i < words.length - 1; i++) {
|
|
152
|
+
const gapStart = words[i].endMs;
|
|
153
|
+
const gapEnd = words[i + 1].startMs;
|
|
154
|
+
if (gapEnd - gapStart > minGapMs) raw.push({
|
|
155
|
+
startMs: gapStart + paddingMs,
|
|
156
|
+
endMs: gapEnd - paddingMs
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
const last = words[words.length - 1];
|
|
160
|
+
if (trimEnds && windowEnd - last.endMs > minGapMs) raw.push({
|
|
161
|
+
startMs: last.endMs + paddingMs,
|
|
162
|
+
endMs: windowEnd
|
|
163
|
+
});
|
|
164
|
+
const clamped = raw.map((s) => ({
|
|
165
|
+
startMs: Math.round(Math.max(s.startMs, windowStart)),
|
|
166
|
+
endMs: Math.round(Math.min(s.endMs, windowEnd))
|
|
167
|
+
})).filter((s) => s.endMs - s.startMs >= MIN_ELEMENT_DURATION_MS);
|
|
168
|
+
const merged = [];
|
|
169
|
+
for (const silence of clamped) {
|
|
170
|
+
const previous = merged[merged.length - 1];
|
|
171
|
+
if (previous && silence.startMs - previous.endMs < minKeepMs) previous.endMs = silence.endMs;
|
|
172
|
+
else merged.push({ ...silence });
|
|
173
|
+
}
|
|
174
|
+
if (merged.some((s) => s.startMs <= windowStart && s.endMs >= windowEnd)) throw new Error("silence cut would remove the entire element — check the transcript timing");
|
|
175
|
+
return merged;
|
|
176
|
+
}
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region src/captions.ts
|
|
179
|
+
/**
|
|
180
|
+
* Build an `applyCaptions` command from a transcript, with element scoping
|
|
181
|
+
* and named style presets resolved. Dispatch the result (or hand it to an
|
|
182
|
+
* agent) — this does not mutate the project.
|
|
183
|
+
*/
|
|
184
|
+
function buildCaptionsCommand(project, transcript, options = {}) {
|
|
185
|
+
let style;
|
|
186
|
+
if (options.styleId) {
|
|
187
|
+
const preset = CAPTION_STYLE_PRESETS.find((p) => p.id === options.styleId);
|
|
188
|
+
if (!preset) {
|
|
189
|
+
const known = CAPTION_STYLE_PRESETS.map((p) => p.id).join(", ");
|
|
190
|
+
throw new Error(`unknown caption style "${options.styleId}" (known: ${known})`);
|
|
191
|
+
}
|
|
192
|
+
style = preset.style;
|
|
193
|
+
}
|
|
194
|
+
let scope = {};
|
|
195
|
+
if (options.elementId) {
|
|
196
|
+
const location = getElementLocation(project, options.elementId);
|
|
197
|
+
if (!location) throw new Error(`no element "${options.elementId}" in project`);
|
|
198
|
+
const element = location.element;
|
|
199
|
+
if (element.type !== "video" && element.type !== "audio") throw new Error(`captions scope to video/audio elements, not "${element.type}"`);
|
|
200
|
+
if (element.timeMap) throw new Error(`element "${options.elementId}" has a time remap; transcript times will not line up`);
|
|
201
|
+
scope = {
|
|
202
|
+
timeOffsetMs: element.startMs,
|
|
203
|
+
sourceStartMs: element.trimStartMs,
|
|
204
|
+
sourceEndMs: element.trimStartMs + element.durationMs
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
return buildApplyCaptionsCommand(transcript, {
|
|
208
|
+
...scope,
|
|
209
|
+
...style ? { style } : {},
|
|
210
|
+
...options.maxChars !== void 0 ? { maxChars: options.maxChars } : {},
|
|
211
|
+
...options.maxGapMs !== void 0 ? { maxGapMs: options.maxGapMs } : {},
|
|
212
|
+
...options.replace !== void 0 ? { replace: options.replace } : {}
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
//#endregion
|
|
216
|
+
//#region src/presets.ts
|
|
217
|
+
const PLATFORM_PRESETS = [
|
|
218
|
+
{
|
|
219
|
+
id: "youtube",
|
|
220
|
+
label: "YouTube (16:9)",
|
|
221
|
+
width: 1920,
|
|
222
|
+
height: 1080,
|
|
223
|
+
fps: 30,
|
|
224
|
+
safeArea: {
|
|
225
|
+
top: 0,
|
|
226
|
+
bottom: .08
|
|
227
|
+
},
|
|
228
|
+
notes: "Standard horizontal video. The bottom ~8% is covered by the scrubber on hover; avoid parking captions or lower thirds at the very bottom edge."
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
id: "youtube-4k",
|
|
232
|
+
label: "YouTube 4K (16:9)",
|
|
233
|
+
width: 3840,
|
|
234
|
+
height: 2160,
|
|
235
|
+
fps: 30,
|
|
236
|
+
safeArea: {
|
|
237
|
+
top: 0,
|
|
238
|
+
bottom: .08
|
|
239
|
+
},
|
|
240
|
+
notes: "As youtube, at UHD. Use for screen-recording-heavy content where text must stay crisp."
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: "shorts",
|
|
244
|
+
label: "YouTube Shorts (9:16)",
|
|
245
|
+
width: 1080,
|
|
246
|
+
height: 1920,
|
|
247
|
+
fps: 30,
|
|
248
|
+
safeArea: {
|
|
249
|
+
top: .1,
|
|
250
|
+
bottom: .25
|
|
251
|
+
},
|
|
252
|
+
notes: "Vertical, 60s max (3min allowed, 60s favored). Title/channel chrome overlays the top 10%; like/comment rail and description cover the bottom 25%. Center captions in the middle band."
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
id: "tiktok",
|
|
256
|
+
label: "TikTok (9:16)",
|
|
257
|
+
width: 1080,
|
|
258
|
+
height: 1920,
|
|
259
|
+
fps: 30,
|
|
260
|
+
safeArea: {
|
|
261
|
+
top: .1,
|
|
262
|
+
bottom: .25
|
|
263
|
+
},
|
|
264
|
+
notes: "Vertical. Hook in the first 1–2s; 21–34s is the engagement sweet spot. Keep captions and faces inside the middle band — the right rail and bottom description bar overlap the frame."
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
id: "reels",
|
|
268
|
+
label: "Instagram Reels (9:16)",
|
|
269
|
+
width: 1080,
|
|
270
|
+
height: 1920,
|
|
271
|
+
fps: 30,
|
|
272
|
+
safeArea: {
|
|
273
|
+
top: .1,
|
|
274
|
+
bottom: .25
|
|
275
|
+
},
|
|
276
|
+
notes: "Vertical, 90s max. The feed crops a 4:5 preview from the center — keep the subject centered vertically so the crop still works."
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
id: "square",
|
|
280
|
+
label: "Square (1:1)",
|
|
281
|
+
width: 1080,
|
|
282
|
+
height: 1080,
|
|
283
|
+
fps: 30,
|
|
284
|
+
safeArea: {
|
|
285
|
+
top: 0,
|
|
286
|
+
bottom: .1
|
|
287
|
+
},
|
|
288
|
+
notes: "Feed-neutral square. Works on LinkedIn and X timelines without cropping."
|
|
289
|
+
}
|
|
290
|
+
];
|
|
291
|
+
function getPlatformPreset(id) {
|
|
292
|
+
return PLATFORM_PRESETS.find((preset) => preset.id === id);
|
|
293
|
+
}
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/io.ts
|
|
296
|
+
async function readProjectFile(path) {
|
|
297
|
+
return parseProject(JSON.parse(await readFile(path, "utf8")));
|
|
298
|
+
}
|
|
299
|
+
async function writeProjectFile(path, project) {
|
|
300
|
+
await writeFile(path, `${JSON.stringify(project, null, 2)}\n`, "utf8");
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Lenient validation for transcript JSON (providers normalize to
|
|
304
|
+
* TranscriptResult, but hand-made files often carry only `words`).
|
|
305
|
+
*/
|
|
306
|
+
const transcriptSchema = z.object({
|
|
307
|
+
text: z.string().default(""),
|
|
308
|
+
language: z.string().optional(),
|
|
309
|
+
durationMs: z.number().optional(),
|
|
310
|
+
words: z.array(z.object({
|
|
311
|
+
text: z.string(),
|
|
312
|
+
startMs: z.number(),
|
|
313
|
+
endMs: z.number(),
|
|
314
|
+
confidence: z.number().optional(),
|
|
315
|
+
speaker: z.string().optional()
|
|
316
|
+
})).default([]),
|
|
317
|
+
segments: z.array(z.object({
|
|
318
|
+
text: z.string(),
|
|
319
|
+
startMs: z.number(),
|
|
320
|
+
endMs: z.number(),
|
|
321
|
+
speaker: z.string().optional()
|
|
322
|
+
})).default([])
|
|
323
|
+
});
|
|
324
|
+
async function readTranscriptFile(path) {
|
|
325
|
+
return transcriptSchema.parse(JSON.parse(await readFile(path, "utf8")));
|
|
326
|
+
}
|
|
327
|
+
//#endregion
|
|
328
|
+
export { PLATFORM_PRESETS as a, planSilenceCuts as c, writeProjectFile as i, lintProject as l, readTranscriptFile as n, getPlatformPreset as o, transcriptSchema as r, buildCaptionsCommand as s, readProjectFile as t };
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mcut/cli",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "mcut on the command line: scaffold, validate, summarize, and batch-edit project documents headlessly",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"mcut": "./dist/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./cli": {
|
|
18
|
+
"types": "./dist/cli.d.ts",
|
|
19
|
+
"import": "./dist/cli.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "tsdown",
|
|
28
|
+
"dev": "tsdown --watch --no-clean",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"test": "bun test"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "https://github.com/mattppal/mcut.git",
|
|
35
|
+
"directory": "packages/cli"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public",
|
|
39
|
+
"provenance": true
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@mcut/timeline": "0.1.0-alpha.0",
|
|
43
|
+
"@mcut/transcription": "0.1.0-alpha.0",
|
|
44
|
+
"zod": "4.4.3"
|
|
45
|
+
},
|
|
46
|
+
"author": "Matt Palmer",
|
|
47
|
+
"homepage": "https://github.com/mattppal/mcut/tree/main/packages/cli#readme",
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/mattppal/mcut/issues"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"mcut",
|
|
53
|
+
"video",
|
|
54
|
+
"video-editing",
|
|
55
|
+
"timeline",
|
|
56
|
+
"typescript",
|
|
57
|
+
"cli",
|
|
58
|
+
"headless"
|
|
59
|
+
],
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=20.11"
|
|
62
|
+
}
|
|
63
|
+
}
|