@clipen/clipen-cli 1.0.8 → 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 +13 -4
- 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 +6 -15
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/bootstrap.py +130 -23
- package/src/clipen/controller/app.py +83 -21
- package/src/clipen/controller/server.py +5 -0
- package/src/clipen/editing/agent_tools.py +1 -1
- 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 +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 +2 -0
- 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 +2 -0
- package/src/clipen/editing/visual_preview.py +62 -0
- package/src/clipen/editing/workbench.py +21 -1
- package/src/clipen/locale_en.py +18 -0
- package/src/clipen/media/storage.py +2 -2
- package/src/clipen/own_ffmpeg.py +113 -0
- package/src/clipen/providers/editing_agent.py +6 -4
- 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/references/captions.md +12 -0
- package/src/clipen/skills/builtin/references/graphics.md +6 -5
- 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 +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/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
|
@@ -8,12 +8,10 @@ from dataclasses import dataclass, replace
|
|
|
8
8
|
from clipen.domain import TextClip, Track, TrackKind
|
|
9
9
|
from clipen.projects import ProjectError
|
|
10
10
|
from clipen.skills import list_skills
|
|
11
|
-
from clipen.skills.visual_styles import font_presets, public_font_styles, public_styles, style_presets
|
|
12
11
|
|
|
13
12
|
from .agent_models import ToolResult
|
|
14
13
|
|
|
15
14
|
# The colours a person may change on a graphic: its accent, its light and its dark colour.
|
|
16
|
-
COMPONENT_COLORS = frozenset({"accent", "paper", "ink"})
|
|
17
15
|
|
|
18
16
|
|
|
19
17
|
@dataclass(frozen=True)
|
|
@@ -119,6 +117,7 @@ class SkillTools:
|
|
|
119
117
|
|
|
120
118
|
def _production_list_program_components(self, args):
|
|
121
119
|
"""How graphics are made now, the looks they share, and the ones already in the film."""
|
|
120
|
+
from clipen.rendering import fetched_fonts
|
|
122
121
|
from clipen.rendering.custom_components import FONT_CHOICES
|
|
123
122
|
|
|
124
123
|
from . import component_looks
|
|
@@ -150,20 +149,24 @@ class SkillTools:
|
|
|
150
149
|
"existing_graphics": existing,
|
|
151
150
|
"looks": component_looks.listing(self),
|
|
152
151
|
"font_choices": [{"family": family, "label": label} for family, label in FONT_CHOICES.items()],
|
|
153
|
-
"
|
|
154
|
-
|
|
152
|
+
"fonts": {
|
|
153
|
+
"carried_and_suggested": "font_choices above",
|
|
154
|
+
"fetched": sorted(fetched_fonts.available()),
|
|
155
|
+
"anything_else": "any font installed on this Mac by name, or any open Google Fonts family after get_font",
|
|
156
|
+
},
|
|
157
|
+
"older_graphics": "Graphics not designed_freely use retired built-in templates; they are no longer drawn and cannot be "
|
|
158
|
+
"changed. Remove them with remove_program_component, and design a new one with add_custom_component where the film needs it.",
|
|
155
159
|
}
|
|
156
160
|
)
|
|
157
161
|
|
|
158
|
-
def _component_draft(self, args):
|
|
162
|
+
def _component_draft(self, args, *, checked=True):
|
|
159
163
|
"""A programme graphic as a person's changes would leave it, checked but not saved.
|
|
160
164
|
|
|
161
|
-
args holds element_id plus any of
|
|
162
|
-
|
|
163
|
-
|
|
165
|
+
args holds element_id plus any of texts, colors, x, y, look_id, start_offset_frames and
|
|
166
|
+
duration_frames; anything left out keeps its current value. frames are more frames of a free design to draw
|
|
167
|
+
in the same Chrome run as its check, for a preview that will want them; checked=False skips
|
|
168
|
+
that Chrome run, for the page that plays the design live in the person's own browser.
|
|
164
169
|
Returns the changed clip, its style profile and the clip as it is now."""
|
|
165
|
-
from clipen.finishing.models import digest
|
|
166
|
-
|
|
167
170
|
from .production_media import load_text_styles
|
|
168
171
|
|
|
169
172
|
if not isinstance(args, dict) or not isinstance(args.get("element_id"), str):
|
|
@@ -188,114 +191,15 @@ class SkillTools:
|
|
|
188
191
|
raise ProjectError(
|
|
189
192
|
"component_not_found", "找不到這個畫面元件,影片可能已經更新,請重新讀取。", status_code=404
|
|
190
193
|
)
|
|
191
|
-
if profile.get("component_id")
|
|
192
|
-
return self._custom_draft(args, timeline, item, profile)
|
|
193
|
-
saved_text, _, saved_detail = item.text.partition("\n")
|
|
194
|
-
text, detail = args.get("text", saved_text), args.get("detail", saved_detail)
|
|
195
|
-
if not isinstance(text, str) or not isinstance(detail, str):
|
|
196
|
-
raise ProjectError("agent_input_invalid", "元件文字格式不正確。", status_code=422)
|
|
197
|
-
text, detail = text.strip(), detail.strip()
|
|
198
|
-
if not text:
|
|
199
|
-
raise ProjectError("component_text_empty", "元件的主要文字不能空白。", status_code=422)
|
|
200
|
-
if "\n" in text or "\n" in detail:
|
|
194
|
+
if profile.get("component_id") != "custom":
|
|
201
195
|
raise ProjectError(
|
|
202
|
-
"
|
|
203
|
-
|
|
204
|
-
skill = self._skill_value()
|
|
205
|
-
component = next((c for c in skill["components"] if c["component_id"] == profile.get("component_id")), None)
|
|
206
|
-
limit = component["max_characters"] if component else 48
|
|
207
|
-
if len(text) > limit or len(detail) > 48:
|
|
208
|
-
raise ProjectError(
|
|
209
|
-
"component_text_overflow",
|
|
210
|
-
f"這個元件的主要文字最多 {limit} 個字,補充文字最多 48 個字。",
|
|
196
|
+
"component_retired",
|
|
197
|
+
"這個元件用的是已停用的內建模板,不能再修改;刪掉它,或請 AI 重新設計一個。",
|
|
211
198
|
status_code=422,
|
|
212
199
|
)
|
|
200
|
+
return self._custom_draft(args, timeline, item, profile, checked)
|
|
213
201
|
|
|
214
|
-
|
|
215
|
-
value = args.get(key, profile.get(key))
|
|
216
|
-
if isinstance(value, bool) or not isinstance(value, (int, float)) or not low <= value <= high:
|
|
217
|
-
raise ProjectError("component_unsafe_position", "元件要留在畫面裡。", status_code=422)
|
|
218
|
-
return round(float(value), 4)
|
|
219
|
-
|
|
220
|
-
x, y = number("x", 0, 0.95), number("y", 0, 0.95)
|
|
221
|
-
shot, start, duration = self._component_time(args, item, profile)
|
|
222
|
-
visual_style, presets = style_presets(skill, args.get("visual_style_id", profile.get("visual_style_id")))
|
|
223
|
-
font_style, presets = font_presets(skill, presets, args.get("font_style_id", profile.get("font_style_id")))
|
|
224
|
-
scale = args.get("scale", profile.get("scale", 1))
|
|
225
|
-
if isinstance(scale, bool) or not isinstance(scale, (int, float)) or not 0.6 <= scale <= 1.6:
|
|
226
|
-
raise ProjectError("component_scale_invalid", "元件大小要在 60% 到 160% 之間。", status_code=422)
|
|
227
|
-
colors = args.get("colors", profile.get("colors", {}))
|
|
228
|
-
if (
|
|
229
|
-
not isinstance(colors, dict)
|
|
230
|
-
or not set(colors) <= COMPONENT_COLORS
|
|
231
|
-
or not all(
|
|
232
|
-
isinstance(v, str) and len(v) == 7 and v[0] == "#" and all(c in "0123456789abcdefABCDEF" for c in v[1:])
|
|
233
|
-
for v in colors.values()
|
|
234
|
-
)
|
|
235
|
-
):
|
|
236
|
-
raise ProjectError("component_color_invalid", "顏色格式不正確。", status_code=422)
|
|
237
|
-
# A person's colours replace the style's, keeping each colour's own transparency.
|
|
238
|
-
for name, value in colors.items():
|
|
239
|
-
presets["palette"][name] = [
|
|
240
|
-
int(value[1:3], 16),
|
|
241
|
-
int(value[3:5], 16),
|
|
242
|
-
int(value[5:7], 16),
|
|
243
|
-
presets["palette"][name][3],
|
|
244
|
-
]
|
|
245
|
-
changed_profile = {key: value for key, value in profile.items() if key not in {"scale", "colors"}}
|
|
246
|
-
changed_profile.update(
|
|
247
|
-
{
|
|
248
|
-
"presets": presets,
|
|
249
|
-
"visual_style_id": visual_style,
|
|
250
|
-
"font_style_id": font_style,
|
|
251
|
-
"x": x,
|
|
252
|
-
"y": y,
|
|
253
|
-
"anchor_item_id": shot.item_id,
|
|
254
|
-
"start_offset_frames": start,
|
|
255
|
-
}
|
|
256
|
-
)
|
|
257
|
-
# Designed size and the style's colours are left out, so untouched graphics keep their identity.
|
|
258
|
-
if round(float(scale), 2) != 1:
|
|
259
|
-
changed_profile["scale"] = round(float(scale), 2)
|
|
260
|
-
if colors:
|
|
261
|
-
changed_profile["colors"] = {name: value.lower() for name, value in sorted(colors.items())}
|
|
262
|
-
style_id = "agent.component." + digest(changed_profile)[:24]
|
|
263
|
-
draft = replace(
|
|
264
|
-
item,
|
|
265
|
-
text=text + ("\n" + detail if detail else ""),
|
|
266
|
-
start_frame=shot.start_frame + start,
|
|
267
|
-
duration_frames=duration,
|
|
268
|
-
style_id=style_id,
|
|
269
|
-
)
|
|
270
|
-
from PIL import Image, ImageDraw
|
|
271
|
-
|
|
272
|
-
from clipen.rendering.program_components import draw_program_component
|
|
273
|
-
from clipen.rendering.titles import TitleCardRenderer, TitleRenderError
|
|
274
|
-
|
|
275
|
-
font = TitleCardRenderer._font_path()
|
|
276
|
-
if font is None:
|
|
277
|
-
raise ProjectError("preview_title_font_missing", "缺少可用的中文字型。", status_code=409)
|
|
278
|
-
try:
|
|
279
|
-
draw_program_component(
|
|
280
|
-
ImageDraw.Draw(Image.new("RGBA", (timeline.width, timeline.height))),
|
|
281
|
-
font,
|
|
282
|
-
timeline,
|
|
283
|
-
draft,
|
|
284
|
-
changed_profile,
|
|
285
|
-
8,
|
|
286
|
-
)
|
|
287
|
-
except TitleRenderError as error:
|
|
288
|
-
message = (
|
|
289
|
-
"這套字型無法顯示部分字元,請換個寫法或換字體。"
|
|
290
|
-
if error.code == "program_component_missing_glyph"
|
|
291
|
-
else "缺少這套字型,請換一套字體。"
|
|
292
|
-
if error.code == "program_font_unavailable"
|
|
293
|
-
else "元件超出畫面了,請縮小一點、縮短文字或往左上移。"
|
|
294
|
-
)
|
|
295
|
-
raise ProjectError(error.code, message, status_code=422) from error
|
|
296
|
-
return draft, changed_profile, item
|
|
297
|
-
|
|
298
|
-
def _custom_draft(self, args, timeline, item, profile):
|
|
202
|
+
def _custom_draft(self, args, timeline, item, profile, checked=True):
|
|
299
203
|
"""A free design as a person's move or retime would leave it: x, y shift the whole page."""
|
|
300
204
|
from clipen.finishing.models import digest
|
|
301
205
|
from clipen.rendering import custom_components
|
|
@@ -365,20 +269,72 @@ class SkillTools:
|
|
|
365
269
|
duration_frames=duration,
|
|
366
270
|
style_id="agent.component." + digest(changed)[:24],
|
|
367
271
|
)
|
|
272
|
+
if not checked:
|
|
273
|
+
return draft, changed, item
|
|
368
274
|
try:
|
|
369
275
|
custom_components.check(timeline, draft, changed)
|
|
370
|
-
if changed.get("look") != profile.get("look"):
|
|
371
|
-
custom_components.check_fonts(timeline, draft, changed)
|
|
372
276
|
except custom_components.CustomRenderError as error:
|
|
373
|
-
if error.code == "custom_component_font_outside_look":
|
|
374
|
-
raise ProjectError(
|
|
375
|
-
error.code,
|
|
376
|
-
f"這個元件的設計用了「{changed['look']['name']}」外觀沒有的字型({error.detail}),換不過去;請交給 AI 改。",
|
|
377
|
-
status_code=422,
|
|
378
|
-
) from error
|
|
379
277
|
raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
|
|
380
278
|
return draft, changed, item
|
|
381
279
|
|
|
280
|
+
def _caption_draft(self, args):
|
|
281
|
+
"""A caption as a person's correction would leave it: its words, delivery and emphasis."""
|
|
282
|
+
from clipen.finishing.models import digest
|
|
283
|
+
|
|
284
|
+
from .production_media import load_text_styles
|
|
285
|
+
|
|
286
|
+
item = next(
|
|
287
|
+
(
|
|
288
|
+
i
|
|
289
|
+
for t in self._timeline().tracks
|
|
290
|
+
if t.track_id == "agent-subtitles"
|
|
291
|
+
for i in t.items
|
|
292
|
+
if i.item_id == args.get("element_id")
|
|
293
|
+
),
|
|
294
|
+
None,
|
|
295
|
+
)
|
|
296
|
+
if item is None:
|
|
297
|
+
raise ProjectError("caption_not_found", "找不到這句字幕,影片可能已經更新,請重新讀取。", status_code=404)
|
|
298
|
+
text = args.get("text", item.text)
|
|
299
|
+
if not isinstance(text, str) or not text.strip() or len(text.strip()) > 80 or "\n" in text:
|
|
300
|
+
raise ProjectError("caption_text_invalid", "字幕要是一行、1–80 個字。", status_code=422)
|
|
301
|
+
text = text.strip()
|
|
302
|
+
profile = load_text_styles(self.repository.projects, self.project_id).get(item.style_id, {})
|
|
303
|
+
if profile.get("kind") != "program_subtitle":
|
|
304
|
+
return replace(item, text=text), None
|
|
305
|
+
delivery = args.get("delivery", profile.get("delivery", "dialogue"))
|
|
306
|
+
if delivery not in {"dialogue", "punchline", "quiet"}:
|
|
307
|
+
raise ProjectError("caption_delivery_invalid", "語氣只能是一般對話、重點句或小聲帶過。", status_code=422)
|
|
308
|
+
emphasis = args.get("emphasis", profile.get("emphasis", []))
|
|
309
|
+
if not isinstance(emphasis, list) or not all(isinstance(w, str) for w in emphasis):
|
|
310
|
+
raise ProjectError("caption_emphasis_invalid", "強調的字要是字串清單。", status_code=422)
|
|
311
|
+
emphasis = [w.strip() for w in emphasis if w.strip() and w.strip() in text][:4]
|
|
312
|
+
changed = {**profile, "delivery": delivery, "emphasis": emphasis}
|
|
313
|
+
if text != item.text:
|
|
314
|
+
# A person's own wording: what they heard, taking over from the draft transcript.
|
|
315
|
+
changed.update({"caption_text_edited": True, "wording_authority": "user", "verification": "user_corrected"})
|
|
316
|
+
return replace(item, text=text, style_id="agent.text." + digest(changed)[:24]), changed
|
|
317
|
+
|
|
318
|
+
def _edit_caption(self, args):
|
|
319
|
+
"""A person corrects one caption: its words, how it is delivered, which words stand out."""
|
|
320
|
+
from .production_media import atomic_json, load_text_styles, text_style_path
|
|
321
|
+
|
|
322
|
+
draft, profile = self._caption_draft(args)
|
|
323
|
+
current = next(i for t in self._timeline().tracks for i in t.items if i.item_id == draft.item_id)
|
|
324
|
+
if (draft.text, draft.style_id) == (current.text, current.style_id):
|
|
325
|
+
raise ProjectError("caption_unchanged", "沒有任何變動。", status_code=422)
|
|
326
|
+
if profile is not None:
|
|
327
|
+
styles = load_text_styles(self.repository.projects, self.project_id)
|
|
328
|
+
styles[draft.style_id] = profile
|
|
329
|
+
atomic_json(text_style_path(self.repository.projects, self.project_id), styles)
|
|
330
|
+
tracks = tuple(
|
|
331
|
+
replace(t, items=tuple(draft if i.item_id == draft.item_id else i for i in t.items))
|
|
332
|
+
if t.track_id == "agent-subtitles"
|
|
333
|
+
else t
|
|
334
|
+
for t in self._timeline().tracks
|
|
335
|
+
)
|
|
336
|
+
return self._save(replace(self._timeline(), tracks=tracks), args.get("summary") or "使用者修改字幕")
|
|
337
|
+
|
|
382
338
|
def _edit_component(self, args):
|
|
383
339
|
"""A person changes one programme graphic: wording, place, look, typeface or timing."""
|
|
384
340
|
from .production_media import atomic_json, load_text_styles, text_style_path
|
|
@@ -403,6 +359,29 @@ class SkillTools:
|
|
|
403
359
|
atomic_json(text_style_path(self.repository.projects, self.project_id), styles)
|
|
404
360
|
return self._save(replace(self._timeline(), tracks=tracks), args.get("summary") or "使用者修改元件")
|
|
405
361
|
|
|
362
|
+
def _production_get_font(self, args):
|
|
363
|
+
"""Fetch an open font from Google Fonts so pages can use it by name."""
|
|
364
|
+
from clipen.rendering import fetched_fonts
|
|
365
|
+
|
|
366
|
+
try:
|
|
367
|
+
entry = fetched_fonts.fetch(args["family"])
|
|
368
|
+
except fetched_fonts.FontUnavailable as error:
|
|
369
|
+
raise ProjectError("font_unavailable", str(error), status_code=422) from error
|
|
370
|
+
return ToolResult(
|
|
371
|
+
{
|
|
372
|
+
"family": entry["family"],
|
|
373
|
+
"license": entry["license"],
|
|
374
|
+
"source": entry["source"],
|
|
375
|
+
"use": f"font-family: '{entry['family']}'",
|
|
376
|
+
"note": "Check that it has every character your text needs; a missing character falls back to another face.",
|
|
377
|
+
}
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
def _production_set_caption_design(self, args):
|
|
381
|
+
from . import caption_design
|
|
382
|
+
|
|
383
|
+
return caption_design.apply(self, args)
|
|
384
|
+
|
|
406
385
|
def _production_set_component_look(self, args):
|
|
407
386
|
"""The Agent creates or changes a look; graphics already using it follow."""
|
|
408
387
|
from . import component_looks
|
|
@@ -440,7 +419,6 @@ class SkillTools:
|
|
|
440
419
|
def _apply_look(self, look, summary):
|
|
441
420
|
"""Save a look and redraw every graphic that uses it; refused if one would then need a typeface the look lacks."""
|
|
442
421
|
from clipen.finishing.models import digest
|
|
443
|
-
from clipen.rendering import custom_components
|
|
444
422
|
|
|
445
423
|
from . import component_looks
|
|
446
424
|
from .production_media import atomic_json, load_text_styles, text_style_path
|
|
@@ -453,27 +431,12 @@ class SkillTools:
|
|
|
453
431
|
status_code=422,
|
|
454
432
|
)
|
|
455
433
|
timeline = self._timeline()
|
|
456
|
-
changed
|
|
434
|
+
changed = {}
|
|
457
435
|
for item, profile in component_looks.on_film(self, timeline):
|
|
458
436
|
if (profile.get("look") or {}).get("look_id") != look["look_id"] or profile["look"] == look:
|
|
459
437
|
continue
|
|
460
438
|
updated = {**profile, "look": look}
|
|
461
|
-
|
|
462
|
-
try:
|
|
463
|
-
custom_components.check_fonts(timeline, draft, updated)
|
|
464
|
-
except custom_components.CustomRenderError as error:
|
|
465
|
-
if error.code != "custom_component_font_outside_look":
|
|
466
|
-
raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
|
|
467
|
-
problems.append(f"「{item.text}」({error.detail})")
|
|
468
|
-
changed[item.item_id] = (draft, updated)
|
|
469
|
-
if problems:
|
|
470
|
-
raise ProjectError(
|
|
471
|
-
"custom_component_font_outside_look",
|
|
472
|
-
"改了之後,這些元件會用到外觀以外的字型:"
|
|
473
|
-
+ "、".join(problems)
|
|
474
|
-
+ "。保留它們用到的字型 key,或先更新這些元件。",
|
|
475
|
-
status_code=422,
|
|
476
|
-
)
|
|
439
|
+
changed[item.item_id] = (replace(item, style_id="agent.component." + digest(updated)[:24]), updated)
|
|
477
440
|
looks[look["look_id"]] = look
|
|
478
441
|
component_looks.store(self, looks)
|
|
479
442
|
public = component_looks.public(look, len(changed))
|
|
@@ -557,65 +520,44 @@ class SkillTools:
|
|
|
557
520
|
)
|
|
558
521
|
|
|
559
522
|
def _component_editing(self):
|
|
560
|
-
"""What the review page needs to edit graphics: each
|
|
523
|
+
"""What the review page needs to edit graphics: each free design's settings and the run's looks.
|
|
524
|
+
|
|
525
|
+
Graphics left from the retired built-in templates are not listed; they are no longer drawn."""
|
|
526
|
+
from clipen.rendering.custom_components import FONT_CHOICES
|
|
527
|
+
|
|
528
|
+
from . import component_looks
|
|
561
529
|
from .production_media import load_text_styles
|
|
562
530
|
|
|
563
|
-
skill = self._skill_value()
|
|
564
531
|
styles = load_text_styles(self.repository.projects, self.project_id)
|
|
565
532
|
shots = {i.item_id: i for i in self._video().items}
|
|
566
|
-
limits = {c["component_id"]: c["max_characters"] for c in skill["components"]}
|
|
567
|
-
names = {c["component_id"]: c.get("name", c["component_id"]) for c in skill["components"]}
|
|
568
533
|
result = {}
|
|
569
|
-
for track in self.
|
|
570
|
-
if not (track.track_id == "program-components" or track.track_id.startswith("program-components-")):
|
|
571
|
-
continue
|
|
534
|
+
for track in self._component_tracks():
|
|
572
535
|
for item in track.items:
|
|
573
536
|
profile = styles.get(item.style_id, {})
|
|
574
537
|
shot = shots.get(profile.get("anchor_item_id"))
|
|
575
|
-
if
|
|
538
|
+
if (
|
|
539
|
+
profile.get("kind") != "program_component"
|
|
540
|
+
or profile.get("component_id") != "custom"
|
|
541
|
+
or shot is None
|
|
542
|
+
):
|
|
576
543
|
continue
|
|
577
|
-
custom = profile["component_id"] == "custom"
|
|
578
544
|
result[item.item_id] = {
|
|
579
|
-
"
|
|
580
|
-
"custom": custom,
|
|
581
|
-
"name": item.text if custom else names.get(profile["component_id"], profile["component_id"]),
|
|
582
|
-
"max_characters": limits.get(profile["component_id"], 48),
|
|
545
|
+
"name": item.text,
|
|
583
546
|
"x": profile.get("x"),
|
|
584
547
|
"y": profile.get("y"),
|
|
585
|
-
"
|
|
586
|
-
"
|
|
587
|
-
"
|
|
588
|
-
"colors": profile.get("colors", {}),
|
|
589
|
-
**(
|
|
590
|
-
{
|
|
591
|
-
"fields": profile.get("fields") or {"texts": [], "colors": []},
|
|
592
|
-
"edits": profile.get("edits") or {},
|
|
593
|
-
"look_id": (profile.get("look") or {}).get("look_id"),
|
|
594
|
-
}
|
|
595
|
-
if custom
|
|
596
|
-
else {}
|
|
597
|
-
),
|
|
548
|
+
"fields": profile.get("fields") or {"texts": [], "colors": []},
|
|
549
|
+
"edits": profile.get("edits") or {},
|
|
550
|
+
"look_id": (profile.get("look") or {}).get("look_id"),
|
|
598
551
|
"shot_start_frame": shot.start_frame,
|
|
599
552
|
"shot_duration_frames": shot.duration_frames,
|
|
600
553
|
}
|
|
554
|
+
from clipen.rendering import fetched_fonts
|
|
601
555
|
|
|
602
|
-
|
|
603
|
-
colours = style_presets(skill, identifier)[1]["palette"]
|
|
604
|
-
return {name: "#%02x%02x%02x" % tuple(colours[name][:3]) for name in sorted(COMPONENT_COLORS)}
|
|
605
|
-
|
|
606
|
-
from clipen.rendering.custom_components import FONT_CHOICES
|
|
607
|
-
|
|
608
|
-
from . import component_looks
|
|
609
|
-
|
|
556
|
+
fetched = {family: f"{family}(Google Fonts)" for family in fetched_fonts.available()}
|
|
610
557
|
return {
|
|
611
558
|
"looks": component_looks.listing(self),
|
|
612
|
-
"font_choices": [{"family": f, "label": l} for f, l in FONT_CHOICES.items()],
|
|
559
|
+
"font_choices": [{"family": f, "label": l} for f, l in {**FONT_CHOICES, **fetched}.items()],
|
|
613
560
|
"components": result,
|
|
614
|
-
"visual_styles": [
|
|
615
|
-
{"id": v["visual_style_id"], "name": v["name"], "colors": palette(v["visual_style_id"])}
|
|
616
|
-
for v in public_styles(skill)
|
|
617
|
-
],
|
|
618
|
-
"font_styles": [{"id": f["font_style_id"], "name": f["name"]} for f in public_font_styles(skill)],
|
|
619
561
|
}
|
|
620
562
|
|
|
621
563
|
def _component_issues(self):
|
|
@@ -644,6 +586,16 @@ class SkillTools:
|
|
|
644
586
|
if profile.get("kind") != "program_component" or anchor is None:
|
|
645
587
|
issues.append({"code": "component_anchor_missing", "item_id": element.item_id})
|
|
646
588
|
continue
|
|
589
|
+
if profile.get("component_id") != "custom":
|
|
590
|
+
issues.append(
|
|
591
|
+
{
|
|
592
|
+
"code": "component_retired",
|
|
593
|
+
"item_id": element.item_id,
|
|
594
|
+
"advisory": True,
|
|
595
|
+
"message": "這個元件用的是已停用的內建模板,不會出現在影片裡;用 remove_program_component 刪掉,需要的話重新設計一個。",
|
|
596
|
+
}
|
|
597
|
+
)
|
|
598
|
+
continue
|
|
647
599
|
if (
|
|
648
600
|
not anchor.start_frame <= element.start_frame < anchor.start_frame + anchor.duration_frames
|
|
649
601
|
or element.start_frame + element.duration_frames > timeline.duration_frames
|
|
@@ -660,26 +612,6 @@ class SkillTools:
|
|
|
660
612
|
boxes.append((element, box))
|
|
661
613
|
except TitleRenderError as error:
|
|
662
614
|
issues.append({"code": error.code, "item_id": element.item_id})
|
|
663
|
-
# Subtitles may be rebuilt after a graphic was placed; recheck the pair here.
|
|
664
|
-
from .component_review import RESTATE_RATIO, concurrent_subtitles, restated_ratio
|
|
665
|
-
|
|
666
|
-
if (
|
|
667
|
-
profile.get("authority") != "user"
|
|
668
|
-
and profile.get("component_id") != "custom"
|
|
669
|
-
and restated_ratio(
|
|
670
|
-
element.text.partition("\n")[0],
|
|
671
|
-
concurrent_subtitles(timeline, element.start_frame, element.duration_frames),
|
|
672
|
-
)
|
|
673
|
-
>= RESTATE_RATIO
|
|
674
|
-
):
|
|
675
|
-
issues.append(
|
|
676
|
-
{
|
|
677
|
-
"code": "component_restates_subtitle",
|
|
678
|
-
"item_id": element.item_id,
|
|
679
|
-
"advisory": True,
|
|
680
|
-
"message": "元件文字和同時出現的字幕大部分重複;不是刻意強調的話可以改寫。",
|
|
681
|
-
}
|
|
682
|
-
)
|
|
683
615
|
for n, (a, left) in enumerate(boxes):
|
|
684
616
|
for b, right in boxes[n + 1 :]:
|
|
685
617
|
if (
|
|
@@ -771,21 +703,17 @@ class SkillTools:
|
|
|
771
703
|
}
|
|
772
704
|
from . import component_looks
|
|
773
705
|
|
|
706
|
+
# A look is optional: graphics of one kind may share one, or a page may set its own type and colour.
|
|
774
707
|
look_id = args.get("look_id") or (previous.get("look") or {}).get("look_id")
|
|
775
|
-
if
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
"component_look_not_found",
|
|
785
|
-
"沒有這個外觀;先用 set_component_look 建立,或從 list_program_components 的 looks 選一個。",
|
|
786
|
-
status_code=422,
|
|
787
|
-
)
|
|
788
|
-
profile["look"] = look
|
|
708
|
+
if look_id:
|
|
709
|
+
look = component_looks.current(self).get(look_id)
|
|
710
|
+
if look is None:
|
|
711
|
+
raise ProjectError(
|
|
712
|
+
"component_look_not_found",
|
|
713
|
+
"沒有這個外觀;先用 set_component_look 建立,或從 list_program_components 的 looks 選一個。",
|
|
714
|
+
status_code=422,
|
|
715
|
+
)
|
|
716
|
+
profile["look"] = look
|
|
789
717
|
item = TextClip(
|
|
790
718
|
args["element_id"],
|
|
791
719
|
shot.start_frame + settings["start_offset_frames"],
|
|
@@ -812,7 +740,6 @@ class SkillTools:
|
|
|
812
740
|
profile["edits"] = {kind: values for kind, values in keep.items() if values}
|
|
813
741
|
item = replace(item, style_id="agent.component." + digest(profile)[:24])
|
|
814
742
|
custom_components.check(timeline, item, profile)
|
|
815
|
-
custom_components.check_fonts(timeline, item, profile)
|
|
816
743
|
except custom_components.CustomRenderError as error:
|
|
817
744
|
raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
|
|
818
745
|
styles[item.style_id] = profile
|
|
@@ -939,9 +866,6 @@ def _custom_problem(error):
|
|
|
939
866
|
"custom_component_script_error": "頁面的程式出錯" + detail + "。",
|
|
940
867
|
"custom_component_frame_timeout": "有一格超過 10 秒還沒畫完;clipenFrame 要能直接畫出指定的那一格。",
|
|
941
868
|
"custom_component_renderer_missing": "這台電腦沒有可用的 Chrome,無法繪製自由元件" + detail + "。",
|
|
942
|
-
"custom_component_font_outside_look": "頁面用了外觀以外的字型"
|
|
943
|
-
+ detail
|
|
944
|
-
+ ";文字的字型要寫成 var(--look-font-鍵名)。想換字或加一套字,先用 set_component_look 改外觀。",
|
|
945
869
|
}.get(error.code, "自由元件繪製失敗" + detail + "。")
|
|
946
870
|
|
|
947
871
|
|
|
@@ -35,9 +35,10 @@ TIMELINE_MUTATIONS = frozenset(
|
|
|
35
35
|
"remove_program_component",
|
|
36
36
|
"add_custom_component",
|
|
37
37
|
"update_custom_component",
|
|
38
|
-
"set_component_text",
|
|
39
38
|
"edit_component",
|
|
39
|
+
"edit_caption",
|
|
40
40
|
"set_component_look",
|
|
41
|
+
"set_caption_design",
|
|
41
42
|
"edit_component_look",
|
|
42
43
|
}
|
|
43
44
|
)
|
|
@@ -52,6 +52,7 @@ _MANUAL = {
|
|
|
52
52
|
"update_custom_component": "修改自由設計元件",
|
|
53
53
|
"set_component_text": "元件文字",
|
|
54
54
|
"edit_component": "修改元件",
|
|
55
|
+
"edit_caption": "修改字幕",
|
|
55
56
|
"edit_component_look": "元件外觀",
|
|
56
57
|
}
|
|
57
58
|
|
|
@@ -77,6 +78,7 @@ _MANUAL_EN = {
|
|
|
77
78
|
"update_custom_component": "changed a custom graphic",
|
|
78
79
|
"set_component_text": "graphic text",
|
|
79
80
|
"edit_component": "edited a graphic",
|
|
81
|
+
"edit_caption": "edited a caption",
|
|
80
82
|
"edit_component_look": "graphic look",
|
|
81
83
|
}
|
|
82
84
|
|
|
@@ -187,3 +187,65 @@ def frame(repository, project_id, run_id, expected_revision_id, frame_number, co
|
|
|
187
187
|
"scope": "editing_still",
|
|
188
188
|
"component_box": box,
|
|
189
189
|
}
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def live_page(repository, project_id, run_id, expected_revision_id, component):
|
|
193
|
+
"""A free design as a page the person's browser plays live, with their unsaved changes."""
|
|
194
|
+
from clipen.rendering import custom_components
|
|
195
|
+
|
|
196
|
+
from .workbench import tools_for
|
|
197
|
+
|
|
198
|
+
revision = repository.current_revision(project_id, run_id)
|
|
199
|
+
if revision.revision_id != expected_revision_id:
|
|
200
|
+
raise ProjectError("revision_conflict", "影片已更新,正在重新讀取編輯畫面。", status_code=409)
|
|
201
|
+
draft, profile, _ = tools_for(repository, project_id, run_id)._component_draft(component, checked=False)
|
|
202
|
+
if not custom_components.is_custom(profile):
|
|
203
|
+
raise ProjectError("component_not_live", "這個元件不能在瀏覽器即時播放。", status_code=422)
|
|
204
|
+
return custom_components.live_page(revision.timeline, draft, profile)
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
def caption_page(repository, project_id, run_id, expected_revision_id, item_id, draft=None):
|
|
208
|
+
"""A caption as its design draws it, as a page the person's browser plays live; draft holds
|
|
209
|
+
a person's unsaved words, delivery and emphasis."""
|
|
210
|
+
from clipen.rendering import custom_components
|
|
211
|
+
|
|
212
|
+
revision = repository.current_revision(project_id, run_id)
|
|
213
|
+
if revision.revision_id != expected_revision_id:
|
|
214
|
+
raise ProjectError("revision_conflict", "影片已更新,正在重新讀取編輯畫面。", status_code=409)
|
|
215
|
+
styles = load_text_styles(repository.projects, project_id)
|
|
216
|
+
item = next(
|
|
217
|
+
(
|
|
218
|
+
i
|
|
219
|
+
for t in revision.timeline.tracks
|
|
220
|
+
if t.track_id == "agent-subtitles"
|
|
221
|
+
for i in t.items
|
|
222
|
+
if i.item_id == item_id
|
|
223
|
+
),
|
|
224
|
+
None,
|
|
225
|
+
)
|
|
226
|
+
profile = styles.get(item.style_id, {}) if item is not None else {}
|
|
227
|
+
if item is not None and draft:
|
|
228
|
+
from .workbench import tools_for
|
|
229
|
+
|
|
230
|
+
item, edited = tools_for(repository, project_id, run_id)._caption_draft({**draft, "element_id": item_id})
|
|
231
|
+
profile = edited or profile
|
|
232
|
+
design = styles.get(profile.get("design") or "")
|
|
233
|
+
if design is None:
|
|
234
|
+
raise ProjectError("caption_not_live", "這句字幕不是 AI 設計的樣式,不能即時播放。", status_code=422)
|
|
235
|
+
page = custom_components.caption_profile(
|
|
236
|
+
design, item.text, profile.get("emphasis", ()), profile.get("delivery", "dialogue")
|
|
237
|
+
)
|
|
238
|
+
return custom_components.live_page(revision.timeline, item, page)
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def kept_cut(repository, project_id, run_id, expected_revision_id):
|
|
242
|
+
"""The film without its text layer, as the last render left it, to play under a live design."""
|
|
243
|
+
revision = repository.current_revision(project_id, run_id)
|
|
244
|
+
if revision.revision_id != expected_revision_id:
|
|
245
|
+
raise ProjectError("revision_conflict", "影片已更新,正在重新讀取編輯畫面。", status_code=409)
|
|
246
|
+
path = FfmpegPreviewRenderer(MediaPreviewRepository(repository.projects)).media_cache_path(
|
|
247
|
+
project_id, revision.timeline
|
|
248
|
+
)
|
|
249
|
+
if path is None or not path.is_file():
|
|
250
|
+
raise ProjectError("clip_needs_render", "先輸出一次這一版影片,才能看動態預覽。", status_code=409)
|
|
251
|
+
return path
|
|
@@ -12,10 +12,29 @@ from .refinement_references import public_state, sent
|
|
|
12
12
|
|
|
13
13
|
# Changes go through review notes to the AI; the user picks which version is current and edits graphics directly.
|
|
14
14
|
USER_TOOLS = frozenset(
|
|
15
|
-
{"restore_revision", "
|
|
15
|
+
{"restore_revision", "edit_component", "edit_component_look", "remove_program_component", "edit_caption"}
|
|
16
16
|
)
|
|
17
17
|
|
|
18
18
|
|
|
19
|
+
def _captions(repository, project_id, timeline):
|
|
20
|
+
"""Every caption a person may correct: its delivery and emphasis, and whether its design plays live."""
|
|
21
|
+
from .production_media import load_text_styles
|
|
22
|
+
|
|
23
|
+
styles = load_text_styles(repository.projects, project_id)
|
|
24
|
+
result = {}
|
|
25
|
+
for track in timeline.tracks:
|
|
26
|
+
if track.track_id != "agent-subtitles":
|
|
27
|
+
continue
|
|
28
|
+
for item in track.items:
|
|
29
|
+
profile = styles.get(item.style_id, {})
|
|
30
|
+
result[item.item_id] = {
|
|
31
|
+
"delivery": profile.get("delivery", "dialogue"),
|
|
32
|
+
"emphasis": profile.get("emphasis", []),
|
|
33
|
+
"live": bool(styles.get(profile.get("design") or "")),
|
|
34
|
+
}
|
|
35
|
+
return result
|
|
36
|
+
|
|
37
|
+
|
|
19
38
|
def idle(repository, project_id, run_id):
|
|
20
39
|
run = repository.get(project_id, run_id)
|
|
21
40
|
latest = repository.latest(project_id)
|
|
@@ -72,6 +91,7 @@ def state(repository, project_id, run_id):
|
|
|
72
91
|
return {
|
|
73
92
|
"revision": revision.to_public(include_timeline=True),
|
|
74
93
|
"component_editing": editing,
|
|
94
|
+
"captions": _captions(repository, project_id, revision.timeline),
|
|
75
95
|
"history": history,
|
|
76
96
|
"ai_usage": usage,
|
|
77
97
|
"references": public_state(intent, revision.timeline),
|