@clipen/clipen-cli 1.0.7 → 1.0.9
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 +16 -6
- package/apps/web/dist/assets/index-DPgSvXZ1.js +15 -0
- package/apps/web/dist/assets/index-DmPWV61v.css +1 -0
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +229 -68
- 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 +2 -1
- package/src/clipen/analysis/setup_cli.py +58 -12
- package/src/clipen/bootstrap.py +499 -167
- package/src/clipen/cli.py +40 -15
- package/src/clipen/controller/app.py +120 -38
- package/src/clipen/controller/server.py +70 -27
- package/src/clipen/editing/agent_repository.py +8 -0
- package/src/clipen/editing/agent_tools.py +1 -1
- package/src/clipen/editing/caption_design.py +134 -0
- package/src/clipen/editing/change_report.py +17 -0
- package/src/clipen/editing/component_looks.py +3 -3
- package/src/clipen/editing/component_review.py +0 -38
- package/src/clipen/editing/coordinator.py +20 -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 +67 -13
- package/src/clipen/editing/production_media.py +13 -2
- package/src/clipen/editing/production_preview.py +11 -9
- package/src/clipen/editing/production_progress.py +48 -3
- package/src/clipen/editing/production_tools.py +11 -20
- package/src/clipen/editing/program_subtitles.py +5 -13
- package/src/clipen/editing/resolve_export.py +2 -183
- package/src/clipen/editing/skill_tools.py +142 -218
- package/src/clipen/editing/tool_receipts.py +2 -1
- package/src/clipen/editing/versions.py +55 -10
- package/src/clipen/editing/visual_preview.py +62 -0
- package/src/clipen/editing/workbench.py +21 -1
- package/src/clipen/i18n.py +155 -0
- package/src/clipen/locale_en.py +546 -0
- package/src/clipen/mcp_editing/__main__.py +8 -0
- package/src/clipen/media/storage.py +2 -2
- package/src/clipen/own_ffmpeg.py +113 -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 +42 -5
- package/src/clipen/providers/liveness.py +39 -0
- package/src/clipen/rendering/custom_components.py +216 -25
- package/src/clipen/rendering/custom_render.py +90 -54
- package/src/clipen/rendering/fetched_fonts.py +127 -0
- package/src/clipen/rendering/production_effects.py +24 -2
- package/src/clipen/rendering/program_components.py +18 -240
- package/src/clipen/rendering/renderer.py +23 -17
- package/src/clipen/rendering/titles.py +29 -12
- package/src/clipen/skills/builtin/SKILL.md +3 -3
- package/src/clipen/skills/builtin/assets/sample-daily-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-event-recap.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-food-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-demo.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-review.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-product-unboxing.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-shorts-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-highlight.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/sample-travel-vlog.mp4 +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-daily-vlog.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-event-recap.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-food-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-demo.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-review.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-product-unboxing.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-shorts-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-highlight.png +0 -0
- package/src/clipen/skills/builtin/assets/style-tpl-travel-vlog.png +0 -0
- package/src/clipen/skills/builtin/display.en.json +89 -0
- package/src/clipen/skills/builtin/references/captions.md +12 -0
- package/src/clipen/skills/builtin/references/graphics.md +6 -6
- package/src/clipen/skills/builtin/template-skills/clipen-daily-vlog/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-event-recap/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-food-review/SKILL.md +9 -4
- package/src/clipen/skills/builtin/template-skills/clipen-product-demo/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-review/SKILL.md +10 -6
- package/src/clipen/skills/builtin/template-skills/clipen-product-unboxing/SKILL.md +9 -7
- package/src/clipen/skills/builtin/template-skills/clipen-shorts-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-highlight/SKILL.md +10 -5
- package/src/clipen/skills/builtin/template-skills/clipen-travel-vlog/SKILL.md +10 -7
- package/src/clipen/skills/catalog.py +22 -8
- package/src/clipen/skills/package.py +1 -10
- package/src/clipen/terminal.py +344 -0
- package/src/clipen/workspace.py +97 -28
- package/apps/web/dist/assets/index-C3Zw0WaM.js +0 -14
- package/apps/web/dist/assets/index-CaxEZKLc.css +0 -1
- package/src/clipen/editing/resolve_titles.py +0 -291
- package/src/clipen/rendering/program_creator.py +0 -804
- package/src/clipen/rendering/program_identities.py +0 -350
- package/src/clipen/rendering/program_motion.py +0 -186
- package/src/clipen/rendering/program_studio.py +0 -227
- package/src/clipen/rendering/program_styles.py +0 -321
- package/src/clipen/skills/builtin/components.json +0 -133
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Captions the AI designs: one web page every caption of the film is drawn with.
|
|
2
|
+
|
|
3
|
+
The page marks where the words go with data-clipen-caption; Clipen fills it with each
|
|
4
|
+
caption's words (emphasised words as <em>) and sets data-delivery on the root to
|
|
5
|
+
dialogue, punchline or quiet. The page may move only while a caption enters and
|
|
6
|
+
leaves (entry_frames, exit_frames); in between it holds still, so a long film's
|
|
7
|
+
captions cost a handful of frames each. Like a look, a new design restyles every
|
|
8
|
+
caption already on the film, and each caption keeps the design it was saved with.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
from dataclasses import replace
|
|
13
|
+
|
|
14
|
+
from clipen.domain import TextClip
|
|
15
|
+
from clipen.projects import ProjectError
|
|
16
|
+
|
|
17
|
+
from .agent_models import ToolResult
|
|
18
|
+
|
|
19
|
+
PREFIX = "agent.captions."
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _path(tools):
|
|
23
|
+
return tools.repository.projects.root / tools.project_id / f"caption-design-{tools.run_id}.json"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def current_id(tools):
|
|
27
|
+
"""The design new captions are made with, or None before the AI has designed them."""
|
|
28
|
+
path = _path(tools)
|
|
29
|
+
if path.is_symlink():
|
|
30
|
+
raise ProjectError("storage_unsafe", "字幕設計檔案不安全。", status_code=409)
|
|
31
|
+
if not path.exists():
|
|
32
|
+
return None
|
|
33
|
+
return json.loads(path.read_text(encoding="utf-8")).get("design_id")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def chosen_id(tools, row):
|
|
37
|
+
"""The design a caption asks for by design_id, or the latest one."""
|
|
38
|
+
if row.get("design_id"):
|
|
39
|
+
from .production_media import load_text_styles
|
|
40
|
+
|
|
41
|
+
design = load_text_styles(tools.repository.projects, tools.project_id).get(row["design_id"])
|
|
42
|
+
if not design or design.get("kind") != "caption_design":
|
|
43
|
+
raise ProjectError(
|
|
44
|
+
"caption_design_not_found",
|
|
45
|
+
"沒有這個字幕設計;用 set_caption_design 回傳的 design_id。",
|
|
46
|
+
status_code=422,
|
|
47
|
+
)
|
|
48
|
+
return row["design_id"]
|
|
49
|
+
return required_id(tools)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def required_id(tools):
|
|
53
|
+
design_id = current_id(tools)
|
|
54
|
+
if design_id is None:
|
|
55
|
+
raise ProjectError(
|
|
56
|
+
"caption_design_required",
|
|
57
|
+
"先用 set_caption_design 設計字幕的樣子,再建立字幕。",
|
|
58
|
+
status_code=422,
|
|
59
|
+
)
|
|
60
|
+
return design_id
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def apply(tools, args):
|
|
64
|
+
"""Check and save a caption design, then restyle every caption on the film with it."""
|
|
65
|
+
from clipen.finishing.models import digest
|
|
66
|
+
from clipen.rendering import custom_components
|
|
67
|
+
|
|
68
|
+
from . import component_looks
|
|
69
|
+
from .production_media import atomic_json, load_text_styles, text_style_path
|
|
70
|
+
from .skill_tools import _custom_problem
|
|
71
|
+
|
|
72
|
+
html = args.get("html")
|
|
73
|
+
if not isinstance(html, str) or "data-clipen-caption" not in html:
|
|
74
|
+
raise ProjectError(
|
|
75
|
+
"caption_design_invalid",
|
|
76
|
+
"字幕頁面要有一個標了 data-clipen-caption 的元素,Clipen 會把每句字幕放進去。",
|
|
77
|
+
status_code=422,
|
|
78
|
+
)
|
|
79
|
+
look = None
|
|
80
|
+
if args.get("look_id"):
|
|
81
|
+
look = component_looks.current(tools).get(args["look_id"])
|
|
82
|
+
if look is None:
|
|
83
|
+
raise ProjectError(
|
|
84
|
+
"component_look_not_found",
|
|
85
|
+
"沒有這個外觀;先用 set_component_look 建立字幕用的外觀,或從 list_program_components 的 looks 選一個。",
|
|
86
|
+
status_code=422,
|
|
87
|
+
)
|
|
88
|
+
design = {
|
|
89
|
+
"kind": "caption_design",
|
|
90
|
+
"html": html,
|
|
91
|
+
"look": look,
|
|
92
|
+
"entry_frames": args.get("entry_frames", 0),
|
|
93
|
+
"exit_frames": args.get("exit_frames", 0),
|
|
94
|
+
**({"throughout": True} if args.get("throughout") else {}),
|
|
95
|
+
}
|
|
96
|
+
design_id = PREFIX + digest(design)[:24]
|
|
97
|
+
timeline = tools._timeline()
|
|
98
|
+
sample = custom_components.SAMPLE_CAPTION
|
|
99
|
+
item = TextClip("caption-sample", 0, 60, sample["text"], design_id)
|
|
100
|
+
page = custom_components.caption_profile(design, sample["text"], sample["emphasis"], sample["delivery"])
|
|
101
|
+
try:
|
|
102
|
+
custom_components.check(timeline, item, page)
|
|
103
|
+
except custom_components.CustomRenderError as error:
|
|
104
|
+
raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
|
|
105
|
+
styles = load_text_styles(tools.repository.projects, tools.project_id)
|
|
106
|
+
styles[design_id] = design
|
|
107
|
+
tracks, restyled = [], 0
|
|
108
|
+
for track in timeline.tracks:
|
|
109
|
+
items = []
|
|
110
|
+
for clip in track.items:
|
|
111
|
+
profile = styles.get(clip.style_id, {}) if isinstance(clip, TextClip) else {}
|
|
112
|
+
if (
|
|
113
|
+
args.get("apply_to_existing", True)
|
|
114
|
+
and profile.get("kind") == "program_subtitle"
|
|
115
|
+
and profile.get("design") != design_id
|
|
116
|
+
):
|
|
117
|
+
updated = {**profile, "design": design_id}
|
|
118
|
+
identifier = "agent.text." + digest(updated)[:24]
|
|
119
|
+
styles[identifier] = updated
|
|
120
|
+
clip = replace(clip, style_id=identifier)
|
|
121
|
+
restyled += 1
|
|
122
|
+
items.append(clip)
|
|
123
|
+
tracks.append(replace(track, items=tuple(items)))
|
|
124
|
+
atomic_json(text_style_path(tools.repository.projects, tools.project_id), styles)
|
|
125
|
+
atomic_json(_path(tools), {"design_id": design_id})
|
|
126
|
+
result = {
|
|
127
|
+
"design_id": design_id,
|
|
128
|
+
"captions_restyled": restyled,
|
|
129
|
+
"inspection_required": "Render a preview and watch the captions: legibility over the footage, emphasis, and how they enter and leave.",
|
|
130
|
+
}
|
|
131
|
+
if not restyled:
|
|
132
|
+
return ToolResult(result)
|
|
133
|
+
saved = tools._save(replace(timeline, tracks=tuple(tracks)), args["summary"])
|
|
134
|
+
return ToolResult({**saved.payload, **result})
|
|
@@ -7,6 +7,23 @@ OUTCOMES = {"done": "已處理", "partly": "部分處理", "not_done": "沒有
|
|
|
7
7
|
# Work may be left only for one of these: the person has to decide or supply something,
|
|
8
8
|
# or no Clipen tool can do it. Running out of effort is not a reason.
|
|
9
9
|
REASONS = {"needs_you": "需要你決定或提供", "cannot": "Clipen 目前做不到"}
|
|
10
|
+
_OUTCOMES_EN = {"done": "Done", "partly": "Partly done", "not_done": "Not done", "kept": "Kept as you said"}
|
|
11
|
+
_REASONS_EN = {"needs_you": "Needs your decision or a file", "cannot": "Clipen can't do this yet"}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def outcome_label(outcome):
|
|
15
|
+
"""How an answer to a note reads to the person, in their language."""
|
|
16
|
+
from clipen.i18n import english
|
|
17
|
+
|
|
18
|
+
return (_OUTCOMES_EN if english() else OUTCOMES).get(outcome, "")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def reason_label(reason):
|
|
22
|
+
from clipen.i18n import english
|
|
23
|
+
|
|
24
|
+
return (_REASONS_EN if english() else REASONS).get(reason, "")
|
|
25
|
+
|
|
26
|
+
|
|
10
27
|
UNFINISHED = "change_report_unfinished"
|
|
11
28
|
|
|
12
29
|
|
|
@@ -15,7 +15,6 @@ import json
|
|
|
15
15
|
import re
|
|
16
16
|
|
|
17
17
|
from clipen.projects import ProjectError
|
|
18
|
-
from clipen.rendering.custom_components import FONT_CHOICES
|
|
19
18
|
|
|
20
19
|
KEY = re.compile(r"^[A-Za-z0-9_\-一-鿿]{1,24}$")
|
|
21
20
|
HEX = re.compile(r"^#[0-9a-fA-F]{6}$")
|
|
@@ -52,8 +51,9 @@ def normalize(value):
|
|
|
52
51
|
entry.get("label") if isinstance(entry.get("label"), str) and entry["label"].strip() else entry["key"]
|
|
53
52
|
)
|
|
54
53
|
if kind == "font":
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
family = entry.get("family")
|
|
55
|
+
if not isinstance(family, str) or not family.strip() or len(family) > 60:
|
|
56
|
+
raise _invalid("字型要寫成字型名稱,例如 PingFang TC、Noto Serif TC。")
|
|
57
57
|
result.append({"key": entry["key"], "label": label.strip()[:24], "family": entry["family"]})
|
|
58
58
|
else:
|
|
59
59
|
if not isinstance(entry.get("value"), str) or not HEX.match(entry["value"]):
|
|
@@ -1,43 +1,11 @@
|
|
|
1
1
|
"""Content checks that keep programme graphics tied to a moment, not a template."""
|
|
2
2
|
|
|
3
|
-
import re
|
|
4
|
-
import unicodedata
|
|
5
3
|
from collections import Counter
|
|
6
4
|
|
|
7
|
-
# Short reactions land on one beat; a long hold reads as a static label.
|
|
8
|
-
RESTATE_RATIO = 0.5
|
|
9
5
|
SAME_POSITION_DISTANCE = 0.03
|
|
10
6
|
SAME_POSITION_RUN = 3
|
|
11
7
|
UNIFORM_DURATION_SHARE = 0.5
|
|
12
8
|
UNIFORM_DURATION_MINIMUM = 4
|
|
13
|
-
_PARALLEL = re.compile(r"^[^,,・]{2,8}[,,][^,,・]{2,8}$")
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def significant(text):
|
|
17
|
-
return "".join(c for c in unicodedata.normalize("NFKC", text) if unicodedata.category(c)[0] not in "PZCS")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def _bigrams(text):
|
|
21
|
-
text = significant(text)
|
|
22
|
-
return [text[n : n + 2] for n in range(len(text) - 1)]
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def restated_ratio(text, subtitles):
|
|
26
|
-
"""Share of the graphic's character pairs copied from concurrent subtitles."""
|
|
27
|
-
pairs = _bigrams(text)
|
|
28
|
-
spoken = significant("".join(subtitles))
|
|
29
|
-
return sum(pair in spoken for pair in pairs) / len(pairs) if pairs else 0.0
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def concurrent_subtitles(timeline, start, duration):
|
|
33
|
-
end = start + duration
|
|
34
|
-
return [
|
|
35
|
-
i.text
|
|
36
|
-
for t in timeline.tracks
|
|
37
|
-
if t.track_id == "agent-subtitles"
|
|
38
|
-
for i in t.items
|
|
39
|
-
if i.start_frame < end and start < i.start_frame + i.duration_frames
|
|
40
|
-
]
|
|
41
9
|
|
|
42
10
|
|
|
43
11
|
def design_notes(timeline, elements, styles):
|
|
@@ -61,14 +29,8 @@ def design_notes(timeline, elements, styles):
|
|
|
61
29
|
duration, count = Counter(round(i.duration_frames / fps * 2) / 2 for i in ordered).most_common(1)[0]
|
|
62
30
|
if count / len(ordered) > UNIFORM_DURATION_SHARE:
|
|
63
31
|
notes.append({"code": "component_duration_uniform", "seconds": duration, "count": count})
|
|
64
|
-
for element in ordered:
|
|
65
|
-
kind = styles.get(element.style_id, {}).get("component_id")
|
|
66
|
-
primary = element.text.partition("\n")[0]
|
|
67
|
-
if kind not in {"program_title"} and _PARALLEL.match(primary):
|
|
68
|
-
notes.append({"code": "component_parallel_phrasing", "item_id": element.item_id, "text": primary})
|
|
69
32
|
messages = {
|
|
70
33
|
"component_position_repeated": "連續多個元件擺在同一位置。請依每個畫面的人物、物件與空白處重新決定位置。",
|
|
71
34
|
"component_duration_uniform": "多數元件的顯示時長相同,節奏像固定節拍。請依每個瞬間的閱讀需要調整。",
|
|
72
|
-
"component_parallel_phrasing": "「A,B」對句常只是描述畫面。請改成畫面看不出的資訊或觀點,或移除這個元件。",
|
|
73
35
|
}
|
|
74
36
|
return [{**note, "message": messages[note["code"]]} for note in notes]
|
|
@@ -7,6 +7,7 @@ import queue
|
|
|
7
7
|
import threading
|
|
8
8
|
from pathlib import Path
|
|
9
9
|
|
|
10
|
+
from clipen.i18n import tr
|
|
10
11
|
from clipen.projects import ProjectError
|
|
11
12
|
from clipen.providers.codex import ProviderCancelled
|
|
12
13
|
|
|
@@ -150,6 +151,9 @@ class EditAgentCoordinator:
|
|
|
150
151
|
from .production_progress import production_activity
|
|
151
152
|
|
|
152
153
|
progress = production_activity(db, latest.run_id)
|
|
154
|
+
from clipen.providers import liveness
|
|
155
|
+
|
|
156
|
+
progress["ai_output_at"] = liveness.last_output(latest.run_id)
|
|
153
157
|
validation = next(
|
|
154
158
|
(
|
|
155
159
|
value
|
|
@@ -194,6 +198,8 @@ class EditAgentCoordinator:
|
|
|
194
198
|
from clipen.rendering.stage import read_stage
|
|
195
199
|
|
|
196
200
|
render["stage"] = read_stage(store.output_path(project_id, entry["render_id"], prepare=False))
|
|
201
|
+
if render["stage"]:
|
|
202
|
+
render["stage"] = tr(render["stage"])
|
|
197
203
|
return {
|
|
198
204
|
**render,
|
|
199
205
|
"revision_id": entry["revision_id"],
|
|
@@ -376,6 +382,10 @@ class EditAgentCoordinator:
|
|
|
376
382
|
def workbench_render(self, project_id, run_id, expected_revision_id):
|
|
377
383
|
from .workbench import idle, tools_for
|
|
378
384
|
|
|
385
|
+
# A person tuning a graphic saves again and again; the newest version replaces a render still under way.
|
|
386
|
+
earlier = self._user_previews.get((project_id, run_id))
|
|
387
|
+
if earlier is not None:
|
|
388
|
+
self._stop_user_renders(project_id, earlier)
|
|
379
389
|
with self._lock:
|
|
380
390
|
run = idle(self.repository, project_id, run_id)
|
|
381
391
|
if run.current_revision_id != expected_revision_id:
|
|
@@ -389,6 +399,16 @@ class EditAgentCoordinator:
|
|
|
389
399
|
del tools._session_cache
|
|
390
400
|
return tools.production_call("render_preview", {}).payload
|
|
391
401
|
|
|
402
|
+
def _stop_user_renders(self, project_id, tools):
|
|
403
|
+
from clipen.rendering import PreviewRenderRepository
|
|
404
|
+
|
|
405
|
+
store = PreviewRenderRepository(self.repository.projects)
|
|
406
|
+
for render_id, (cancel, thread) in list(getattr(tools, "_preview_jobs", {}).items()):
|
|
407
|
+
if thread.is_alive():
|
|
408
|
+
store.request_cancel(project_id, render_id)
|
|
409
|
+
cancel.set()
|
|
410
|
+
thread.join(timeout=30)
|
|
411
|
+
|
|
392
412
|
def resume(self, project_id: str, run_id: str, consent: object) -> AgentRun:
|
|
393
413
|
if consent is not True:
|
|
394
414
|
raise ProjectError(
|
|
@@ -10,6 +10,7 @@ from fractions import Fraction
|
|
|
10
10
|
from pathlib import Path
|
|
11
11
|
|
|
12
12
|
from clipen.domain import TrackKind
|
|
13
|
+
from clipen.i18n import english
|
|
13
14
|
from clipen.projects import ProjectError
|
|
14
15
|
from clipen.projects.storage import utc_now
|
|
15
16
|
|
|
@@ -36,7 +37,8 @@ class EvidenceTools:
|
|
|
36
37
|
raise ProjectError("asr_unavailable", "本機語音辨識尚未就緒,請先安裝或修復本機語音環境。", status_code=409)
|
|
37
38
|
request = {
|
|
38
39
|
"source": span.to_storage(),
|
|
39
|
-
|
|
40
|
+
# Speech is recognised in the language the person works in unless the AI names another.
|
|
41
|
+
"language": args.get("language", "en" if english() else "zh"),
|
|
40
42
|
"align_words": args.get("align_words", True),
|
|
41
43
|
"model": runtime[1],
|
|
42
44
|
}
|
|
@@ -4,6 +4,8 @@ Compares stored timeline payloads, so it works for every version ever saved,
|
|
|
4
4
|
whoever made the change.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
from clipen.i18n import tr
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
def _components(payload):
|
|
9
11
|
return {
|
|
@@ -45,7 +47,10 @@ def _media(payload, kind):
|
|
|
45
47
|
|
|
46
48
|
def _name(item):
|
|
47
49
|
first = (item.get("text") or "").split("\n", 1)[0].strip()
|
|
48
|
-
|
|
50
|
+
if not first:
|
|
51
|
+
return tr("一個元件", "a graphic")
|
|
52
|
+
shown = f"{first[:18]}{'…' if len(first) > 18 else ''}"
|
|
53
|
+
return tr(f"「{shown}」", f"“{shown}”")
|
|
49
54
|
|
|
50
55
|
|
|
51
56
|
def _clock(frames, payload):
|
|
@@ -58,12 +63,16 @@ def _graphic_change(before, after, styles, recut=False):
|
|
|
58
63
|
"""One sentence for one graphic that is in both versions, or None when it did not change."""
|
|
59
64
|
if before.get("text") != after.get("text"):
|
|
60
65
|
old, new = (item.get("text", "").split("\n", 1)[0] for item in (before, after))
|
|
61
|
-
|
|
66
|
+
if old != new:
|
|
67
|
+
return tr(f"把「{old}」改成「{new}」", f"Changed “{old}” to “{new}”")
|
|
68
|
+
return tr(f"改了{_name(after)}的補充文字", f"Changed the supporting text of {_name(after)}")
|
|
62
69
|
if before.get("style_id") != after.get("style_id"):
|
|
63
70
|
old, new = styles.get(before.get("style_id"), {}), styles.get(after.get("style_id"), {})
|
|
64
71
|
old_look, new_look = old.get("look") or {}, new.get("look") or {}
|
|
65
72
|
if new_look and old_look.get("look_id") != new_look.get("look_id") and old.get("html") == new.get("html"):
|
|
66
|
-
return
|
|
73
|
+
return tr(
|
|
74
|
+
f"把{_name(after)}換成「{new_look['name']}」外觀", f"Gave {_name(after)} the “{new_look['name']}” look"
|
|
75
|
+
)
|
|
67
76
|
if new_look and old_look != new_look and old.get("html") == new.get("html"):
|
|
68
77
|
# Said once per look, not once per graphic that follows it.
|
|
69
78
|
return (
|
|
@@ -73,33 +82,44 @@ def _graphic_change(before, after, styles, recut=False):
|
|
|
73
82
|
old_look.get("colors") != new_look.get("colors"),
|
|
74
83
|
)
|
|
75
84
|
if old.get("html") != new.get("html") and new.get("html"):
|
|
76
|
-
return f"重新設計{_name(after)}"
|
|
85
|
+
return tr(f"重新設計{_name(after)}", f"Redesigned {_name(after)}")
|
|
77
86
|
if old.get("edits") != new.get("edits") and new.get("html"):
|
|
78
87
|
before_edits, after_edits = old.get("edits") or {}, new.get("edits") or {}
|
|
79
88
|
words = (before_edits.get("texts") or {}) != (after_edits.get("texts") or {})
|
|
80
89
|
colours = (before_edits.get("colors") or {}) != (after_edits.get("colors") or {})
|
|
81
|
-
|
|
90
|
+
what = (
|
|
91
|
+
tr("文字和顏色", "text and colours")
|
|
92
|
+
if words and colours
|
|
93
|
+
else tr("文字", "text")
|
|
94
|
+
if words
|
|
95
|
+
else tr("顏色", "colours")
|
|
96
|
+
)
|
|
97
|
+
return tr(f"改了{_name(after)}的{what}", f"Changed the {what} of {_name(after)}")
|
|
82
98
|
if (old.get("x"), old.get("y")) != (new.get("x"), new.get("y")) and old and new:
|
|
83
|
-
return f"移動{_name(after)}"
|
|
99
|
+
return tr(f"移動{_name(after)}", f"Moved {_name(after)}")
|
|
84
100
|
if old.get("scale", 1) != new.get("scale", 1):
|
|
85
|
-
|
|
101
|
+
larger = new.get("scale", 1) > old.get("scale", 1)
|
|
102
|
+
return tr(
|
|
103
|
+
f"{'放大' if larger else '縮小'}{_name(after)}",
|
|
104
|
+
f"Made {_name(after)} {'larger' if larger else 'smaller'}",
|
|
105
|
+
)
|
|
86
106
|
if old.get("colors") != new.get("colors"):
|
|
87
|
-
return f"換了{_name(after)}的顏色"
|
|
107
|
+
return tr(f"換了{_name(after)}的顏色", f"Changed the colours of {_name(after)}")
|
|
88
108
|
if old.get("visual_style_id") != new.get("visual_style_id"):
|
|
89
|
-
return f"{_name(after)}換了樣式"
|
|
109
|
+
return tr(f"{_name(after)}換了樣式", f"Changed the style of {_name(after)}")
|
|
90
110
|
if old.get("font_style_id") != new.get("font_style_id"):
|
|
91
|
-
return f"{_name(after)}換了字體"
|
|
111
|
+
return tr(f"{_name(after)}換了字體", f"Changed the fonts of {_name(after)}")
|
|
92
112
|
if (old.get("start_offset_frames"), old.get("anchor_item_id")) == (
|
|
93
113
|
new.get("start_offset_frames"),
|
|
94
114
|
new.get("anchor_item_id"),
|
|
95
115
|
) and not recut:
|
|
96
|
-
return f"調整{_name(after)}"
|
|
116
|
+
return tr(f"調整{_name(after)}", f"Adjusted {_name(after)}")
|
|
97
117
|
# After a new cut every graphic shifts with its shot; that is part of the cut, not news of its own.
|
|
98
118
|
if not recut and (before["start_frame"], before["duration_frames"]) != (
|
|
99
119
|
after["start_frame"],
|
|
100
120
|
after["duration_frames"],
|
|
101
121
|
):
|
|
102
|
-
return f"調整{_name(after)}出現的時間"
|
|
122
|
+
return tr(f"調整{_name(after)}出現的時間", f"Retimed {_name(after)}")
|
|
103
123
|
return None
|
|
104
124
|
|
|
105
125
|
|
|
@@ -115,15 +135,14 @@ def describe(before, after, styles=None):
|
|
|
115
135
|
(i["start_frame"], i["duration_frames"], i.get("source")) for i in new_cut
|
|
116
136
|
]:
|
|
117
137
|
if before["duration_frames"] != after["duration_frames"]:
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
138
|
+
lengths = f"{_clock(before['duration_frames'], before)} → {_clock(after['duration_frames'], after)}"
|
|
139
|
+
changes.append(tr(f"重新剪輯,片長 {lengths}", f"Recut, length {lengths}"))
|
|
121
140
|
else:
|
|
122
|
-
changes.append("調整剪輯")
|
|
141
|
+
changes.append(tr("調整剪輯", "Adjusted the cut"))
|
|
123
142
|
elif [[e for e in i.get("effects", []) if not e.get("effect_id", "").startswith("audio.")] for i in old_cut] != [
|
|
124
143
|
[e for e in i.get("effects", []) if not e.get("effect_id", "").startswith("audio.")] for i in new_cut
|
|
125
144
|
]:
|
|
126
|
-
changes.append("調整畫面效果或轉場")
|
|
145
|
+
changes.append(tr("調整畫面效果或轉場", "Adjusted effects or transitions"))
|
|
127
146
|
|
|
128
147
|
def music(cut):
|
|
129
148
|
return sorted(
|
|
@@ -149,18 +168,18 @@ def describe(before, after, styles=None):
|
|
|
149
168
|
|
|
150
169
|
# A new cut moves the music with it; only a different song, or new levels on the same cut, is news.
|
|
151
170
|
if music(old_cut) != music(new_cut):
|
|
152
|
-
changes.append("換了配樂")
|
|
171
|
+
changes.append(tr("換了配樂", "Changed the music"))
|
|
153
172
|
elif not changes and (
|
|
154
173
|
sound(old_cut) != sound(new_cut)
|
|
155
174
|
or [e for i in old_cut for e in i.get("effects", []) if e.get("effect_id") == "audio.layers"]
|
|
156
175
|
!= [e for i in new_cut for e in i.get("effects", []) if e.get("effect_id") == "audio.layers"]
|
|
157
176
|
):
|
|
158
|
-
changes.append("調整配樂或聲音")
|
|
177
|
+
changes.append(tr("調整配樂或聲音", "Adjusted the music or sound"))
|
|
159
178
|
old, new = _components(before), _components(after)
|
|
160
179
|
for key in new.keys() - old.keys():
|
|
161
|
-
changes.append(f"新增{_name(new[key])}")
|
|
180
|
+
changes.append(tr(f"新增{_name(new[key])}", f"Added {_name(new[key])}"))
|
|
162
181
|
for key in old.keys() - new.keys():
|
|
163
|
-
changes.append(f"刪除{_name(old[key])}")
|
|
182
|
+
changes.append(tr(f"刪除{_name(old[key])}", f"Removed {_name(old[key])}"))
|
|
164
183
|
looks = {}
|
|
165
184
|
for key in sorted(old.keys() & new.keys(), key=lambda k: new[k]["start_frame"]):
|
|
166
185
|
sentence = _graphic_change(old[key], new[key], styles, recut)
|
|
@@ -168,12 +187,17 @@ def describe(before, after, styles=None):
|
|
|
168
187
|
_, name, fonts, colours = sentence
|
|
169
188
|
if name not in looks:
|
|
170
189
|
looks[name] = True
|
|
171
|
-
|
|
172
|
-
|
|
190
|
+
what = (
|
|
191
|
+
tr("字型和配色", "fonts and colours")
|
|
192
|
+
if fonts and colours
|
|
193
|
+
else tr("字型", "fonts")
|
|
194
|
+
if fonts
|
|
195
|
+
else tr("配色", "colours")
|
|
173
196
|
)
|
|
197
|
+
changes.append(tr(f"換了「{name}」外觀的{what}", f"Changed the {what} of the “{name}” look"))
|
|
174
198
|
continue
|
|
175
199
|
if sentence is None and not recut and _lanes(before)[key] != _lanes(after)[key]:
|
|
176
|
-
sentence = f"把{_name(new[key])}移到另一軌"
|
|
200
|
+
sentence = tr(f"把{_name(new[key])}移到另一軌", f"Moved {_name(new[key])} to another lane")
|
|
177
201
|
if sentence:
|
|
178
202
|
changes.append(sentence)
|
|
179
203
|
old_subtitles, new_subtitles = _subtitles(before), _subtitles(after)
|
|
@@ -181,12 +205,17 @@ def describe(before, after, styles=None):
|
|
|
181
205
|
changed = len(old_subtitles.keys() ^ new_subtitles.keys()) + sum(
|
|
182
206
|
old_subtitles[k] != new_subtitles[k] for k in old_subtitles.keys() & new_subtitles.keys()
|
|
183
207
|
)
|
|
184
|
-
changes.append(
|
|
208
|
+
changes.append(
|
|
209
|
+
tr(f"修改 {changed} 句字幕", f"Changed {changed} {'caption' if changed == 1 else 'captions'}")
|
|
210
|
+
if changed
|
|
211
|
+
else tr("調整字幕", "Adjusted the captions")
|
|
212
|
+
)
|
|
185
213
|
return changes
|
|
186
214
|
|
|
187
215
|
|
|
188
216
|
def summary(changes, limit=2):
|
|
189
217
|
if not changes:
|
|
190
218
|
return None
|
|
191
|
-
shown = "、".join(changes[:limit])
|
|
192
|
-
|
|
219
|
+
shown = tr("、", ", ").join(changes[:limit])
|
|
220
|
+
more = len(changes) - limit
|
|
221
|
+
return shown + (tr(f",還有 {more} 處", f", and {more} more") if more > 0 else "")
|
|
@@ -255,6 +255,11 @@ EXTRA_TOOLS = (
|
|
|
255
255
|
"additionalProperties": False,
|
|
256
256
|
},
|
|
257
257
|
"delivery": {"enum": ["dialogue", "punchline", "quiet"]},
|
|
258
|
+
"design_id": {
|
|
259
|
+
"type": "string",
|
|
260
|
+
"maxLength": 80,
|
|
261
|
+
"description": "A caption design from set_caption_design; default the latest.",
|
|
262
|
+
},
|
|
258
263
|
"emphasis": {
|
|
259
264
|
"type": "array",
|
|
260
265
|
"items": {"type": "string", "minLength": 1, "maxLength": 16},
|
|
@@ -310,14 +315,23 @@ EXTRA_TOOLS = (
|
|
|
310
315
|
),
|
|
311
316
|
schema(
|
|
312
317
|
"set_color_grade",
|
|
313
|
-
"
|
|
318
|
+
"Grade one clip: contrast, saturation, brightness and gamma; colour temperature (-1 cool to 1 warm) and tint (-1 magenta to 1 green); "
|
|
319
|
+
"shadows and highlights (-1 darker to 1 lighter); vignette and film grain (0-1). Leave out what you do not change; neutral values remove the grade.",
|
|
314
320
|
{
|
|
315
321
|
"item_id": ID,
|
|
316
322
|
"contrast": {"type": "number", "minimum": 0.5, "maximum": 2},
|
|
317
323
|
"saturation": {"type": "number", "minimum": 0, "maximum": 2},
|
|
318
324
|
"brightness": {"type": "number", "minimum": -0.3, "maximum": 0.3},
|
|
325
|
+
"gamma": {"type": "number", "minimum": 0.5, "maximum": 2},
|
|
326
|
+
"temperature": {"type": "number", "minimum": -1, "maximum": 1},
|
|
327
|
+
"tint": {"type": "number", "minimum": -1, "maximum": 1},
|
|
328
|
+
"shadows": {"type": "number", "minimum": -1, "maximum": 1},
|
|
329
|
+
"highlights": {"type": "number", "minimum": -1, "maximum": 1},
|
|
330
|
+
"vignette": {"type": "number", "minimum": 0, "maximum": 1},
|
|
331
|
+
"grain": {"type": "number", "minimum": 0, "maximum": 1},
|
|
319
332
|
**SUMMARY,
|
|
320
333
|
},
|
|
334
|
+
["item_id", "summary"],
|
|
321
335
|
),
|
|
322
336
|
schema(
|
|
323
337
|
"set_mosaic",
|
|
@@ -426,19 +440,32 @@ EXTRA_TOOLS = (
|
|
|
426
440
|
"Save native editable timeline JSON and source/license credits for the current revision. This is not a Resolve project.",
|
|
427
441
|
),
|
|
428
442
|
)
|
|
443
|
+
CAPTION_DESIGN_HELP = (
|
|
444
|
+
"Design how every caption of the film looks, as one self-contained web page (HTML, CSS, SVG, JS), before replace_subtitles; "
|
|
445
|
+
"there is no built-in caption style. Put one element with data-clipen-caption where the words go: Clipen fills it with each "
|
|
446
|
+
"caption's words, its emphasis words wrapped in <em>, and sets data-delivery on <html> to dialogue, punchline or quiet, so "
|
|
447
|
+
"style em and [data-delivery=punchline] / [data-delivery=quiet] yourself. The page is the whole picture; draw only the caption "
|
|
448
|
+
"and keep the rest transparent; place and style it however the film calls for. Any typeface works, as for graphics (installed, "
|
|
449
|
+
"carried, or fetched with get_font); look_id is optional. Motion: by default Clipen draws the first entry_frames and the last "
|
|
450
|
+
"exit_frames (0-60 each) and one still frame between, so render stays fast; set throughout: true to let it move on every frame. "
|
|
451
|
+
"--clipen-duration (seconds) lets an exit start at var(--clipen-duration) minus its length. A new design restyles every caption "
|
|
452
|
+
"on the film unless apply_to_existing is false; each design gets a design_id, and replace_subtitles rows may pick one per caption "
|
|
453
|
+
"with design_id, so a film may use several. Render and watch them."
|
|
454
|
+
)
|
|
429
455
|
CUSTOM_COMPONENT_HELP = (
|
|
430
456
|
"Design an in-picture graphic freely as one self-contained web page: any HTML, CSS, SVG, Canvas or JavaScript, any layout, "
|
|
431
|
-
"typeface, colour, shape or motion.
|
|
457
|
+
"typeface, colour, shape or motion. Every graphic in the film is made this way; there are no built-in components. "
|
|
432
458
|
"The page is the whole picture (window.clipen.width x window.clipen.height pixels, e.g. 1920x1080); draw only the graphic and leave "
|
|
433
459
|
"the rest transparent, so the footage shows through. Clipen sets the time: CSS animations and the Web Animations API play by "
|
|
434
460
|
"themselves, frame-accurately; for script-driven drawing define window.clipenFrame = (frame, seconds) => {...} (may be async) "
|
|
435
461
|
"and draw that exact frame there. requestAnimationFrame loops, timers and real clocks do not advance. Frame 0 is the first frame "
|
|
436
462
|
"of the graphic; window.clipen also gives fps and durationFrames. The page has no network: inline everything (data: URLs, inline SVG). "
|
|
437
|
-
"
|
|
438
|
-
"
|
|
439
|
-
"
|
|
440
|
-
"
|
|
441
|
-
"
|
|
463
|
+
"Type: use any typeface by its name: every font installed on this Mac, the fonts Clipen carries, and any open font from "
|
|
464
|
+
"Google Fonts once you fetch it with get_font (then font-family: '<its name>'). Looks are optional: graphics of one kind may share a look "
|
|
465
|
+
"made with set_component_look (pass look_id; Clipen gives its fonts and colours as var(--look-font-<key>) and var(--look-<key>), and every "
|
|
466
|
+
"graphic using it follows its changes), or a page may set its own type and colour. A graphic may run across a cut: a full-picture design "
|
|
467
|
+
"that covers the cut is a transition of your own design (set_transition only offers dips). Only technical checks apply: the page must load, run without "
|
|
468
|
+
"errors, draw each frame within 10 seconds, draw something, and stay under 2 MB. The result returns two images: a still of the graphic at rest over the footage, and a sheet of frames from entry to exit (labelled by frame number), so you can judge the motion; look at both and fix what does not read. "
|
|
442
469
|
'Mark what people may change themselves: put each main wording as plain text in an element with data-clipen-text="key" '
|
|
443
470
|
'(optional data-clipen-label="主標"), and declare main colours as :root custom properties named --clipen-<name> (e.g. --clipen-主色) used via var(). '
|
|
444
471
|
"Their changes are applied before your scripts run; split text into letters on DOMContentLoaded or later, from the element's current text."
|
|
@@ -457,10 +484,10 @@ CUSTOM_COMPONENT_FIELDS = {
|
|
|
457
484
|
"maxLength": 40,
|
|
458
485
|
"description": "Short label people see on the timeline, e.g. 澀谷地標標題.",
|
|
459
486
|
},
|
|
460
|
-
"html": {"type": "string", "minLength": 1, "maxLength":
|
|
487
|
+
"html": {"type": "string", "minLength": 1, "maxLength": 2000000},
|
|
461
488
|
"look_id": {
|
|
462
489
|
**ID,
|
|
463
|
-
"description": "
|
|
490
|
+
"description": "Optional: a shared look (typefaces and colours) from set_component_look.",
|
|
464
491
|
},
|
|
465
492
|
"evidence": TEXT,
|
|
466
493
|
**SUMMARY,
|
|
@@ -469,9 +496,8 @@ LOOK_KEY = {"type": "string", "minLength": 1, "maxLength": 24}
|
|
|
469
496
|
LOOK_HELP = (
|
|
470
497
|
"Create or change a look: a named set of typefaces and colours that graphics of one kind share (e.g. a chapter look, a place look, "
|
|
471
498
|
"a reaction look). Design each look for its role; looks may differ completely. Pages use the look through CSS variables: "
|
|
472
|
-
"font-family: var(--look-font-<key>) and color var(--look-<key>). Graphics already using this look_id are redrawn with it
|
|
473
|
-
"
|
|
474
|
-
"(system fonts, plus fonts Clipen carries: Chinese handwriting 'Clipen Chenyu' and brush 'Clipen Iansui', Japanese handwriting "
|
|
499
|
+
"font-family: var(--look-font-<key>) and color var(--look-<key>). Graphics already using this look_id are redrawn with it. A typeface may be any font "
|
|
500
|
+
"installed on this Mac, any open font fetched with get_font, or one Clipen carries (list_program_components lists them; carried: Chinese handwriting 'Clipen Chenyu' and brush 'Clipen Iansui', Japanese handwriting "
|
|
475
501
|
"'Yusei Magic', 'Yomogi', 'Zen Kurenaido', 'Hachi Maru Pop', Japanese display 'Dela Gothic One', 'RocknRoll One', 'Zen Maru Gothic', "
|
|
476
502
|
"Latin 'Bebas Neue', 'Anton', 'Caveat', 'Playfair Display'). When a typeface lacks a Chinese or Japanese character the graphic "
|
|
477
503
|
"shows, that font key draws all its Chinese and Japanese in the next face of the same feel that has them all (Clipen Chenyu "
|
|
@@ -536,11 +562,39 @@ SKILL_TOOLS = (
|
|
|
536
562
|
},
|
|
537
563
|
["look_id", "name", "fonts", "summary"],
|
|
538
564
|
),
|
|
565
|
+
schema(
|
|
566
|
+
"get_font",
|
|
567
|
+
"Fetch an open-licensed font family from Google Fonts by its exact name (e.g. 'Noto Serif TC', 'LXGW WenKai TC', 'Bricolage Grotesque') "
|
|
568
|
+
"so graphics and captions can use it as font-family: '<name>'. Clipen downloads it once, checks it is OFL, Apache or UFL licensed, "
|
|
569
|
+
"and keeps it on this Mac; pages stay offline. Fonts installed on the Mac need no fetching.",
|
|
570
|
+
{"family": {"type": "string", "minLength": 1, "maxLength": 60}},
|
|
571
|
+
["family"],
|
|
572
|
+
),
|
|
573
|
+
schema(
|
|
574
|
+
"set_caption_design",
|
|
575
|
+
CAPTION_DESIGN_HELP,
|
|
576
|
+
{
|
|
577
|
+
"html": {"type": "string", "minLength": 1, "maxLength": 2000000},
|
|
578
|
+
"look_id": ID,
|
|
579
|
+
"entry_frames": {"type": "integer", "minimum": 0, "maximum": 60},
|
|
580
|
+
"exit_frames": {"type": "integer", "minimum": 0, "maximum": 60},
|
|
581
|
+
"throughout": {
|
|
582
|
+
"type": "boolean",
|
|
583
|
+
"description": "true: the caption may move on every frame (slower to render).",
|
|
584
|
+
},
|
|
585
|
+
"apply_to_existing": {
|
|
586
|
+
"type": "boolean",
|
|
587
|
+
"description": "false: keep the captions already on the film as they are; default true.",
|
|
588
|
+
},
|
|
589
|
+
**SUMMARY,
|
|
590
|
+
},
|
|
591
|
+
["html", "summary"],
|
|
592
|
+
),
|
|
539
593
|
schema(
|
|
540
594
|
"add_custom_component",
|
|
541
595
|
CUSTOM_COMPONENT_HELP,
|
|
542
596
|
CUSTOM_COMPONENT_FIELDS,
|
|
543
|
-
["element_id", "item_id", "start_offset_frames", "duration_frames", "name", "html", "
|
|
597
|
+
["element_id", "item_id", "start_offset_frames", "duration_frames", "name", "html", "summary"],
|
|
544
598
|
),
|
|
545
599
|
schema(
|
|
546
600
|
"update_custom_component",
|