@clipen/clipen-cli 1.0.6 → 1.0.8
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.md +5 -4
- package/apps/web/dist/assets/{index-CaxEZKLc.css → index-CJ80KHsQ.css} +1 -1
- package/apps/web/dist/assets/index-C_4u_hVf.js +16 -0
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +237 -78
- package/package.json +8 -2
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/qwen_worker.py +13 -4
- package/src/clipen/analysis/setup.py +26 -1
- package/src/clipen/analysis/setup_cli.py +59 -10
- package/src/clipen/bootstrap.py +411 -176
- package/src/clipen/cli.py +40 -15
- package/src/clipen/controller/app.py +37 -17
- package/src/clipen/controller/server.py +65 -27
- package/src/clipen/editing/agent_repository.py +8 -0
- package/src/clipen/editing/alignment_setup.py +40 -15
- package/src/clipen/editing/change_report.py +17 -0
- package/src/clipen/editing/coordinator.py +6 -0
- package/src/clipen/editing/evidence_jobs.py +3 -1
- package/src/clipen/editing/history_changes.py +56 -27
- package/src/clipen/editing/production_catalog.py +3 -3
- package/src/clipen/editing/production_media.py +18 -0
- package/src/clipen/editing/production_progress.py +46 -3
- package/src/clipen/editing/production_tools.py +3 -1
- package/src/clipen/editing/versions.py +53 -10
- package/src/clipen/finishing/audio.py +59 -45
- package/src/clipen/i18n.py +155 -0
- package/src/clipen/locale_en.py +528 -0
- package/src/clipen/mcp_editing/__main__.py +8 -0
- package/src/clipen/own_python.py +43 -0
- package/src/clipen/projects/models.py +16 -1
- package/src/clipen/projects/picker.py +3 -1
- package/src/clipen/projects/storage.py +17 -1
- package/src/clipen/providers/claude_editing.py +3 -1
- package/src/clipen/providers/codex_editing.py +3 -1
- package/src/clipen/providers/editing_agent.py +36 -1
- package/src/clipen/providers/liveness.py +39 -0
- package/src/clipen/rendering/custom_components.py +104 -2
- package/src/clipen/rendering/custom_render.py +45 -0
- package/src/clipen/skills/builtin/display.en.json +89 -0
- package/src/clipen/skills/builtin/references/graphics.md +1 -2
- package/src/clipen/skills/catalog.py +22 -0
- package/src/clipen/terminal.py +344 -0
- package/src/clipen/workspace.py +97 -28
- package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
|
@@ -17,9 +17,20 @@ class ProjectError(RuntimeError):
|
|
|
17
17
|
def __init__(self, code: str, message: str, *, status_code: int = 400) -> None:
|
|
18
18
|
super().__init__(message)
|
|
19
19
|
self.code = code
|
|
20
|
-
self.
|
|
20
|
+
self._message = message
|
|
21
21
|
self.status_code = status_code
|
|
22
22
|
|
|
23
|
+
@property
|
|
24
|
+
def message(self) -> str:
|
|
25
|
+
"""The message in the language of whoever reads it now: the request, or the AI's attempt."""
|
|
26
|
+
from clipen.i18n import tr
|
|
27
|
+
|
|
28
|
+
return tr(self._message)
|
|
29
|
+
|
|
30
|
+
@message.setter
|
|
31
|
+
def message(self, value: str) -> None:
|
|
32
|
+
self._message = value
|
|
33
|
+
|
|
23
34
|
|
|
24
35
|
class DirectoryRole(str, Enum):
|
|
25
36
|
SOURCE = "source"
|
|
@@ -135,6 +146,9 @@ class ProjectSnapshot:
|
|
|
135
146
|
updated_at: str
|
|
136
147
|
directories: tuple[DirectoryReference, ...] = ()
|
|
137
148
|
last_activity_at: str | None = field(default=None, compare=False)
|
|
149
|
+
# Where the project stands, for its card on the home page: whether its footage was checked and
|
|
150
|
+
# how its latest AI production ended. Derived when listing; never stored.
|
|
151
|
+
standing: Mapping[str, object] | None = field(default=None, compare=False)
|
|
138
152
|
|
|
139
153
|
def __post_init__(self) -> None:
|
|
140
154
|
validate_project_id(self.project_id)
|
|
@@ -170,6 +184,7 @@ class ProjectSnapshot:
|
|
|
170
184
|
"updated_at": self.updated_at,
|
|
171
185
|
"last_activity_at": self.last_activity_at or self.updated_at,
|
|
172
186
|
"directories": [reference.to_public() for reference in self.directories],
|
|
187
|
+
**({"standing": dict(self.standing)} if self.standing is not None else {}),
|
|
173
188
|
}
|
|
174
189
|
|
|
175
190
|
@classmethod
|
|
@@ -43,7 +43,9 @@ class MacOSDirectoryPicker(NativeDirectoryPicker):
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
def choose(self, role: DirectoryRole) -> Path | None:
|
|
46
|
-
|
|
46
|
+
from clipen.i18n import tr
|
|
47
|
+
|
|
48
|
+
return self.choose_folder(tr(self._PROMPTS[role]))
|
|
47
49
|
|
|
48
50
|
def choose_folder(self, prompt: str) -> Path | None:
|
|
49
51
|
if sys.platform != "darwin":
|
|
@@ -365,7 +365,23 @@ class ProjectRepository:
|
|
|
365
365
|
UNION ALL SELECT MAX(created_at) FROM inventory_runs
|
|
366
366
|
UNION ALL SELECT MAX(completed_at) FROM preview_renders
|
|
367
367
|
)""").fetchone()[0]
|
|
368
|
-
|
|
368
|
+
checked = (
|
|
369
|
+
db.execute("SELECT 1 FROM inventory_runs WHERE state='succeeded' LIMIT 1").fetchone() is not None
|
|
370
|
+
)
|
|
371
|
+
run = db.execute(
|
|
372
|
+
"SELECT state,error_code FROM edit_agent_runs ORDER BY created_at DESC,rowid DESC LIMIT 1"
|
|
373
|
+
).fetchone()
|
|
374
|
+
standing = {
|
|
375
|
+
"footage_checked": checked,
|
|
376
|
+
"production": None if run is None else {"state": run["state"], "error_code": run["error_code"]},
|
|
377
|
+
}
|
|
378
|
+
projects.append(
|
|
379
|
+
replace(
|
|
380
|
+
project,
|
|
381
|
+
last_activity_at=max(project.updated_at, activity or project.updated_at),
|
|
382
|
+
standing=standing,
|
|
383
|
+
)
|
|
384
|
+
)
|
|
369
385
|
projects.sort(key=lambda project: project.last_activity_at or project.updated_at, reverse=True)
|
|
370
386
|
return tuple(projects)
|
|
371
387
|
|
|
@@ -48,7 +48,9 @@ class ClaudeEditingAgent(BoundedEditingAgent):
|
|
|
48
48
|
server = {
|
|
49
49
|
"type": "stdio",
|
|
50
50
|
"command": str(self.python),
|
|
51
|
-
"args": mcp_server_arguments(
|
|
51
|
+
"args": mcp_server_arguments(
|
|
52
|
+
self.projects_root, project_id, run_id, self.local_runtime, getattr(self, "_language", "zh-TW")
|
|
53
|
+
),
|
|
52
54
|
}
|
|
53
55
|
return (
|
|
54
56
|
str(self.binary),
|
|
@@ -47,7 +47,9 @@ class CodexEditingAgent(BoundedEditingAgent):
|
|
|
47
47
|
workspace: Path,
|
|
48
48
|
output_path: Path,
|
|
49
49
|
) -> tuple[str, ...]:
|
|
50
|
-
args = mcp_server_arguments(
|
|
50
|
+
args = mcp_server_arguments(
|
|
51
|
+
self.projects_root, project_id, run_id, self.local_runtime, getattr(self, "_language", "zh-TW")
|
|
52
|
+
)
|
|
51
53
|
return (
|
|
52
54
|
str(self.binary),
|
|
53
55
|
"--ask-for-approval",
|
|
@@ -22,6 +22,7 @@ from typing import Mapping
|
|
|
22
22
|
|
|
23
23
|
from clipen.editing.agent import AgentRun, EditAgentRepository
|
|
24
24
|
from clipen.editing.production_catalog import AGENT_NAMES
|
|
25
|
+
from clipen.providers import liveness
|
|
25
26
|
from clipen.providers.recovery import ProviderUsage
|
|
26
27
|
|
|
27
28
|
from .errors import (
|
|
@@ -140,6 +141,32 @@ for rendering, inspection and finish_edit; report concrete incomplete work if bl
|
|
|
140
141
|
The person reads Traditional Chinese: write the change report and your closing message
|
|
141
142
|
in Traditional Chinese, whatever language these instructions use.
|
|
142
143
|
"""
|
|
144
|
+
_ENGLISH = (
|
|
145
|
+
(
|
|
146
|
+
"The person reads Traditional Chinese: write the change report and your closing message\n"
|
|
147
|
+
"in Traditional Chinese, whatever language these instructions use.",
|
|
148
|
+
"The person reads English: write the change report and your closing message in English.\n"
|
|
149
|
+
"Write titles, chapter cards, labels and other on-screen text in English too, whatever\n"
|
|
150
|
+
"language the skill's defaults or examples use; captions keep the language that was spoken.",
|
|
151
|
+
),
|
|
152
|
+
(
|
|
153
|
+
"The person reads Traditional Chinese: write the change report, every reply to a note and\n"
|
|
154
|
+
"your closing message in Traditional Chinese, whatever language these instructions use.",
|
|
155
|
+
"The person reads English: write the change report, every reply to a note and your\n"
|
|
156
|
+
"closing message in English. Write new on-screen text in English, whatever language the\n"
|
|
157
|
+
"skill's defaults or examples use; captions keep the language that was spoken.",
|
|
158
|
+
),
|
|
159
|
+
("Correct subtitles faithfully in Traditional Chinese.", "Correct subtitles faithfully in the language spoken."),
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _in_english(prompt):
|
|
164
|
+
"""The prompt for a person who reads English: only the lines about language change."""
|
|
165
|
+
for chinese, english in _ENGLISH:
|
|
166
|
+
prompt = prompt.replace(chinese, english)
|
|
167
|
+
return prompt
|
|
168
|
+
|
|
169
|
+
|
|
143
170
|
_MCP_TOOLS = (
|
|
144
171
|
"get_edit_status",
|
|
145
172
|
"search_media",
|
|
@@ -282,8 +309,9 @@ def mcp_server_arguments(
|
|
|
282
309
|
project_id: str,
|
|
283
310
|
run_id: str,
|
|
284
311
|
local_runtime: tuple[Path, Path] | None,
|
|
312
|
+
language: str = "zh-TW",
|
|
285
313
|
) -> list[str]:
|
|
286
|
-
"""Arguments that start the Clipen MCP server bound to one edit run."""
|
|
314
|
+
"""Arguments that start the Clipen MCP server bound to one edit run, speaking the run's language."""
|
|
287
315
|
args = [
|
|
288
316
|
"-m",
|
|
289
317
|
"clipen.mcp_editing",
|
|
@@ -296,6 +324,8 @@ def mcp_server_arguments(
|
|
|
296
324
|
]
|
|
297
325
|
if local_runtime:
|
|
298
326
|
args += ["--data-root", str(local_runtime[0]), "--asr-requirements", str(local_runtime[1])]
|
|
327
|
+
if language != "zh-TW":
|
|
328
|
+
args += ["--language", language]
|
|
299
329
|
return args
|
|
300
330
|
|
|
301
331
|
|
|
@@ -398,6 +428,9 @@ class BoundedEditingAgent:
|
|
|
398
428
|
raise ValueError("editing timeout must be between 30 and 14400 seconds")
|
|
399
429
|
run = self.repository.get(project_id, run_id)
|
|
400
430
|
self._prompt = _PRODUCTION_PROMPT if session else _PROMPT
|
|
431
|
+
self._language = (session or {}).get("intent", {}).get("language", "zh-TW")
|
|
432
|
+
if self._language == "en":
|
|
433
|
+
self._prompt = _in_english(self._prompt)
|
|
401
434
|
if run.provider != self.provider_id:
|
|
402
435
|
raise ValueError("editing run belongs to another provider")
|
|
403
436
|
attempt_id = "agent-" + uuid.uuid4().hex
|
|
@@ -412,8 +445,10 @@ class BoundedEditingAgent:
|
|
|
412
445
|
self._slept = []
|
|
413
446
|
try:
|
|
414
447
|
try:
|
|
448
|
+
liveness.watch(run_id, events)
|
|
415
449
|
returncode = self._run(command, workspace, events, diagnostics, timeout_seconds, cancel)
|
|
416
450
|
finally:
|
|
451
|
+
liveness.forget(run_id, events)
|
|
417
452
|
record = getattr(self.repository, "record_machine_sleep", None)
|
|
418
453
|
if self._slept and record is not None:
|
|
419
454
|
record(project_id, run_id, self._slept)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""When each running AI attempt last wrote output, so the UI can tell working from stuck.
|
|
2
|
+
|
|
3
|
+
The provider streams its events into a file while it works; that file's modification time is
|
|
4
|
+
the last moment the AI process said anything, including the long thinking between tool calls
|
|
5
|
+
that leaves no tool activity behind. Kept in memory: it only means something while Clipen runs.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import threading
|
|
11
|
+
from datetime import datetime, timezone
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
_lock = threading.Lock()
|
|
15
|
+
_attempts: dict[str, Path] = {}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def watch(run_id: str, events: Path) -> None:
|
|
19
|
+
with _lock:
|
|
20
|
+
_attempts[run_id] = events
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def forget(run_id: str, events: Path) -> None:
|
|
24
|
+
with _lock:
|
|
25
|
+
if _attempts.get(run_id) == events:
|
|
26
|
+
del _attempts[run_id]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def last_output(run_id: str) -> str | None:
|
|
30
|
+
"""The ISO time the run's AI process last wrote output, or None when no process runs for it."""
|
|
31
|
+
with _lock:
|
|
32
|
+
events = _attempts.get(run_id)
|
|
33
|
+
if events is None:
|
|
34
|
+
return None
|
|
35
|
+
try:
|
|
36
|
+
written = events.stat().st_mtime
|
|
37
|
+
except OSError:
|
|
38
|
+
return None
|
|
39
|
+
return datetime.fromtimestamp(written, timezone.utc).isoformat(timespec="microseconds")
|
|
@@ -6,9 +6,12 @@ disk by content, and composited like any other programme graphic, so the
|
|
|
6
6
|
preview, the film and the Resolve export show the same picture.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
import functools
|
|
9
10
|
import hashlib
|
|
10
11
|
import json
|
|
11
12
|
import os
|
|
13
|
+
import re
|
|
14
|
+
import struct
|
|
12
15
|
import subprocess
|
|
13
16
|
import sys
|
|
14
17
|
import tempfile
|
|
@@ -109,10 +112,106 @@ FALLBACKS = {
|
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
|
|
115
|
+
def _chain(family):
|
|
116
|
+
return list(dict.fromkeys([family, *FALLBACKS.get(family, []), "PingFang TC"]))
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def _stack(chain):
|
|
120
|
+
return ", ".join(f'"{name}"' for name in chain) + ", sans-serif"
|
|
121
|
+
|
|
122
|
+
|
|
112
123
|
def font_stack(family):
|
|
113
124
|
"""The CSS font list for a typeface: itself, faces of the same feel for missing characters, then PingFang."""
|
|
114
|
-
|
|
115
|
-
|
|
125
|
+
return _stack(_chain(family))
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
# Chinese, Japanese kana and half-width kana: where faces of one feel still differ from one another.
|
|
129
|
+
_CJK = re.compile("[-ヿㇰ-ㇿ㐀-䶿一-鿿豈-ヲ-゚]")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@functools.lru_cache(maxsize=None)
|
|
133
|
+
def covered(family):
|
|
134
|
+
"""The characters a carried font draws, read from its cmap table."""
|
|
135
|
+
from importlib.resources import files
|
|
136
|
+
|
|
137
|
+
data = files("clipen.rendering").joinpath("fonts", BUNDLED[family]["file"]).read_bytes()
|
|
138
|
+
tables = {
|
|
139
|
+
data[12 + 16 * i : 16 + 16 * i]: struct.unpack(">I", data[20 + 16 * i : 24 + 16 * i])[0]
|
|
140
|
+
for i in range(struct.unpack(">H", data[4:6])[0])
|
|
141
|
+
}
|
|
142
|
+
cmap = tables[b"cmap"]
|
|
143
|
+
subtables = {}
|
|
144
|
+
for i in range(struct.unpack(">H", data[cmap + 2 : cmap + 4])[0]):
|
|
145
|
+
platform, encoding, offset = struct.unpack(">HHI", data[cmap + 4 + 8 * i : cmap + 12 + 8 * i])
|
|
146
|
+
subtables[(platform, encoding)] = cmap + offset
|
|
147
|
+
points = set()
|
|
148
|
+
full = subtables.get((3, 10)) or subtables.get((0, 4)) or subtables.get((0, 6))
|
|
149
|
+
if full is not None and struct.unpack(">H", data[full : full + 2])[0] == 12:
|
|
150
|
+
for g in range(struct.unpack(">I", data[full + 12 : full + 16])[0]):
|
|
151
|
+
first, last, _ = struct.unpack(">III", data[full + 16 + 12 * g : full + 28 + 12 * g])
|
|
152
|
+
points.update(range(first, last + 1))
|
|
153
|
+
return frozenset(points)
|
|
154
|
+
base = subtables.get((3, 1)) or subtables.get((0, 3))
|
|
155
|
+
if base is None or struct.unpack(">H", data[base : base + 2])[0] != 4:
|
|
156
|
+
return frozenset()
|
|
157
|
+
segments = struct.unpack(">H", data[base + 6 : base + 8])[0] // 2
|
|
158
|
+
ends = base + 14
|
|
159
|
+
starts, deltas, ranges = ends + 2 * segments + 2, ends + 4 * segments + 2, ends + 6 * segments + 2
|
|
160
|
+
|
|
161
|
+
def word(at):
|
|
162
|
+
return struct.unpack(">H", data[at : at + 2])[0]
|
|
163
|
+
|
|
164
|
+
for s in range(segments):
|
|
165
|
+
first, last, delta, offset = (
|
|
166
|
+
word(starts + 2 * s),
|
|
167
|
+
word(ends + 2 * s),
|
|
168
|
+
word(deltas + 2 * s),
|
|
169
|
+
word(ranges + 2 * s),
|
|
170
|
+
)
|
|
171
|
+
for point in range(first, min(last, 0xFFFE) + 1):
|
|
172
|
+
if offset:
|
|
173
|
+
glyph = word(ranges + 2 * s + offset + 2 * (point - first))
|
|
174
|
+
glyph = (glyph + delta) & 0xFFFF if glyph else 0
|
|
175
|
+
else:
|
|
176
|
+
glyph = (point + delta) & 0xFFFF
|
|
177
|
+
if glyph:
|
|
178
|
+
points.add(point)
|
|
179
|
+
return frozenset(points)
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def face_plan(profile):
|
|
183
|
+
"""Per look font role: the carried faces of its chain that lack Chinese or Japanese characters the page holds."""
|
|
184
|
+
look = profile.get("look")
|
|
185
|
+
if not look:
|
|
186
|
+
return []
|
|
187
|
+
words = "".join(str(v) for v in (_edits(profile).get("texts") or {}).values())
|
|
188
|
+
needed = set(_CJK.findall(profile["html"] + words))
|
|
189
|
+
if not needed:
|
|
190
|
+
return []
|
|
191
|
+
plan = []
|
|
192
|
+
for font in look["fonts"]:
|
|
193
|
+
chain = _chain(font["family"])
|
|
194
|
+
missing = {f: "".join(sorted(c for c in needed if ord(c) not in covered(f))) for f in chain if f in BUNDLED}
|
|
195
|
+
plan.append({"key": font["key"], "chain": chain, "missing": missing})
|
|
196
|
+
return plan
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def one_face(role, shown):
|
|
200
|
+
"""The stack that draws every Chinese or Japanese character a role shows in one face, or None when its own does.
|
|
201
|
+
|
|
202
|
+
Letting each missing character fall to the next face mixes two hands in one word (七里ヶ浜 in two styles);
|
|
203
|
+
instead the role moves to the first face of the same feel that has them all. Faces that draw none of
|
|
204
|
+
those characters, such as a Latin display face, stay first for the Latin letters. Fonts Mac carries
|
|
205
|
+
are taken to draw them all."""
|
|
206
|
+
chars = set(_CJK.findall("".join(shown)))
|
|
207
|
+
lacks = {face: chars & set(role["missing"].get(face, "")) for face in role["chain"]}
|
|
208
|
+
if not chars or not lacks[role["chain"][0]]:
|
|
209
|
+
return None
|
|
210
|
+
for index, face in enumerate(role["chain"]):
|
|
211
|
+
if not lacks[face]:
|
|
212
|
+
kept = [f for f in role["chain"][:index] if lacks[f] == chars]
|
|
213
|
+
return _stack(kept + role["chain"][index:])
|
|
214
|
+
return None
|
|
116
215
|
|
|
117
216
|
|
|
118
217
|
def look_css(look):
|
|
@@ -142,6 +241,8 @@ def _key(profile, timeline, duration):
|
|
|
142
241
|
duration,
|
|
143
242
|
_edits(profile),
|
|
144
243
|
look_css(profile.get("look")),
|
|
244
|
+
# Bumped when the way a role picks one face changes, so old frames are drawn again.
|
|
245
|
+
"one-face-1",
|
|
145
246
|
],
|
|
146
247
|
ensure_ascii=False,
|
|
147
248
|
sort_keys=True,
|
|
@@ -182,6 +283,7 @@ def frames(timeline, item, profile, wanted, cancel=None):
|
|
|
182
283
|
"frame_timeout": FRAME_TIMEOUT_SECONDS,
|
|
183
284
|
"edits": _edits(profile),
|
|
184
285
|
"look": look_css(profile.get("look")),
|
|
286
|
+
"faces": face_plan(profile),
|
|
185
287
|
}
|
|
186
288
|
_run(job, timeout=30 + FRAME_TIMEOUT_SECONDS + len(missing) * 1.5, cancel=cancel)
|
|
187
289
|
return paths
|
|
@@ -103,6 +103,44 @@ _FIELDS = """
|
|
|
103
103
|
}
|
|
104
104
|
"""
|
|
105
105
|
|
|
106
|
+
# The words each typeface is asked to draw right now, keyed by the face asked for first.
|
|
107
|
+
_SHOWN = """
|
|
108
|
+
() => {
|
|
109
|
+
const shown = {};
|
|
110
|
+
document.querySelectorAll('body *').forEach((el) => {
|
|
111
|
+
const own = Array.from(el.childNodes).filter((n) => n.nodeType === 3).map((n) => n.textContent).join('').trim();
|
|
112
|
+
if (!own) return;
|
|
113
|
+
const first = getComputedStyle(el).fontFamily.split(',')[0].trim().replace(/^["']|["']$/g, '');
|
|
114
|
+
shown[first] = (shown[first] || '') + own;
|
|
115
|
+
});
|
|
116
|
+
return shown;
|
|
117
|
+
}
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def one_face_per_role(page, plan, duration, fps):
|
|
122
|
+
"""Give each look role one face for the Chinese and Japanese it shows anywhere in the graphic, before drawing.
|
|
123
|
+
|
|
124
|
+
Text a page writes over time is read at a few fixed moments, so every run of the same graphic decides alike."""
|
|
125
|
+
from clipen.rendering.custom_components import one_face
|
|
126
|
+
|
|
127
|
+
if not plan:
|
|
128
|
+
return
|
|
129
|
+
shown = {}
|
|
130
|
+
for frame in sorted({0, duration // 4, duration // 2, duration * 3 // 4, duration - 1}):
|
|
131
|
+
page.evaluate(_SEEK, [frame, fps])
|
|
132
|
+
for family, words in page.evaluate(_SHOWN).items():
|
|
133
|
+
shown.setdefault(family, []).append(words)
|
|
134
|
+
stacks = {role["key"]: one_face(role, shown.get(role["chain"][0], [])) for role in plan}
|
|
135
|
+
stacks = {key: stack for key, stack in stacks.items() if stack}
|
|
136
|
+
if stacks:
|
|
137
|
+
page.evaluate(
|
|
138
|
+
"(stacks) => Object.entries(stacks).forEach(([key, stack]) =>"
|
|
139
|
+
" document.documentElement.style.setProperty('--look-font-' + key, stack))",
|
|
140
|
+
stacks,
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
|
|
106
144
|
_SEEK = """
|
|
107
145
|
async ([frame, fps]) => {
|
|
108
146
|
const ms = frame / fps * 1000;
|
|
@@ -189,6 +227,13 @@ def render(job):
|
|
|
189
227
|
(out / "fields.json").write_text(
|
|
190
228
|
json.dumps(page.evaluate(_FIELDS), ensure_ascii=False), encoding="utf-8"
|
|
191
229
|
)
|
|
230
|
+
if job["frames"]:
|
|
231
|
+
try:
|
|
232
|
+
one_face_per_role(page, job.get("faces"), int(job["duration"]), fps)
|
|
233
|
+
except TimeoutError:
|
|
234
|
+
fail("custom_component_frame_timeout", "faces")
|
|
235
|
+
except Error as error:
|
|
236
|
+
fail("custom_component_script_error", problems[0] if problems else str(error))
|
|
192
237
|
for frame in job["frames"]:
|
|
193
238
|
try:
|
|
194
239
|
page.evaluate(_SEEK, [int(frame), fps])
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_about": "English names and descriptions for the built-in skill and templates, shown when the interface reads English. Display only: not part of the frozen skill content.",
|
|
3
|
+
"skills": {
|
|
4
|
+
"travel-program": {
|
|
5
|
+
"name": "People-and-experience travel show",
|
|
6
|
+
"description": "A travel show made from real people, conversation and experience, with consistent captions, info labels, motion and sound."
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"references": {
|
|
10
|
+
"旅遊行程的地名標示、激動句子放大、資訊寫進字幕;轉成 Clipen 原創版面。": "Place names along the route, excited lines made big, facts written into captions; turned into Clipen's own layouts.",
|
|
11
|
+
"左上角地點小標、店名與評價的小字標示、收斂的畫面質感;轉成 Clipen 原創版面。": "A small place label top left, small shop-name and rating tags, a restrained look; turned into Clipen's own layouts.",
|
|
12
|
+
"描邊字幕與黃色重點、貼在人物旁的反應字;轉成 Clipen 原創版面。": "Outlined captions with yellow highlights and reaction words beside people; turned into Clipen's own layouts.",
|
|
13
|
+
"YouTube 頻道": "YouTube channel"
|
|
14
|
+
},
|
|
15
|
+
"templates": {
|
|
16
|
+
"travel-vlog": {
|
|
17
|
+
"name": "Travel vlog", "category": "Travel",
|
|
18
|
+
"description": "Take viewers along in first person: setting off, on the way, arriving, and how it felt.",
|
|
19
|
+
"editorial_direction": "Follow your itinerary and keep the real conversations and reactions on the way; label places, transport and costs only when they help.",
|
|
20
|
+
"design_direction": "Outlined handwritten titles, tape-style “place | English” labels, yellow sticker words only for funny or surprising moments.",
|
|
21
|
+
"music_direction": "Light acoustic guitar or lo-fi beats that step back when people talk.",
|
|
22
|
+
"tags": ["First person", "Itinerary order", "Place labels"]
|
|
23
|
+
},
|
|
24
|
+
"product-unboxing": {
|
|
25
|
+
"name": "Unboxing", "category": "Products",
|
|
26
|
+
"description": "From the box and what is inside to first impressions, so viewers know what they would get.",
|
|
27
|
+
"editorial_direction": "In unboxing order: box, accessories, the product, first use. Specs and prices only from the footage or from you.",
|
|
28
|
+
"design_direction": "A slanted colour-block title to open, specs as black tags beside the product, a starburst reaction only for real surprise.",
|
|
29
|
+
"music_direction": "Clean electronic beats, turned down while unboxing and explaining.",
|
|
30
|
+
"tags": ["Unboxing order", "Spec labels", "First impressions"]
|
|
31
|
+
},
|
|
32
|
+
"travel-highlight": {
|
|
33
|
+
"name": "Travel highlights", "category": "Travel",
|
|
34
|
+
"description": "The whole trip in under three minutes, carried by picture and music.",
|
|
35
|
+
"editorial_direction": "Pick the trip's best and most telling moments and cut to the music; keep only the one or two lines that land.",
|
|
36
|
+
"design_direction": "A widely spaced serif title and thin-line place labels, no stickers, everything fading in slowly so the scenery has the frame.",
|
|
37
|
+
"music_direction": "Music with rises and falls sets the pace; cuts fall on the beat.",
|
|
38
|
+
"tags": ["Music first", "Best shots", "Restrained titles"]
|
|
39
|
+
},
|
|
40
|
+
"food-review": {
|
|
41
|
+
"name": "Food spot", "category": "Travel",
|
|
42
|
+
"description": "Take viewers to one place to eat: why you came, what you ordered, the first bite.",
|
|
43
|
+
"editorial_direction": "Say why you came and what you ordered; keep the first bite and the real reaction whole. Prices and names need a source.",
|
|
44
|
+
"design_direction": "A rounded capsule shop name, price tags beside the food, speech bubbles only when it is really good or surprising.",
|
|
45
|
+
"music_direction": "Light beats, lower while eating and talking.",
|
|
46
|
+
"tags": ["First bite", "Shop and price", "Real reactions"]
|
|
47
|
+
},
|
|
48
|
+
"daily-vlog": {
|
|
49
|
+
"name": "Daily vlog", "category": "Life",
|
|
50
|
+
"description": "The little things in a day, like chatting with a friend.",
|
|
51
|
+
"editorial_direction": "In the order of the day, keep the fun conversations and small moments; pass quickly over empty shots and travel.",
|
|
52
|
+
"design_direction": "A handwritten title with a wavy underline that appears as if written; cute reaction words, but not too many.",
|
|
53
|
+
"music_direction": "Warm lo-fi or acoustic guitar that steps back when people talk.",
|
|
54
|
+
"tags": ["Everyday feel", "Time order", "Easy conversation"]
|
|
55
|
+
},
|
|
56
|
+
"product-demo": {
|
|
57
|
+
"name": "Product demo", "category": "Products",
|
|
58
|
+
"description": "Show step by step how to use a product so viewers can follow and learn.",
|
|
59
|
+
"editorial_direction": "One step at a time in the order you use it; each step says what to do, then shows a clear close-up.",
|
|
60
|
+
"design_direction": "Dark interface-panel titles, keycap “STEP” labels, straight arrows pointing at buttons and screens.",
|
|
61
|
+
"music_direction": "Quiet electronic beats, clearly lower while explaining.",
|
|
62
|
+
"tags": ["Step by step", "Close-ups", "Order of use"]
|
|
63
|
+
},
|
|
64
|
+
"product-review": {
|
|
65
|
+
"name": "Product review", "category": "Products",
|
|
66
|
+
"description": "What it is like after real use: pros, cons, and who it suits.",
|
|
67
|
+
"editorial_direction": "Say what was tested and how, then the pros and the cons, then who it suits. Judgements come only from what the speaker actually experienced in the footage.",
|
|
68
|
+
"design_direction": "Highlighter titles, a tick for each pro and a cross for each con, the verdict as a stamp.",
|
|
69
|
+
"music_direction": "Steady beats, lower while explaining and comparing.",
|
|
70
|
+
"tags": ["Pros and cons", "Real testing", "Verdict"]
|
|
71
|
+
},
|
|
72
|
+
"event-recap": {
|
|
73
|
+
"name": "Event recap", "category": "Events",
|
|
74
|
+
"description": "The highlights of a wedding, party or exhibition, keeping the feel of being there.",
|
|
75
|
+
"editorial_direction": "Follow the event: the opening, the main moments, people's reactions and the close. Keep the key lines of speeches or vows whole.",
|
|
76
|
+
"design_direction": "A gold calligraphic title with fine lines, small time and place labels, names with a thin underline, all fading in elegantly.",
|
|
77
|
+
"music_direction": "Warm piano or strings that stop or drop well down during speeches.",
|
|
78
|
+
"tags": ["Event order", "Key moments", "Atmosphere"]
|
|
79
|
+
},
|
|
80
|
+
"shorts-highlight": {
|
|
81
|
+
"name": "Shorts highlight", "category": "Shorts",
|
|
82
|
+
"description": "A vertical 30–60 second highlight that grabs attention in the first second.",
|
|
83
|
+
"editorial_direction": "Open on the funniest or most striking moment, then quickly give the context; something new every two or three seconds.",
|
|
84
|
+
"design_direction": "Big vertical text with a red and black double outline, neon block labels, key words popping with the lines, large captions.",
|
|
85
|
+
"music_direction": "Brisk music; cuts fall on the beat.",
|
|
86
|
+
"tags": ["Vertical 9:16", "Hook in 1 second", "Fast pace"]
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
- 頁面就是整個畫面(window.clipen.width × height,例如 1920×1080)。只畫元件本身,其餘保持透明,讓素材透出來。用 vw/vh 或依 window.clipen 計算尺寸,不同解析度才會一致。
|
|
41
41
|
- 時間由 Clipen 控制:CSS 動畫與 Web Animations 會逐格精準播放;用程式畫的話,定義 `window.clipenFrame = (frame, seconds) => {...}`,在裡面畫出那一格。requestAnimationFrame 迴圈、計時器與真實時鐘不會前進。第 0 格是元件出現的第一格,window.clipen 也提供 fps 與 durationFrames。
|
|
42
42
|
- 沒有網路:圖片與圖形請內嵌(data: URL、inline SVG)。
|
|
43
|
-
- 字型只能用元件外觀裡的:寫成 `font-family: var(--look-font-鍵名)`,外觀的顏色是 `var(--look-鍵名)`。用了外觀以外的字型(包括沒指定字型時的瀏覽器預設字)會被擋下。可選的字型列在 list_program_components 的 font_choices:系統字體,加上 Clipen 內附、任何電腦都能用的字型(中文手寫 Clipen Chenyu、楷書筆意 Clipen Iansui;日文手寫 Yusei Magic、Yomogi、Zen Kurenaido、Hachi Maru Pop;日文標題 Dela Gothic One、RocknRoll One、Zen Maru Gothic;英文 Bebas Neue、Anton、Caveat、Playfair Display
|
|
43
|
+
- 字型只能用元件外觀裡的:寫成 `font-family: var(--look-font-鍵名)`,外觀的顏色是 `var(--look-鍵名)`。用了外觀以外的字型(包括沒指定字型時的瀏覽器預設字)會被擋下。可選的字型列在 list_program_components 的 font_choices:系統字體,加上 Clipen 內附、任何電腦都能用的字型(中文手寫 Clipen Chenyu、楷書筆意 Clipen Iansui;日文手寫 Yusei Magic、Yomogi、Zen Kurenaido、Hachi Maru Pop;日文標題 Dela Gothic One、RocknRoll One、Zen Maru Gothic;英文 Bebas Neue、Anton、Caveat、Playfair Display)。字型缺了元件要顯示的中日文字時,這個字型鍵名的中日文會整組換成同樣感覺、而且字都齊全的下一套字型(例如辰宇遇到日文假名就整組改用 Yomogi),一個詞裡不會混兩種字。想保留自己選的字型,就選字都齊全的那一套;日文為主的元件優先選日文字型。想換字或加一套字,就改外觀;用這個外觀的元件會一起換。改外觀時不要拿掉元件還在用的字型鍵名。
|
|
44
44
|
- 標出使用者可以自己改的地方:主要文字放在加了 `data-clipen-text="鍵名"` 的元素裡(可加 `data-clipen-label="主標"` 當顯示名稱),元素內只放純文字;主要顏色寫成 `:root` 上的 `--clipen-名稱` 變數(例如 `--clipen-主色`、`--clipen-字色`),再用 `var(--clipen-主色)` 套用。使用者在審片頁改的字與顏色會在頁面腳本執行前套上;要逐字拆開做動畫時,在 DOMContentLoaded 之後依元素目前的文字拆。沒有標出時,使用者只能請你重做;每個元件都要標。
|
|
45
45
|
- 除了字型要來自外觀,只有技術檢查:頁面要能載入、程式不出錯、每格 10 秒內畫完、確實畫出東西、200 KB 以內。
|
|
46
46
|
- 工具會回傳兩張圖:元件停在畫面上的樣子,以及從進場到退場的多格對照(每格標了第幾格)。兩張都要看:字是否清楚、有沒有擋到臉或字幕、是否服務這一刻;動畫是否看得出順序、節奏是否合適、退場是否乾淨。不滿意就用 update_custom_component 改,只需要給要變的欄位。
|
|
@@ -56,4 +56,3 @@
|
|
|
56
56
|
|
|
57
57
|
較早的作品可能有用舊內建模板做的元件(list_program_components 的 designed_freely 為 false),或沒有外觀的自由元件(look_id 為空,更新時要指定 look_id)。它們會照常顯示;
|
|
58
58
|
要改它們時,用 remove_program_component 移除,再用 add_custom_component 設計新的。
|
|
59
|
-
自由元件匯出到 DaVinci Resolve 時是圖片,不能在 Resolve 裡改字。
|
|
@@ -304,9 +304,31 @@ def _public(skill):
|
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
|
|
307
|
+
def _english(skill):
|
|
308
|
+
"""The built-in skill and templates as an English reader sees them; their frozen content is unchanged."""
|
|
309
|
+
display = json.loads(_root().joinpath("display.en.json").read_text(encoding="utf-8"))
|
|
310
|
+
# A template's own skill is named after its template.
|
|
311
|
+
template = display["templates"].get(skill["skill_id"].removeprefix("clipen-"), {})
|
|
312
|
+
names = display["skills"].get(skill["skill_id"]) or {
|
|
313
|
+
k: template[k] for k in ("name", "description") if k in template
|
|
314
|
+
}
|
|
315
|
+
if names:
|
|
316
|
+
skill.update(names)
|
|
317
|
+
for template in skill["templates"]:
|
|
318
|
+
template.update(display["templates"].get(template["template_id"], {}))
|
|
319
|
+
for reference in template.get("references", []):
|
|
320
|
+
for key in ("title", "takeaway"):
|
|
321
|
+
reference[key] = display["references"].get(reference.get(key), reference.get(key))
|
|
322
|
+
return skill
|
|
323
|
+
|
|
324
|
+
|
|
307
325
|
def list_skills():
|
|
326
|
+
from clipen.i18n import english
|
|
327
|
+
|
|
308
328
|
core, skills = builtin_skills()
|
|
309
329
|
listed = [_public(compose([entry], core=core)) for entry in skills.values()]
|
|
330
|
+
if english():
|
|
331
|
+
listed = [_english(skill) if skill["source"] == "builtin" else skill for skill in listed]
|
|
310
332
|
library = skill_library()
|
|
311
333
|
for item in library.list():
|
|
312
334
|
if item["state"] == "ready":
|