@clipen/clipen-cli 1.0.8 → 1.0.10
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 +57 -39
- package/README.zh-TW.md +98 -0
- package/apps/web/dist/assets/index-BHFCflzf.js +15 -0
- package/apps/web/dist/assets/index-BtenOBwP.css +1 -0
- package/apps/web/dist/favicon.svg +1 -1
- package/apps/web/dist/index.html +2 -2
- package/bin/clipen.js +10 -17
- package/package.json +2 -2
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/annotations/suggestions.py +1 -1
- package/src/clipen/bootstrap.py +190 -28
- package/src/clipen/controller/app.py +185 -22
- package/src/clipen/controller/server.py +19 -6
- package/src/clipen/editing/agent_repository.py +29 -3
- package/src/clipen/editing/agent_tools.py +2 -1
- package/src/clipen/editing/aspect.py +27 -0
- package/src/clipen/editing/caption_design.py +134 -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 +14 -0
- package/src/clipen/editing/production_catalog.py +77 -16
- package/src/clipen/editing/production_media.py +14 -3
- package/src/clipen/editing/production_preview.py +18 -9
- package/src/clipen/editing/production_progress.py +2 -0
- package/src/clipen/editing/production_tools.py +18 -22
- 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 +150 -218
- package/src/clipen/editing/slip.py +109 -0
- package/src/clipen/editing/tool_receipts.py +3 -1
- package/src/clipen/editing/versions.py +4 -0
- package/src/clipen/editing/visual_preview.py +73 -3
- package/src/clipen/editing/workbench.py +53 -1
- package/src/clipen/locale_en.py +36 -0
- package/src/clipen/mcp_editing/server.py +3 -1
- package/src/clipen/media/discovery.py +2 -2
- package/src/clipen/media/preview.py +5 -0
- package/src/clipen/media/storage.py +5 -2
- package/src/clipen/own_ffmpeg.py +113 -0
- package/src/clipen/projects/models.py +2 -0
- package/src/clipen/projects/storage.py +84 -4
- package/src/clipen/providers/account.py +37 -6
- package/src/clipen/providers/claude.py +5 -3
- package/src/clipen/providers/claude_editing.py +5 -6
- package/src/clipen/providers/codex.py +19 -7
- package/src/clipen/providers/codex_editing.py +2 -1
- package/src/clipen/providers/editing_agent.py +30 -6
- package/src/clipen/providers/model_selection.py +67 -0
- package/src/clipen/rendering/cover.py +1 -1
- 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/program_subtitles.py +3 -1
- package/src/clipen/rendering/renderer.py +36 -20
- 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/references/captions.md +12 -0
- package/src/clipen/skills/builtin/references/graphics.md +7 -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/builtin/templates.json +9 -0
- package/src/clipen/skills/catalog.py +0 -8
- package/src/clipen/skills/package.py +1 -10
- package/apps/web/dist/assets/index-CJ80KHsQ.css +0 -1
- package/apps/web/dist/assets/index-C_4u_hVf.js +0 -16
- package/src/clipen/editing/EDITORIAL_REGRESSIONS.md +0 -38
- package/src/clipen/editing/REFACTOR_DESIGN.md +0 -241
- package/src/clipen/editing/REFACTOR_HANDOFF.md +0 -73
- 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
|
@@ -42,6 +42,7 @@ from clipen.projects import ProjectWorkspace
|
|
|
42
42
|
from clipen.provider_registry import exec_adapter_factory
|
|
43
43
|
from clipen.providers import CodexExecAdapter, ProviderUnavailable
|
|
44
44
|
from clipen.providers.claude import ClaudeCliAdapter
|
|
45
|
+
from clipen.rendering import PreviewRenderRepository
|
|
45
46
|
from clipen.terminal import Terminal, display_width
|
|
46
47
|
|
|
47
48
|
from .app import (
|
|
@@ -165,28 +166,35 @@ class ServerPaths:
|
|
|
165
166
|
def provider_account(provider_id: str, attempt_root: Path, ttl: float = 60.0) -> Callable[[], dict]:
|
|
166
167
|
"""A cached, read-only lookup of the running model and remaining quota."""
|
|
167
168
|
from clipen.providers.account import claude_account, codex_account
|
|
169
|
+
from clipen.providers.model_selection import CLAUDE_MODELS, selected_model
|
|
168
170
|
|
|
169
171
|
lock, cache = threading.Lock(), {}
|
|
170
172
|
|
|
171
|
-
def lookup() -> dict:
|
|
173
|
+
def lookup(selection: str | None) -> dict:
|
|
172
174
|
if provider_id == "claude":
|
|
173
175
|
from clipen.providers.claude import claude_environment
|
|
174
176
|
|
|
175
|
-
return
|
|
177
|
+
return {
|
|
178
|
+
**claude_account(attempt_root, claude_environment(), model_override=selection),
|
|
179
|
+
"models": [{"id": model, "name": name} for model, name in CLAUDE_MODELS.items()],
|
|
180
|
+
}
|
|
176
181
|
if provider_id != "codex":
|
|
177
182
|
return {"model": None, "quota": None}
|
|
178
183
|
try:
|
|
179
184
|
adapter = CodexExecAdapter(attempt_root)
|
|
180
185
|
except ProviderUnavailable:
|
|
181
186
|
return {"model": None, "quota": None}
|
|
182
|
-
return codex_account(adapter.binary, adapter._environment)
|
|
187
|
+
return codex_account(adapter.binary, adapter._environment, model_override=selection, include_models=True)
|
|
183
188
|
|
|
184
189
|
def cached() -> dict:
|
|
190
|
+
selection = selected_model(attempt_root, provider_id)
|
|
191
|
+
if provider_id == "claude":
|
|
192
|
+
return {**lookup(selection), "selected_model": selection}
|
|
185
193
|
with lock:
|
|
186
|
-
if cache and time.monotonic() - cache["at"] < ttl:
|
|
194
|
+
if cache and cache["selection"] == selection and time.monotonic() - cache["at"] < ttl:
|
|
187
195
|
return cache["value"]
|
|
188
|
-
value = lookup()
|
|
189
|
-
cache.update(at=time.monotonic(), value=value)
|
|
196
|
+
value = {**lookup(selection), "selected_model": selection}
|
|
197
|
+
cache.update(at=time.monotonic(), value=value, selection=selection)
|
|
190
198
|
return value
|
|
191
199
|
|
|
192
200
|
return cached
|
|
@@ -425,8 +433,12 @@ async def _serve(
|
|
|
425
433
|
)
|
|
426
434
|
evidence_service.recover()
|
|
427
435
|
preparation_repository = PreparationRepository(workspace.repository)
|
|
436
|
+
# A film left rendering when Clipen last stopped has no process behind it any more; left
|
|
437
|
+
# as running, the page would wait on it forever and newer saves would never render.
|
|
438
|
+
renders = PreviewRenderRepository(workspace.repository)
|
|
428
439
|
for project in workspace.repository.list_projects():
|
|
429
440
|
preparation_repository.interrupt_incomplete(project.project_id)
|
|
441
|
+
renders.interrupt_incomplete(project.project_id)
|
|
430
442
|
if paths.asr_requirements is not None:
|
|
431
443
|
analysis_runtime = ManagedAnalysisRuntime(
|
|
432
444
|
preparation_repository,
|
|
@@ -454,6 +466,7 @@ async def _serve(
|
|
|
454
466
|
media_previews=media_previews,
|
|
455
467
|
edit_agents=edit_agents,
|
|
456
468
|
provider_account=provider_account(provider.provider_id, paths.attempt_root),
|
|
469
|
+
provider_model_root=paths.attempt_root,
|
|
457
470
|
)
|
|
458
471
|
config = uvicorn.Config(
|
|
459
472
|
app,
|
|
@@ -64,6 +64,7 @@ class EditAgentRepository:
|
|
|
64
64
|
"target_duration_seconds",
|
|
65
65
|
"music_asset_id",
|
|
66
66
|
"template_id",
|
|
67
|
+
"aspect_ratio",
|
|
67
68
|
}
|
|
68
69
|
):
|
|
69
70
|
raise ProjectError("production_input_invalid", "請選擇剪輯樣板並填寫影片需求。", status_code=422)
|
|
@@ -102,6 +103,10 @@ class EditAgentRepository:
|
|
|
102
103
|
# The template skill was chosen directly; keep its design brief in the intent.
|
|
103
104
|
template = skill["template"]
|
|
104
105
|
skill["selected_template_id"] = template["template_id"]
|
|
106
|
+
from .aspect import DEFAULT_ASPECT, canvas, checked
|
|
107
|
+
|
|
108
|
+
# The shape is chosen with the film; a template suggests one (short-form is vertical).
|
|
109
|
+
aspect = checked(production.get("aspect_ratio", (template or {}).get("aspect_ratio", DEFAULT_ASPECT)))
|
|
105
110
|
target = production.get("target_duration_seconds", skill.get("default_duration_seconds", 60))
|
|
106
111
|
if isinstance(target, bool) or not isinstance(target, int) or not 30 <= target <= 1200:
|
|
107
112
|
raise ProjectError("production_input_invalid", "預計片長必須為 30 到 1200 秒。", status_code=422)
|
|
@@ -121,6 +126,7 @@ class EditAgentRepository:
|
|
|
121
126
|
**({"font_style_id": selected_font} if font_supplied else {}),
|
|
122
127
|
**({"target_duration_seconds": target} if "target_duration_seconds" in production else {}),
|
|
123
128
|
**({"music_asset_id": production["music_asset_id"]} if "music_asset_id" in production else {}),
|
|
129
|
+
**({"aspect_ratio": aspect} if "aspect_ratio" in production else {}),
|
|
124
130
|
}
|
|
125
131
|
creative_direction = {**PROGRAM_DIRECTION, "production_requirements": FULL_PRODUCTION_REQUIREMENTS}
|
|
126
132
|
creative_direction = validate_direction(creative_direction)
|
|
@@ -186,8 +192,7 @@ class EditAgentRepository:
|
|
|
186
192
|
None,
|
|
187
193
|
None,
|
|
188
194
|
Rational(30, 1),
|
|
189
|
-
|
|
190
|
-
720,
|
|
195
|
+
*canvas(aspect),
|
|
191
196
|
0,
|
|
192
197
|
(Track("video-main", TrackKind.VIDEO, ()),),
|
|
193
198
|
production_session_id=run_id,
|
|
@@ -231,6 +236,7 @@ class EditAgentRepository:
|
|
|
231
236
|
"visual_style_id": selected,
|
|
232
237
|
"font_style_id": selected_font,
|
|
233
238
|
"target_duration_seconds": target,
|
|
239
|
+
"aspect_ratio": aspect,
|
|
234
240
|
"music_choice": selected_music,
|
|
235
241
|
# The AI writes in the language of the person who asked.
|
|
236
242
|
**({"language": "en"} if english() else {}),
|
|
@@ -357,6 +363,7 @@ class EditAgentRepository:
|
|
|
357
363
|
expected_references_version=None,
|
|
358
364
|
provider=None,
|
|
359
365
|
):
|
|
366
|
+
from .production_media import source_rows
|
|
360
367
|
from .refinement_references import hand_over, public_state, references
|
|
361
368
|
from .workbench import music_choice
|
|
362
369
|
|
|
@@ -378,6 +385,8 @@ class EditAgentRepository:
|
|
|
378
385
|
**({"provider": provider} if provider is not None else {}),
|
|
379
386
|
}
|
|
380
387
|
)
|
|
388
|
+
# Footage checked since the film began (added later, or new in the footage folder) joins it now.
|
|
389
|
+
checked = source_rows(self.projects, project_id)
|
|
381
390
|
with self.projects.connect(project_id) as db:
|
|
382
391
|
db.execute("BEGIN IMMEDIATE")
|
|
383
392
|
receipt = db.execute("SELECT * FROM edit_agent_command_receipts WHERE request_id=?", (request,)).fetchone()
|
|
@@ -394,7 +403,9 @@ class EditAgentRepository:
|
|
|
394
403
|
raise ProjectError("edit_agent_busy", "請先停止目前的 AI 製作。", status_code=409)
|
|
395
404
|
if run.current_revision_id != expected_revision_id:
|
|
396
405
|
raise ProjectError("revision_conflict", "影片已更新,請重新讀取後提出修改。", status_code=409)
|
|
397
|
-
session = db.execute(
|
|
406
|
+
session = db.execute(
|
|
407
|
+
"SELECT intent_json, sources_json FROM production_sessions WHERE run_id=?", (normalized,)
|
|
408
|
+
).fetchone()
|
|
398
409
|
if session is None:
|
|
399
410
|
raise ProjectError("production_required", "這個版本不支援持續修訂。", status_code=422)
|
|
400
411
|
intent = json.loads(session["intent_json"])
|
|
@@ -412,6 +423,21 @@ class EditAgentRepository:
|
|
|
412
423
|
"created_at": utc_now(),
|
|
413
424
|
"references": reference_snapshot,
|
|
414
425
|
}
|
|
426
|
+
# Footage the film has not had yet is granted, kept beside every source it already uses,
|
|
427
|
+
# and named for the AI so it decides whether and where it belongs.
|
|
428
|
+
granted = json.loads(session["sources_json"])
|
|
429
|
+
held = {(s["version_id"], s["stream_index"]) for s in granted}
|
|
430
|
+
arrived = [s for s in checked if (s["version_id"], s["stream_index"]) not in held]
|
|
431
|
+
if arrived:
|
|
432
|
+
inventory = db.execute("SELECT run_id FROM current_inventory WHERE slot=1").fetchone()
|
|
433
|
+
db.execute(
|
|
434
|
+
"UPDATE production_sessions SET sources_json=?, inventory_run_id=? WHERE run_id=?",
|
|
435
|
+
(encoded(granted + arrived), inventory["run_id"], normalized),
|
|
436
|
+
)
|
|
437
|
+
intent["latest_revision_request"]["new_sources"] = [
|
|
438
|
+
{k: s[k] for k in ("version_id", "stream_index", "display_name", "kind", "duration_seconds")}
|
|
439
|
+
for s in arrived
|
|
440
|
+
]
|
|
415
441
|
# What the last change left for the person goes with the next request, so it is not lost.
|
|
416
442
|
from .change_report import carried
|
|
417
443
|
|
|
@@ -72,8 +72,9 @@ class EditAgentTools(SkillTools, EvidenceTools, ProductionTools):
|
|
|
72
72
|
if getattr(self, "_user_edit", False):
|
|
73
73
|
# Only a person can reword a graphic directly; the AI revises through its own component tools.
|
|
74
74
|
handlers["edit_component"] = self._edit_component
|
|
75
|
-
handlers["set_component_text"] = self._edit_component
|
|
76
75
|
handlers["edit_component_look"] = self._edit_component_look
|
|
76
|
+
handlers["edit_caption"] = self._edit_caption
|
|
77
|
+
handlers["slip_clip"] = self._slip_clip
|
|
77
78
|
handler = (lambda args: self.production_call(name, args)) if name in EXTRA_NAMES else handlers.get(name)
|
|
78
79
|
if handler is None:
|
|
79
80
|
raise ProjectError("tool_not_allowed", "這個工具未獲 Clipen 授權。", status_code=404)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""A film's shape, chosen when it is set up and kept for every revision."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from clipen.projects import ProjectError
|
|
6
|
+
|
|
7
|
+
ASPECT_RATIOS = {"16:9": (16, 9), "9:16": (9, 16), "1:1": (1, 1), "4:5": (4, 5)}
|
|
8
|
+
DEFAULT_ASPECT = "16:9"
|
|
9
|
+
# The sizes a preview may use, by the length of its shorter side.
|
|
10
|
+
SHORT_SIDES = (360, 720, 1080)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def checked(aspect: object) -> str:
|
|
14
|
+
if aspect not in ASPECT_RATIOS:
|
|
15
|
+
raise ProjectError("production_input_invalid", "畫面比例必須是 16:9、9:16、1:1 或 4:5。", status_code=422)
|
|
16
|
+
return str(aspect)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def canvas(aspect: str, short_side: int = 720) -> tuple[int, int]:
|
|
20
|
+
"""Width and height for the shape, its shorter side short_side pixels, both even."""
|
|
21
|
+
across, down = ASPECT_RATIOS[aspect]
|
|
22
|
+
long_side = round(short_side * max(across, down) / min(across, down) / 2) * 2
|
|
23
|
+
return (long_side, short_side) if across >= down else (short_side, long_side)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def aspect_of(width: int, height: int) -> str | None:
|
|
27
|
+
return next((name for name, (a, d) in ASPECT_RATIOS.items() if width * d == height * a), None)
|
|
@@ -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})
|
|
@@ -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]
|
|
@@ -382,6 +382,10 @@ class EditAgentCoordinator:
|
|
|
382
382
|
def workbench_render(self, project_id, run_id, expected_revision_id):
|
|
383
383
|
from .workbench import idle, tools_for
|
|
384
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)
|
|
385
389
|
with self._lock:
|
|
386
390
|
run = idle(self.repository, project_id, run_id)
|
|
387
391
|
if run.current_revision_id != expected_revision_id:
|
|
@@ -395,6 +399,16 @@ class EditAgentCoordinator:
|
|
|
395
399
|
del tools._session_cache
|
|
396
400
|
return tools.production_call("render_preview", {}).payload
|
|
397
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
|
+
|
|
398
412
|
def resume(self, project_id: str, run_id: str, consent: object) -> AgentRun:
|
|
399
413
|
if consent is not True:
|
|
400
414
|
raise ProjectError(
|
|
@@ -129,8 +129,15 @@ EXTRA_TOOLS = (
|
|
|
129
129
|
),
|
|
130
130
|
schema(
|
|
131
131
|
"set_canvas",
|
|
132
|
-
"Choose a bounded SDR preview canvas before styling
|
|
133
|
-
|
|
132
|
+
"Choose a bounded SDR preview canvas before styling, in the film's shape (intent.aspect_ratio: 16:9, 9:16, 1:1 or 4:5; "
|
|
133
|
+
"the person chose it and it cannot change). Sizes by the shorter side: 360, 720 or 1080 pixels, e.g. 1280x720 for 16:9, "
|
|
134
|
+
"720x1280 for 9:16, 720x720 for 1:1, 720x900 for 4:5. Changes the revision and invalidates previous render review; "
|
|
135
|
+
"source media and timing remain intact.",
|
|
136
|
+
{
|
|
137
|
+
"width": {"type": "integer", "minimum": 360, "maximum": 1920},
|
|
138
|
+
"height": {"type": "integer", "minimum": 360, "maximum": 1920},
|
|
139
|
+
**SUMMARY,
|
|
140
|
+
},
|
|
134
141
|
),
|
|
135
142
|
schema(
|
|
136
143
|
"set_target_duration",
|
|
@@ -255,6 +262,11 @@ EXTRA_TOOLS = (
|
|
|
255
262
|
"additionalProperties": False,
|
|
256
263
|
},
|
|
257
264
|
"delivery": {"enum": ["dialogue", "punchline", "quiet"]},
|
|
265
|
+
"design_id": {
|
|
266
|
+
"type": "string",
|
|
267
|
+
"maxLength": 80,
|
|
268
|
+
"description": "A caption design from set_caption_design; default the latest.",
|
|
269
|
+
},
|
|
258
270
|
"emphasis": {
|
|
259
271
|
"type": "array",
|
|
260
272
|
"items": {"type": "string", "minLength": 1, "maxLength": 16},
|
|
@@ -310,14 +322,23 @@ EXTRA_TOOLS = (
|
|
|
310
322
|
),
|
|
311
323
|
schema(
|
|
312
324
|
"set_color_grade",
|
|
313
|
-
"
|
|
325
|
+
"Grade one clip: contrast, saturation, brightness and gamma; colour temperature (-1 cool to 1 warm) and tint (-1 magenta to 1 green); "
|
|
326
|
+
"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
327
|
{
|
|
315
328
|
"item_id": ID,
|
|
316
329
|
"contrast": {"type": "number", "minimum": 0.5, "maximum": 2},
|
|
317
330
|
"saturation": {"type": "number", "minimum": 0, "maximum": 2},
|
|
318
331
|
"brightness": {"type": "number", "minimum": -0.3, "maximum": 0.3},
|
|
332
|
+
"gamma": {"type": "number", "minimum": 0.5, "maximum": 2},
|
|
333
|
+
"temperature": {"type": "number", "minimum": -1, "maximum": 1},
|
|
334
|
+
"tint": {"type": "number", "minimum": -1, "maximum": 1},
|
|
335
|
+
"shadows": {"type": "number", "minimum": -1, "maximum": 1},
|
|
336
|
+
"highlights": {"type": "number", "minimum": -1, "maximum": 1},
|
|
337
|
+
"vignette": {"type": "number", "minimum": 0, "maximum": 1},
|
|
338
|
+
"grain": {"type": "number", "minimum": 0, "maximum": 1},
|
|
319
339
|
**SUMMARY,
|
|
320
340
|
},
|
|
341
|
+
["item_id", "summary"],
|
|
321
342
|
),
|
|
322
343
|
schema(
|
|
323
344
|
"set_mosaic",
|
|
@@ -426,19 +447,32 @@ EXTRA_TOOLS = (
|
|
|
426
447
|
"Save native editable timeline JSON and source/license credits for the current revision. This is not a Resolve project.",
|
|
427
448
|
),
|
|
428
449
|
)
|
|
450
|
+
CAPTION_DESIGN_HELP = (
|
|
451
|
+
"Design how every caption of the film looks, as one self-contained web page (HTML, CSS, SVG, JS), before replace_subtitles; "
|
|
452
|
+
"there is no built-in caption style. Put one element with data-clipen-caption where the words go: Clipen fills it with each "
|
|
453
|
+
"caption's words, its emphasis words wrapped in <em>, and sets data-delivery on <html> to dialogue, punchline or quiet, so "
|
|
454
|
+
"style em and [data-delivery=punchline] / [data-delivery=quiet] yourself. The page is the whole picture; draw only the caption "
|
|
455
|
+
"and keep the rest transparent; place and style it however the film calls for. Any typeface works, as for graphics (installed, "
|
|
456
|
+
"carried, or fetched with get_font); look_id is optional. Motion: by default Clipen draws the first entry_frames and the last "
|
|
457
|
+
"exit_frames (0-60 each) and one still frame between, so render stays fast; set throughout: true to let it move on every frame. "
|
|
458
|
+
"--clipen-duration (seconds) lets an exit start at var(--clipen-duration) minus its length. A new design restyles every caption "
|
|
459
|
+
"on the film unless apply_to_existing is false; each design gets a design_id, and replace_subtitles rows may pick one per caption "
|
|
460
|
+
"with design_id, so a film may use several. Render and watch them."
|
|
461
|
+
)
|
|
429
462
|
CUSTOM_COMPONENT_HELP = (
|
|
430
463
|
"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.
|
|
432
|
-
"The page is the whole picture (window.clipen.width x window.clipen.height pixels, e.g. 1920x1080); draw only the graphic and leave "
|
|
464
|
+
"typeface, colour, shape or motion. Every graphic in the film is made this way; there are no built-in components. "
|
|
465
|
+
"The page is the whole picture (window.clipen.width x window.clipen.height pixels in the film's shape, e.g. 1920x1080 for 16:9, 1080x1920 for 9:16); draw only the graphic and leave "
|
|
433
466
|
"the rest transparent, so the footage shows through. Clipen sets the time: CSS animations and the Web Animations API play by "
|
|
434
467
|
"themselves, frame-accurately; for script-driven drawing define window.clipenFrame = (frame, seconds) => {...} (may be async) "
|
|
435
468
|
"and draw that exact frame there. requestAnimationFrame loops, timers and real clocks do not advance. Frame 0 is the first frame "
|
|
436
469
|
"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
|
-
"
|
|
470
|
+
"Type: use any typeface by its name: every font installed on this Mac, the fonts Clipen carries, and any open font from "
|
|
471
|
+
"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 "
|
|
472
|
+
"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 "
|
|
473
|
+
"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 "
|
|
474
|
+
"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 "
|
|
475
|
+
"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
476
|
'Mark what people may change themselves: put each main wording as plain text in an element with data-clipen-text="key" '
|
|
443
477
|
'(optional data-clipen-label="主標"), and declare main colours as :root custom properties named --clipen-<name> (e.g. --clipen-主色) used via var(). '
|
|
444
478
|
"Their changes are applied before your scripts run; split text into letters on DOMContentLoaded or later, from the element's current text."
|
|
@@ -457,10 +491,10 @@ CUSTOM_COMPONENT_FIELDS = {
|
|
|
457
491
|
"maxLength": 40,
|
|
458
492
|
"description": "Short label people see on the timeline, e.g. 澀谷地標標題.",
|
|
459
493
|
},
|
|
460
|
-
"html": {"type": "string", "minLength": 1, "maxLength":
|
|
494
|
+
"html": {"type": "string", "minLength": 1, "maxLength": 2000000},
|
|
461
495
|
"look_id": {
|
|
462
496
|
**ID,
|
|
463
|
-
"description": "
|
|
497
|
+
"description": "Optional: a shared look (typefaces and colours) from set_component_look.",
|
|
464
498
|
},
|
|
465
499
|
"evidence": TEXT,
|
|
466
500
|
**SUMMARY,
|
|
@@ -469,9 +503,8 @@ LOOK_KEY = {"type": "string", "minLength": 1, "maxLength": 24}
|
|
|
469
503
|
LOOK_HELP = (
|
|
470
504
|
"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
505
|
"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 "
|
|
506
|
+
"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 "
|
|
507
|
+
"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
508
|
"'Yusei Magic', 'Yomogi', 'Zen Kurenaido', 'Hachi Maru Pop', Japanese display 'Dela Gothic One', 'RocknRoll One', 'Zen Maru Gothic', "
|
|
476
509
|
"Latin 'Bebas Neue', 'Anton', 'Caveat', 'Playfair Display'). When a typeface lacks a Chinese or Japanese character the graphic "
|
|
477
510
|
"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 +569,39 @@ SKILL_TOOLS = (
|
|
|
536
569
|
},
|
|
537
570
|
["look_id", "name", "fonts", "summary"],
|
|
538
571
|
),
|
|
572
|
+
schema(
|
|
573
|
+
"get_font",
|
|
574
|
+
"Fetch an open-licensed font family from Google Fonts by its exact name (e.g. 'Noto Serif TC', 'LXGW WenKai TC', 'Bricolage Grotesque') "
|
|
575
|
+
"so graphics and captions can use it as font-family: '<name>'. Clipen downloads it once, checks it is OFL, Apache or UFL licensed, "
|
|
576
|
+
"and keeps it on this Mac; pages stay offline. Fonts installed on the Mac need no fetching.",
|
|
577
|
+
{"family": {"type": "string", "minLength": 1, "maxLength": 60}},
|
|
578
|
+
["family"],
|
|
579
|
+
),
|
|
580
|
+
schema(
|
|
581
|
+
"set_caption_design",
|
|
582
|
+
CAPTION_DESIGN_HELP,
|
|
583
|
+
{
|
|
584
|
+
"html": {"type": "string", "minLength": 1, "maxLength": 2000000},
|
|
585
|
+
"look_id": ID,
|
|
586
|
+
"entry_frames": {"type": "integer", "minimum": 0, "maximum": 60},
|
|
587
|
+
"exit_frames": {"type": "integer", "minimum": 0, "maximum": 60},
|
|
588
|
+
"throughout": {
|
|
589
|
+
"type": "boolean",
|
|
590
|
+
"description": "true: the caption may move on every frame (slower to render).",
|
|
591
|
+
},
|
|
592
|
+
"apply_to_existing": {
|
|
593
|
+
"type": "boolean",
|
|
594
|
+
"description": "false: keep the captions already on the film as they are; default true.",
|
|
595
|
+
},
|
|
596
|
+
**SUMMARY,
|
|
597
|
+
},
|
|
598
|
+
["html", "summary"],
|
|
599
|
+
),
|
|
539
600
|
schema(
|
|
540
601
|
"add_custom_component",
|
|
541
602
|
CUSTOM_COMPONENT_HELP,
|
|
542
603
|
CUSTOM_COMPONENT_FIELDS,
|
|
543
|
-
["element_id", "item_id", "start_offset_frames", "duration_frames", "name", "html", "
|
|
604
|
+
["element_id", "item_id", "start_offset_frames", "duration_frames", "name", "html", "summary"],
|
|
544
605
|
),
|
|
545
606
|
schema(
|
|
546
607
|
"update_custom_component",
|