@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
|
@@ -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,80 @@ 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 _slip_clip(self, args):
|
|
319
|
+
"""A person slips one shot: same place and length in the film, an earlier or later stretch of its footage."""
|
|
320
|
+
self._require_keys(args, {"item_id", "frames"}, optional={"summary"})
|
|
321
|
+
from .slip import slipped
|
|
322
|
+
|
|
323
|
+
timeline, details = slipped(self, args["item_id"], args["frames"])
|
|
324
|
+
return self._save(timeline, "微調鏡頭片段", **details)
|
|
325
|
+
|
|
326
|
+
def _edit_caption(self, args):
|
|
327
|
+
"""A person corrects one caption: its words, how it is delivered, which words stand out."""
|
|
328
|
+
from .production_media import atomic_json, load_text_styles, text_style_path
|
|
329
|
+
|
|
330
|
+
draft, profile = self._caption_draft(args)
|
|
331
|
+
current = next(i for t in self._timeline().tracks for i in t.items if i.item_id == draft.item_id)
|
|
332
|
+
if (draft.text, draft.style_id) == (current.text, current.style_id):
|
|
333
|
+
raise ProjectError("caption_unchanged", "沒有任何變動。", status_code=422)
|
|
334
|
+
if profile is not None:
|
|
335
|
+
styles = load_text_styles(self.repository.projects, self.project_id)
|
|
336
|
+
styles[draft.style_id] = profile
|
|
337
|
+
atomic_json(text_style_path(self.repository.projects, self.project_id), styles)
|
|
338
|
+
tracks = tuple(
|
|
339
|
+
replace(t, items=tuple(draft if i.item_id == draft.item_id else i for i in t.items))
|
|
340
|
+
if t.track_id == "agent-subtitles"
|
|
341
|
+
else t
|
|
342
|
+
for t in self._timeline().tracks
|
|
343
|
+
)
|
|
344
|
+
return self._save(replace(self._timeline(), tracks=tracks), args.get("summary") or "使用者修改字幕")
|
|
345
|
+
|
|
382
346
|
def _edit_component(self, args):
|
|
383
347
|
"""A person changes one programme graphic: wording, place, look, typeface or timing."""
|
|
384
348
|
from .production_media import atomic_json, load_text_styles, text_style_path
|
|
@@ -403,6 +367,29 @@ class SkillTools:
|
|
|
403
367
|
atomic_json(text_style_path(self.repository.projects, self.project_id), styles)
|
|
404
368
|
return self._save(replace(self._timeline(), tracks=tracks), args.get("summary") or "使用者修改元件")
|
|
405
369
|
|
|
370
|
+
def _production_get_font(self, args):
|
|
371
|
+
"""Fetch an open font from Google Fonts so pages can use it by name."""
|
|
372
|
+
from clipen.rendering import fetched_fonts
|
|
373
|
+
|
|
374
|
+
try:
|
|
375
|
+
entry = fetched_fonts.fetch(args["family"])
|
|
376
|
+
except fetched_fonts.FontUnavailable as error:
|
|
377
|
+
raise ProjectError("font_unavailable", str(error), status_code=422) from error
|
|
378
|
+
return ToolResult(
|
|
379
|
+
{
|
|
380
|
+
"family": entry["family"],
|
|
381
|
+
"license": entry["license"],
|
|
382
|
+
"source": entry["source"],
|
|
383
|
+
"use": f"font-family: '{entry['family']}'",
|
|
384
|
+
"note": "Check that it has every character your text needs; a missing character falls back to another face.",
|
|
385
|
+
}
|
|
386
|
+
)
|
|
387
|
+
|
|
388
|
+
def _production_set_caption_design(self, args):
|
|
389
|
+
from . import caption_design
|
|
390
|
+
|
|
391
|
+
return caption_design.apply(self, args)
|
|
392
|
+
|
|
406
393
|
def _production_set_component_look(self, args):
|
|
407
394
|
"""The Agent creates or changes a look; graphics already using it follow."""
|
|
408
395
|
from . import component_looks
|
|
@@ -440,7 +427,6 @@ class SkillTools:
|
|
|
440
427
|
def _apply_look(self, look, summary):
|
|
441
428
|
"""Save a look and redraw every graphic that uses it; refused if one would then need a typeface the look lacks."""
|
|
442
429
|
from clipen.finishing.models import digest
|
|
443
|
-
from clipen.rendering import custom_components
|
|
444
430
|
|
|
445
431
|
from . import component_looks
|
|
446
432
|
from .production_media import atomic_json, load_text_styles, text_style_path
|
|
@@ -453,27 +439,12 @@ class SkillTools:
|
|
|
453
439
|
status_code=422,
|
|
454
440
|
)
|
|
455
441
|
timeline = self._timeline()
|
|
456
|
-
changed
|
|
442
|
+
changed = {}
|
|
457
443
|
for item, profile in component_looks.on_film(self, timeline):
|
|
458
444
|
if (profile.get("look") or {}).get("look_id") != look["look_id"] or profile["look"] == look:
|
|
459
445
|
continue
|
|
460
446
|
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
|
-
)
|
|
447
|
+
changed[item.item_id] = (replace(item, style_id="agent.component." + digest(updated)[:24]), updated)
|
|
477
448
|
looks[look["look_id"]] = look
|
|
478
449
|
component_looks.store(self, looks)
|
|
479
450
|
public = component_looks.public(look, len(changed))
|
|
@@ -557,65 +528,44 @@ class SkillTools:
|
|
|
557
528
|
)
|
|
558
529
|
|
|
559
530
|
def _component_editing(self):
|
|
560
|
-
"""What the review page needs to edit graphics: each
|
|
531
|
+
"""What the review page needs to edit graphics: each free design's settings and the run's looks.
|
|
532
|
+
|
|
533
|
+
Graphics left from the retired built-in templates are not listed; they are no longer drawn."""
|
|
534
|
+
from clipen.rendering.custom_components import FONT_CHOICES
|
|
535
|
+
|
|
536
|
+
from . import component_looks
|
|
561
537
|
from .production_media import load_text_styles
|
|
562
538
|
|
|
563
|
-
skill = self._skill_value()
|
|
564
539
|
styles = load_text_styles(self.repository.projects, self.project_id)
|
|
565
540
|
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
541
|
result = {}
|
|
569
|
-
for track in self.
|
|
570
|
-
if not (track.track_id == "program-components" or track.track_id.startswith("program-components-")):
|
|
571
|
-
continue
|
|
542
|
+
for track in self._component_tracks():
|
|
572
543
|
for item in track.items:
|
|
573
544
|
profile = styles.get(item.style_id, {})
|
|
574
545
|
shot = shots.get(profile.get("anchor_item_id"))
|
|
575
|
-
if
|
|
546
|
+
if (
|
|
547
|
+
profile.get("kind") != "program_component"
|
|
548
|
+
or profile.get("component_id") != "custom"
|
|
549
|
+
or shot is None
|
|
550
|
+
):
|
|
576
551
|
continue
|
|
577
|
-
custom = profile["component_id"] == "custom"
|
|
578
552
|
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),
|
|
553
|
+
"name": item.text,
|
|
583
554
|
"x": profile.get("x"),
|
|
584
555
|
"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
|
-
),
|
|
556
|
+
"fields": profile.get("fields") or {"texts": [], "colors": []},
|
|
557
|
+
"edits": profile.get("edits") or {},
|
|
558
|
+
"look_id": (profile.get("look") or {}).get("look_id"),
|
|
598
559
|
"shot_start_frame": shot.start_frame,
|
|
599
560
|
"shot_duration_frames": shot.duration_frames,
|
|
600
561
|
}
|
|
562
|
+
from clipen.rendering import fetched_fonts
|
|
601
563
|
|
|
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
|
-
|
|
564
|
+
fetched = {family: f"{family}(Google Fonts)" for family in fetched_fonts.available()}
|
|
610
565
|
return {
|
|
611
566
|
"looks": component_looks.listing(self),
|
|
612
|
-
"font_choices": [{"family": f, "label": l} for f, l in FONT_CHOICES.items()],
|
|
567
|
+
"font_choices": [{"family": f, "label": l} for f, l in {**FONT_CHOICES, **fetched}.items()],
|
|
613
568
|
"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
569
|
}
|
|
620
570
|
|
|
621
571
|
def _component_issues(self):
|
|
@@ -644,6 +594,16 @@ class SkillTools:
|
|
|
644
594
|
if profile.get("kind") != "program_component" or anchor is None:
|
|
645
595
|
issues.append({"code": "component_anchor_missing", "item_id": element.item_id})
|
|
646
596
|
continue
|
|
597
|
+
if profile.get("component_id") != "custom":
|
|
598
|
+
issues.append(
|
|
599
|
+
{
|
|
600
|
+
"code": "component_retired",
|
|
601
|
+
"item_id": element.item_id,
|
|
602
|
+
"advisory": True,
|
|
603
|
+
"message": "這個元件用的是已停用的內建模板,不會出現在影片裡;用 remove_program_component 刪掉,需要的話重新設計一個。",
|
|
604
|
+
}
|
|
605
|
+
)
|
|
606
|
+
continue
|
|
647
607
|
if (
|
|
648
608
|
not anchor.start_frame <= element.start_frame < anchor.start_frame + anchor.duration_frames
|
|
649
609
|
or element.start_frame + element.duration_frames > timeline.duration_frames
|
|
@@ -660,26 +620,6 @@ class SkillTools:
|
|
|
660
620
|
boxes.append((element, box))
|
|
661
621
|
except TitleRenderError as error:
|
|
662
622
|
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
623
|
for n, (a, left) in enumerate(boxes):
|
|
684
624
|
for b, right in boxes[n + 1 :]:
|
|
685
625
|
if (
|
|
@@ -771,21 +711,17 @@ class SkillTools:
|
|
|
771
711
|
}
|
|
772
712
|
from . import component_looks
|
|
773
713
|
|
|
714
|
+
# A look is optional: graphics of one kind may share one, or a page may set its own type and colour.
|
|
774
715
|
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
|
|
716
|
+
if look_id:
|
|
717
|
+
look = component_looks.current(self).get(look_id)
|
|
718
|
+
if look is None:
|
|
719
|
+
raise ProjectError(
|
|
720
|
+
"component_look_not_found",
|
|
721
|
+
"沒有這個外觀;先用 set_component_look 建立,或從 list_program_components 的 looks 選一個。",
|
|
722
|
+
status_code=422,
|
|
723
|
+
)
|
|
724
|
+
profile["look"] = look
|
|
789
725
|
item = TextClip(
|
|
790
726
|
args["element_id"],
|
|
791
727
|
shot.start_frame + settings["start_offset_frames"],
|
|
@@ -812,7 +748,6 @@ class SkillTools:
|
|
|
812
748
|
profile["edits"] = {kind: values for kind, values in keep.items() if values}
|
|
813
749
|
item = replace(item, style_id="agent.component." + digest(profile)[:24])
|
|
814
750
|
custom_components.check(timeline, item, profile)
|
|
815
|
-
custom_components.check_fonts(timeline, item, profile)
|
|
816
751
|
except custom_components.CustomRenderError as error:
|
|
817
752
|
raise ProjectError(error.code, _custom_problem(error), status_code=422) from error
|
|
818
753
|
styles[item.style_id] = profile
|
|
@@ -939,9 +874,6 @@ def _custom_problem(error):
|
|
|
939
874
|
"custom_component_script_error": "頁面的程式出錯" + detail + "。",
|
|
940
875
|
"custom_component_frame_timeout": "有一格超過 10 秒還沒畫完;clipenFrame 要能直接畫出指定的那一格。",
|
|
941
876
|
"custom_component_renderer_missing": "這台電腦沒有可用的 Chrome,無法繪製自由元件" + detail + "。",
|
|
942
|
-
"custom_component_font_outside_look": "頁面用了外觀以外的字型"
|
|
943
|
-
+ detail
|
|
944
|
-
+ ";文字的字型要寫成 var(--look-font-鍵名)。想換字或加一套字,先用 set_component_look 改外觀。",
|
|
945
877
|
}.get(error.code, "自由元件繪製失敗" + detail + "。")
|
|
946
878
|
|
|
947
879
|
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""Slip a shot: it keeps where and how long it plays in the film, and shows an earlier or later stretch
|
|
2
|
+
of its footage, for example to let a sentence finish that the cut stopped short."""
|
|
3
|
+
|
|
4
|
+
from dataclasses import replace
|
|
5
|
+
from fractions import Fraction
|
|
6
|
+
from math import floor
|
|
7
|
+
|
|
8
|
+
from clipen.domain import TextClip
|
|
9
|
+
from clipen.projects import ProjectError
|
|
10
|
+
|
|
11
|
+
# Picture treatment drawn for particular moments of the footage cannot follow it to other moments.
|
|
12
|
+
_PINNED_TO_MOMENTS = frozenset({"video.mosaic"})
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def problem(message):
|
|
16
|
+
return ProjectError("slip_invalid", message, status_code=422)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def room(tools, item):
|
|
20
|
+
"""How many frames the shot can slip earlier and later before it runs off its footage."""
|
|
21
|
+
span = item.source.span
|
|
22
|
+
row = next(
|
|
23
|
+
(
|
|
24
|
+
r
|
|
25
|
+
for r in tools._source_rows()
|
|
26
|
+
if r["version_id"] == span.version_id and r["stream_index"] == span.stream_index
|
|
27
|
+
),
|
|
28
|
+
None,
|
|
29
|
+
)
|
|
30
|
+
if row is None:
|
|
31
|
+
return 0, 0
|
|
32
|
+
timeline = tools._timeline()
|
|
33
|
+
unit = Fraction(span.time_base.numerator, span.time_base.denominator)
|
|
34
|
+
fps = Fraction(timeline.frame_rate.numerator, timeline.frame_rate.denominator)
|
|
35
|
+
earlier = floor((int(span.start_pts) - int(row["start_pts"])) * unit * fps)
|
|
36
|
+
later = floor((int(row["end_pts"]) - int(span.end_pts)) * unit * fps)
|
|
37
|
+
return max(0, earlier), max(0, later)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def slipped(tools, item_id, frames):
|
|
41
|
+
"""The timeline with the shot moved `frames` later in its footage (earlier when negative).
|
|
42
|
+
|
|
43
|
+
Its captions move with the speech they show and leave when that speech leaves the shot; graphics,
|
|
44
|
+
music and every other shot stay where they are."""
|
|
45
|
+
if isinstance(frames, bool) or not isinstance(frames, int) or frames == 0:
|
|
46
|
+
raise problem("請指定要往前或往後移動幾格。")
|
|
47
|
+
timeline = tools._timeline()
|
|
48
|
+
video = tools._video()
|
|
49
|
+
item = next((i for i in video.items if i.item_id == item_id), None)
|
|
50
|
+
if item is None:
|
|
51
|
+
raise problem("找不到這個鏡頭。")
|
|
52
|
+
fps = Fraction(timeline.frame_rate.numerator, timeline.frame_rate.denominator)
|
|
53
|
+
earlier, later = room(tools, item)
|
|
54
|
+
if not -earlier <= frames <= later:
|
|
55
|
+
raise problem(
|
|
56
|
+
f"這個鏡頭最多只能往前 {float(earlier / fps):.1f} 秒、往後 {float(later / fps):.1f} 秒,再過去就沒有毛片了。"
|
|
57
|
+
)
|
|
58
|
+
span = item.source.span
|
|
59
|
+
unit = Fraction(span.time_base.numerator, span.time_base.denominator)
|
|
60
|
+
shift = round(Fraction(frames) / fps / unit)
|
|
61
|
+
moved_span = replace(span, start_pts=str(int(span.start_pts) + shift), end_pts=str(int(span.end_pts) + shift))
|
|
62
|
+
removed_effects = [e.effect_id for e in item.effects if e.effect_id in _PINNED_TO_MOMENTS]
|
|
63
|
+
shot = replace(
|
|
64
|
+
item,
|
|
65
|
+
source=replace(item.source, span=moved_span, handle_before_pts=0, handle_after_pts=0),
|
|
66
|
+
effects=tuple(e for e in item.effects if e.effect_id not in _PINNED_TO_MOMENTS),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
from .production_media import load_text_styles
|
|
70
|
+
|
|
71
|
+
styles = load_text_styles(tools.repository.projects, tools.project_id)
|
|
72
|
+
first, last = item.start_frame, item.start_frame + item.duration_frames
|
|
73
|
+
moved, removed = [], []
|
|
74
|
+
tracks = []
|
|
75
|
+
for track in timeline.tracks:
|
|
76
|
+
if track.track_id == video.track_id:
|
|
77
|
+
tracks.append(replace(track, items=tuple(shot if i.item_id == item_id else i for i in track.items)))
|
|
78
|
+
continue
|
|
79
|
+
if track.track_id != "agent-subtitles":
|
|
80
|
+
tracks.append(track)
|
|
81
|
+
continue
|
|
82
|
+
kept = []
|
|
83
|
+
for caption in track.items:
|
|
84
|
+
profile = styles.get(caption.style_id, {}) if isinstance(caption, TextClip) else {}
|
|
85
|
+
anchored = profile.get("anchor_item_id")
|
|
86
|
+
belongs = anchored == item_id or (
|
|
87
|
+
anchored is None
|
|
88
|
+
and first <= caption.start_frame
|
|
89
|
+
and caption.start_frame + caption.duration_frames <= last
|
|
90
|
+
)
|
|
91
|
+
if not belongs:
|
|
92
|
+
kept.append(caption)
|
|
93
|
+
continue
|
|
94
|
+
start = caption.start_frame - frames
|
|
95
|
+
if first <= start and start + caption.duration_frames <= last:
|
|
96
|
+
kept.append(replace(caption, start_frame=start))
|
|
97
|
+
moved.append(caption.item_id)
|
|
98
|
+
else:
|
|
99
|
+
removed.append({"item_id": caption.item_id, "text": getattr(caption, "text", "")})
|
|
100
|
+
tracks.append(replace(track, items=tuple(kept)))
|
|
101
|
+
seconds = float(Fraction(int(moved_span.start_pts)) * unit)
|
|
102
|
+
return replace(timeline, tracks=tuple(tracks)), {
|
|
103
|
+
"item_id": item_id,
|
|
104
|
+
"source_start_seconds": round(seconds, 3),
|
|
105
|
+
"source_end_seconds": round(float(Fraction(int(moved_span.end_pts)) * unit), 3),
|
|
106
|
+
"moved_captions": moved,
|
|
107
|
+
"removed_captions": removed,
|
|
108
|
+
"removed_effects": removed_effects,
|
|
109
|
+
}
|
|
@@ -35,9 +35,11 @@ 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
|
+
"slip_clip",
|
|
40
41
|
"set_component_look",
|
|
42
|
+
"set_caption_design",
|
|
41
43
|
"edit_component_look",
|
|
42
44
|
}
|
|
43
45
|
)
|
|
@@ -52,6 +52,8 @@ _MANUAL = {
|
|
|
52
52
|
"update_custom_component": "修改自由設計元件",
|
|
53
53
|
"set_component_text": "元件文字",
|
|
54
54
|
"edit_component": "修改元件",
|
|
55
|
+
"edit_caption": "修改字幕",
|
|
56
|
+
"slip_clip": "微調鏡頭片段",
|
|
55
57
|
"edit_component_look": "元件外觀",
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -77,6 +79,8 @@ _MANUAL_EN = {
|
|
|
77
79
|
"update_custom_component": "changed a custom graphic",
|
|
78
80
|
"set_component_text": "graphic text",
|
|
79
81
|
"edit_component": "edited a graphic",
|
|
82
|
+
"edit_caption": "edited a caption",
|
|
83
|
+
"slip_clip": "slipped a shot",
|
|
80
84
|
"edit_component_look": "graphic look",
|
|
81
85
|
}
|
|
82
86
|
|