capcut-cli 0.1.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 +21 -0
- package/README.md +220 -0
- package/dist/draft.js +116 -0
- package/dist/factory.js +370 -0
- package/dist/index.js +705 -0
- package/dist/time.js +74 -0
- package/package.json +41 -0
package/dist/time.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
const US_PER_SEC = 1_000_000;
|
|
2
|
+
const US_PER_MS = 1_000;
|
|
3
|
+
export function usToSeconds(us) {
|
|
4
|
+
return us / US_PER_SEC;
|
|
5
|
+
}
|
|
6
|
+
export function secondsToUs(s) {
|
|
7
|
+
return Math.round(s * US_PER_SEC);
|
|
8
|
+
}
|
|
9
|
+
export function formatTime(us) {
|
|
10
|
+
const totalSec = us / US_PER_SEC;
|
|
11
|
+
const h = Math.floor(totalSec / 3600);
|
|
12
|
+
const m = Math.floor((totalSec % 3600) / 60);
|
|
13
|
+
const s = totalSec % 60;
|
|
14
|
+
if (h > 0)
|
|
15
|
+
return `${h}:${pad(m)}:${pad2(s)}`;
|
|
16
|
+
return `${m}:${pad2(s)}`;
|
|
17
|
+
}
|
|
18
|
+
export function formatDuration(us) {
|
|
19
|
+
const s = us / US_PER_SEC;
|
|
20
|
+
if (s < 1)
|
|
21
|
+
return `${(us / US_PER_MS).toFixed(0)}ms`;
|
|
22
|
+
if (s < 60)
|
|
23
|
+
return `${s.toFixed(2)}s`;
|
|
24
|
+
const m = Math.floor(s / 60);
|
|
25
|
+
const rem = s % 60;
|
|
26
|
+
return `${m}m${rem.toFixed(1)}s`;
|
|
27
|
+
}
|
|
28
|
+
export function parseTimeInput(input) {
|
|
29
|
+
// "+0.5s", "-1s", "1.5s", "+500ms", "1:30", "0:05.5"
|
|
30
|
+
const negative = input.startsWith("-");
|
|
31
|
+
const clean = input.replace(/^[+-]/, "");
|
|
32
|
+
if (clean.endsWith("ms")) {
|
|
33
|
+
const val = parseFloat(clean.replace("ms", ""));
|
|
34
|
+
return (negative ? -1 : 1) * Math.round(val * US_PER_MS);
|
|
35
|
+
}
|
|
36
|
+
if (clean.endsWith("s")) {
|
|
37
|
+
const val = parseFloat(clean.replace("s", ""));
|
|
38
|
+
return (negative ? -1 : 1) * secondsToUs(val);
|
|
39
|
+
}
|
|
40
|
+
if (clean.includes(":")) {
|
|
41
|
+
const parts = clean.split(":");
|
|
42
|
+
let totalSec = 0;
|
|
43
|
+
if (parts.length === 3) {
|
|
44
|
+
totalSec = parseInt(parts[0]) * 3600 + parseInt(parts[1]) * 60 + parseFloat(parts[2]);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
totalSec = parseInt(parts[0]) * 60 + parseFloat(parts[1]);
|
|
48
|
+
}
|
|
49
|
+
return (negative ? -1 : 1) * secondsToUs(totalSec);
|
|
50
|
+
}
|
|
51
|
+
// bare number = seconds
|
|
52
|
+
const val = parseFloat(clean);
|
|
53
|
+
if (isNaN(val))
|
|
54
|
+
throw new Error(`Invalid time: ${input}`);
|
|
55
|
+
return (negative ? -1 : 1) * secondsToUs(val);
|
|
56
|
+
}
|
|
57
|
+
function pad(n) {
|
|
58
|
+
return n.toString().padStart(2, "0");
|
|
59
|
+
}
|
|
60
|
+
function pad2(n) {
|
|
61
|
+
const whole = Math.floor(n);
|
|
62
|
+
const frac = n - whole;
|
|
63
|
+
if (frac === 0)
|
|
64
|
+
return whole.toString().padStart(2, "0");
|
|
65
|
+
return (whole + frac).toFixed(2).padStart(5, "0");
|
|
66
|
+
}
|
|
67
|
+
export function srtTime(us) {
|
|
68
|
+
const totalSec = us / US_PER_SEC;
|
|
69
|
+
const h = Math.floor(totalSec / 3600);
|
|
70
|
+
const m = Math.floor((totalSec % 3600) / 60);
|
|
71
|
+
const s = Math.floor(totalSec % 60);
|
|
72
|
+
const ms = Math.round((totalSec % 1) * 1000);
|
|
73
|
+
return `${pad(h)}:${pad(m)}:${pad(s)},${ms.toString().padStart(3, "0")}`;
|
|
74
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "capcut-cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Fast CLI for editing CapCut projects. Edit text, timing, speed, and volume in seconds instead of minutes.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"capcut": "./dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"prepublishOnly": "tsc",
|
|
17
|
+
"dev": "node --import tsx src/index.ts"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"capcut",
|
|
21
|
+
"video-editing",
|
|
22
|
+
"cli",
|
|
23
|
+
"draft_content",
|
|
24
|
+
"automation",
|
|
25
|
+
"batch-edit"
|
|
26
|
+
],
|
|
27
|
+
"author": "René Zander",
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/renezander030/capcut-cli.git"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/node": "^25.6.0",
|
|
38
|
+
"tsx": "^4.0.0",
|
|
39
|
+
"typescript": "^5.5.0"
|
|
40
|
+
}
|
|
41
|
+
}
|