@clipen/clipen-cli 1.0.0 → 1.0.2
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 +56 -48
- package/apps/web/dist/assets/{index-D5D2HiB1.js → index-DPHwA954.js} +1 -1
- package/apps/web/dist/index.html +1 -1
- package/bin/clipen.js +1 -1
- package/package.json +7 -6
- package/pyproject.toml +18 -2
- package/requirements/dev.txt +2 -0
- package/src/clipen/__init__.py +1 -1
- package/src/clipen/analysis/__init__.py +7 -7
- package/src/clipen/analysis/artifacts.py +4 -10
- package/src/clipen/analysis/audio.py +10 -8
- package/src/clipen/analysis/evidence_service.py +345 -167
- package/src/clipen/analysis/image_similarity.py +5 -14
- package/src/clipen/analysis/keyframes.py +5 -17
- package/src/clipen/analysis/models.py +5 -7
- package/src/clipen/analysis/qwen_worker.py +19 -54
- package/src/clipen/analysis/resources.py +2 -1
- package/src/clipen/analysis/runtime.py +1 -3
- package/src/clipen/analysis/service.py +16 -48
- package/src/clipen/analysis/setup.py +11 -25
- package/src/clipen/analysis/setup_cli.py +5 -15
- package/src/clipen/analysis/storage.py +96 -278
- package/src/clipen/analysis/transcription.py +40 -82
- package/src/clipen/analysis/visual.py +109 -48
- package/src/clipen/annotations/__init__.py +5 -2
- package/src/clipen/annotations/models.py +1 -1
- package/src/clipen/annotations/storage.py +132 -84
- package/src/clipen/annotations/suggestions.py +3 -8
- package/src/clipen/asr_release.py +4 -11
- package/src/clipen/bootstrap.py +71 -61
- package/src/clipen/{planning/models.py → candidates.py} +29 -47
- package/src/clipen/cli.py +4 -9
- package/src/clipen/controller/app.py +401 -214
- package/src/clipen/controller/server.py +28 -38
- package/src/clipen/domain/__init__.py +1 -1
- package/src/clipen/domain/media_time.py +3 -10
- package/src/clipen/domain/timeline.py +45 -47
- package/src/clipen/domain/validation.py +0 -1
- package/src/clipen/editing/__init__.py +1 -1
- package/src/clipen/editing/agent_models.py +4 -11
- package/src/clipen/editing/agent_repository.py +393 -172
- package/src/clipen/editing/agent_tools.py +180 -99
- package/src/clipen/editing/alignment.py +92 -52
- package/src/clipen/editing/alignment_setup.py +118 -70
- package/src/clipen/editing/alignment_worker.py +11 -9
- package/src/clipen/editing/change_report.py +95 -38
- package/src/clipen/editing/compiler.py +0 -1
- package/src/clipen/editing/component_looks.py +58 -34
- package/src/clipen/editing/component_review.py +34 -38
- package/src/clipen/editing/coordinator.py +213 -92
- package/src/clipen/editing/editorial_review.py +217 -95
- package/src/clipen/editing/evidence_jobs.py +457 -200
- package/src/clipen/editing/history_changes.py +129 -68
- package/src/clipen/editing/music_choices.py +8 -5
- package/src/clipen/editing/production_catalog.py +573 -136
- package/src/clipen/editing/production_limits.py +43 -17
- package/src/clipen/editing/production_media.py +376 -167
- package/src/clipen/editing/production_preview.py +322 -129
- package/src/clipen/editing/production_progress.py +164 -69
- package/src/clipen/editing/production_requirements.py +106 -39
- package/src/clipen/editing/production_tools.py +1064 -462
- package/src/clipen/editing/program_audio.py +211 -81
- package/src/clipen/editing/program_direction.py +59 -25
- package/src/clipen/editing/program_story.py +83 -45
- package/src/clipen/editing/program_subtitles.py +194 -96
- package/src/clipen/editing/programme_review.py +98 -50
- package/src/clipen/editing/prompt_history.py +64 -27
- package/src/clipen/editing/recut.py +65 -25
- package/src/clipen/editing/refinement_references.py +176 -86
- package/src/clipen/editing/resolve_export.py +449 -218
- package/src/clipen/editing/resolve_titles.py +162 -105
- package/src/clipen/editing/skill_tools.py +530 -154
- package/src/clipen/editing/source_dialogue.py +177 -67
- package/src/clipen/editing/speech_coverage.py +42 -22
- package/src/clipen/editing/speech_quality.py +6 -1
- package/src/clipen/editing/tool_receipts.py +78 -32
- package/src/clipen/editing/versions.py +122 -64
- package/src/clipen/editing/visual_preview.py +157 -61
- package/src/clipen/editing/workbench.py +104 -42
- package/src/clipen/finishing/audio.py +69 -30
- package/src/clipen/finishing/catalog.py +176 -93
- package/src/clipen/finishing/models.py +1 -1
- package/src/clipen/finishing/renderer.py +33 -14
- package/src/clipen/mcp_editing/__main__.py +3 -1
- package/src/clipen/mcp_editing/server.py +77 -34
- package/src/clipen/media/__init__.py +3 -3
- package/src/clipen/media/discovery.py +7 -20
- package/src/clipen/media/models.py +7 -18
- package/src/clipen/media/preview.py +14 -24
- package/src/clipen/media/probe.py +16 -44
- package/src/clipen/media/service.py +6 -19
- package/src/clipen/media/storage.py +33 -81
- package/src/clipen/music_vocabulary.py +33 -4
- package/src/clipen/power.py +8 -3
- package/src/clipen/projects/__init__.py +1 -1
- package/src/clipen/projects/deletion.py +19 -32
- package/src/clipen/projects/finishing_schema.py +3 -1
- package/src/clipen/projects/models.py +2 -5
- package/src/clipen/projects/picker.py +13 -37
- package/src/clipen/projects/service.py +8 -24
- package/src/clipen/projects/storage.py +226 -246
- package/src/clipen/provider_registry.py +9 -20
- package/src/clipen/providers/account.py +86 -35
- package/src/clipen/providers/claude.py +59 -25
- package/src/clipen/providers/claude_editing.py +14 -7
- package/src/clipen/providers/codex.py +73 -118
- package/src/clipen/providers/codex_editing.py +2 -2
- package/src/clipen/providers/editing_agent.py +19 -17
- package/src/clipen/providers/recovery.py +7 -8
- package/src/clipen/rendering/cover.py +18 -5
- package/src/clipen/rendering/custom_components.py +167 -79
- package/src/clipen/rendering/custom_render.py +62 -41
- package/src/clipen/rendering/production_effects.py +77 -45
- package/src/clipen/rendering/program_components.py +134 -73
- package/src/clipen/rendering/program_creator.py +432 -277
- package/src/clipen/rendering/program_identities.py +277 -182
- package/src/clipen/rendering/program_motion.py +140 -95
- package/src/clipen/rendering/program_studio.py +175 -116
- package/src/clipen/rendering/program_styles.py +231 -145
- package/src/clipen/rendering/program_subtitles.py +71 -34
- package/src/clipen/rendering/renderer.py +150 -121
- package/src/clipen/rendering/storage.py +9 -22
- package/src/clipen/rendering/titles.py +193 -86
- package/src/clipen/skills/__init__.py +1 -0
- package/src/clipen/skills/catalog.py +151 -55
- package/src/clipen/skills/library.py +13 -7
- package/src/clipen/skills/package.py +46 -23
- package/src/clipen/skills/visual_styles.py +29 -18
- package/src/clipen/workspace.py +15 -44
- package/install +0 -25
- package/src/clipen/planning/__init__.py +0 -9
- package/uninstall +0 -25
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"""The account the AI gives of each change: what it changed and why, how it handled each review note,
|
|
2
2
|
and what it left undone. finish_edit refuses to close a change without one."""
|
|
3
|
+
|
|
3
4
|
from clipen.projects import ProjectError
|
|
4
5
|
|
|
5
|
-
OUTCOMES = {
|
|
6
|
+
OUTCOMES = {"done": "已處理", "partly": "部分處理", "not_done": "沒有處理", "kept": "照你說的保留"}
|
|
6
7
|
# Work may be left only for one of these: the person has to decide or supply something,
|
|
7
8
|
# or no Clipen tool can do it. Running out of effort is not a reason.
|
|
8
|
-
REASONS = {
|
|
9
|
-
UNFINISHED =
|
|
9
|
+
REASONS = {"needs_you": "需要你決定或提供", "cannot": "Clipen 目前做不到"}
|
|
10
|
+
UNFINISHED = "change_report_unfinished"
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def _text(value, limit):
|
|
@@ -14,58 +15,114 @@ def _text(value, limit):
|
|
|
14
15
|
|
|
15
16
|
|
|
16
17
|
def _invalid(message):
|
|
17
|
-
return ProjectError(
|
|
18
|
+
return ProjectError("change_report_invalid", message, status_code=422)
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
def check_report(arguments, intent):
|
|
21
22
|
"""The report finish_edit was given, checked against the notes the person sent with this request."""
|
|
22
|
-
changes = arguments.get(
|
|
23
|
-
if
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
changes = arguments.get("changes")
|
|
24
|
+
if (
|
|
25
|
+
not isinstance(changes, list)
|
|
26
|
+
or not 1 <= len(changes) <= 20
|
|
27
|
+
or not all(
|
|
28
|
+
isinstance(c, dict) and set(c) <= {"what", "why"} and _text(c.get("what"), 200) and _text(c.get("why"), 300)
|
|
29
|
+
for c in changes
|
|
30
|
+
)
|
|
31
|
+
):
|
|
32
|
+
raise _invalid(
|
|
33
|
+
"finish_edit 要附上修改說明:changes 列出 1–20 項,每項寫 what(改了什麼,200 字內)與 why(為什麼,300 字內),用觀眾看得懂的話。"
|
|
34
|
+
)
|
|
35
|
+
not_done = arguments.get("not_done", [])
|
|
36
|
+
if (
|
|
37
|
+
not isinstance(not_done, list)
|
|
38
|
+
or len(not_done) > 10
|
|
39
|
+
or not all(
|
|
40
|
+
isinstance(item, dict)
|
|
41
|
+
and set(item) <= {"what", "reason", "detail"}
|
|
42
|
+
and item.get("reason") in REASONS
|
|
43
|
+
and _text(item.get("what"), 200)
|
|
44
|
+
and _text(item.get("detail"), 300)
|
|
45
|
+
for item in not_done
|
|
46
|
+
)
|
|
47
|
+
):
|
|
48
|
+
raise _invalid(
|
|
49
|
+
"not_done 每項要有 what(沒做到什麼)、reason 與 detail,最多 10 項。reason 只能是 needs_you"
|
|
50
|
+
"(detail 寫使用者要決定或提供什麼)或 cannot(detail 寫是哪個工具限制做不到)。"
|
|
51
|
+
"你的工具做得到的事不能列在這裡,要先做完。"
|
|
52
|
+
)
|
|
53
|
+
request = intent.get("latest_revision_request") or {}
|
|
54
|
+
sent = {
|
|
55
|
+
item["reference_id"]
|
|
56
|
+
for item in (request.get("references") or {}).get("items", [])
|
|
57
|
+
if isinstance(item, dict) and "reference_id" in item
|
|
58
|
+
}
|
|
59
|
+
notes = arguments.get("notes", [])
|
|
36
60
|
if not isinstance(notes, list) or not all(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
61
|
+
isinstance(n, dict)
|
|
62
|
+
and set(n) <= {"reference_id", "outcome", "explanation", "reason"}
|
|
63
|
+
and n.get("outcome") in OUTCOMES
|
|
64
|
+
and _text(n.get("explanation"), 300)
|
|
65
|
+
and isinstance(n.get("reference_id"), str)
|
|
66
|
+
for n in notes
|
|
67
|
+
):
|
|
68
|
+
raise _invalid(
|
|
69
|
+
"notes 每項要有 reference_id、outcome(done/partly/not_done/kept)與 explanation(300 字內)。"
|
|
70
|
+
)
|
|
71
|
+
if any(n["outcome"] in ("partly", "not_done") and n.get("reason") not in REASONS for n in notes):
|
|
72
|
+
raise _invalid(
|
|
73
|
+
"outcome 是 partly 或 not_done 的注記要附 reason:needs_you(需要使用者決定或提供)或 cannot(工具做不到)。"
|
|
74
|
+
"你的工具做得到的就先做完,再回報 done。"
|
|
75
|
+
)
|
|
76
|
+
answered = [n["reference_id"] for n in notes]
|
|
44
77
|
if len(answered) != len(set(answered)) or set(answered) != sent:
|
|
45
78
|
missing = len(sent - set(answered))
|
|
46
|
-
raise _invalid(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
79
|
+
raise _invalid(
|
|
80
|
+
f"使用者這次送了 {len(sent)} 筆注記,notes 要逐筆回應每一筆(reference_id 不重複、不多不少)"
|
|
81
|
+
+ (f";還有 {missing} 筆沒回應。" if missing else "。")
|
|
82
|
+
)
|
|
83
|
+
return {
|
|
84
|
+
"changes": [{"what": c["what"].strip(), "why": c["why"].strip()} for c in changes],
|
|
85
|
+
"notes": [
|
|
86
|
+
{
|
|
87
|
+
"reference_id": n["reference_id"],
|
|
88
|
+
"outcome": n["outcome"],
|
|
89
|
+
"explanation": n["explanation"].strip(),
|
|
90
|
+
**({"reason": n["reason"]} if n["outcome"] in ("partly", "not_done") else {}),
|
|
91
|
+
}
|
|
92
|
+
for n in notes
|
|
93
|
+
],
|
|
94
|
+
"not_done": [
|
|
95
|
+
{"what": i["what"].strip(), "reason": i["reason"], "detail": i["detail"].strip()} for i in not_done
|
|
96
|
+
],
|
|
97
|
+
}
|
|
52
98
|
|
|
53
99
|
|
|
54
100
|
def unfinished(report):
|
|
55
101
|
"""What the report leaves undone, as short lines the AI is asked to reconsider."""
|
|
56
|
-
return
|
|
57
|
-
|
|
102
|
+
return [
|
|
103
|
+
f"注記 {n['reference_id']}:{n['explanation']}"
|
|
104
|
+
for n in report["notes"]
|
|
105
|
+
if n["outcome"] in ("partly", "not_done")
|
|
106
|
+
] + [f"{i['what']}({i['detail']})" for i in report["not_done"]]
|
|
58
107
|
|
|
59
108
|
|
|
60
109
|
def challenge(report):
|
|
61
110
|
"""Asked once per request before work is left undone: do what the tools can do first."""
|
|
62
111
|
left = unfinished(report)
|
|
63
|
-
return ProjectError(
|
|
64
|
-
|
|
65
|
-
|
|
112
|
+
return ProjectError(
|
|
113
|
+
UNFINISHED,
|
|
114
|
+
"修改說明裡還有沒做完的地方:"
|
|
115
|
+
+ ";".join(left)[:900]
|
|
116
|
+
+ "。用你的工具做得到的,現在就做完並改回報 done;只有真的需要使用者決定或提供、或工具確實做不到的才保留,"
|
|
117
|
+
"確認後再呼叫一次 finish_edit。",
|
|
118
|
+
status_code=409,
|
|
119
|
+
)
|
|
66
120
|
|
|
67
121
|
|
|
68
122
|
def carried(report):
|
|
69
123
|
"""What the last change left for the person, handed to the next request."""
|
|
70
|
-
return [
|
|
71
|
-
|
|
124
|
+
return [
|
|
125
|
+
{"what": i["what"], "reason": i["reason"], "detail": i["detail"]}
|
|
126
|
+
for i in report.get("not_done", [])
|
|
127
|
+
if isinstance(i, dict) and i.get("reason") in REASONS
|
|
128
|
+
]
|
|
@@ -10,98 +10,122 @@ Each graphic keeps a copy of its look, so every version draws as it was saved.
|
|
|
10
10
|
The run's list of looks lives beside the film; the copies on the current film
|
|
11
11
|
win, so going back to an earlier version also brings back its looks.
|
|
12
12
|
"""
|
|
13
|
+
|
|
13
14
|
import json
|
|
14
15
|
import re
|
|
15
16
|
|
|
16
17
|
from clipen.projects import ProjectError
|
|
17
18
|
from clipen.rendering.custom_components import FONT_CHOICES
|
|
18
19
|
|
|
19
|
-
KEY = re.compile(r
|
|
20
|
-
HEX = re.compile(r
|
|
20
|
+
KEY = re.compile(r"^[A-Za-z0-9_\-一-鿿]{1,24}$")
|
|
21
|
+
HEX = re.compile(r"^#[0-9a-fA-F]{6}$")
|
|
21
22
|
MAX_LOOKS, MAX_FONTS, MAX_COLORS = 8, 3, 6
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
def _invalid(message):
|
|
25
|
-
return ProjectError(
|
|
26
|
+
return ProjectError("component_look_invalid", message, status_code=422)
|
|
26
27
|
|
|
27
28
|
|
|
28
29
|
def normalize(value):
|
|
29
30
|
"""A look as given by the Agent, checked: {look_id, name, fonts: [{key, label, family}], colors: [{key, label, value}]}."""
|
|
30
|
-
if not isinstance(value, dict) or not isinstance(value.get(
|
|
31
|
-
raise _invalid(
|
|
32
|
-
name = value.get(
|
|
33
|
-
fonts, colors = value.get(
|
|
31
|
+
if not isinstance(value, dict) or not isinstance(value.get("look_id"), str) or not KEY.match(value["look_id"]):
|
|
32
|
+
raise _invalid("look_id 要是 1–24 個字的英數字、中文、- 或 _。")
|
|
33
|
+
name = value.get("name") if isinstance(value.get("name"), str) and value["name"].strip() else value["look_id"]
|
|
34
|
+
fonts, colors = value.get("fonts"), value.get("colors", [])
|
|
34
35
|
if not isinstance(fonts, list) or not 1 <= len(fonts) <= MAX_FONTS:
|
|
35
|
-
raise _invalid(f
|
|
36
|
+
raise _invalid(f"每個外觀要有 1–{MAX_FONTS} 套字型。")
|
|
36
37
|
if not isinstance(colors, list) or len(colors) > MAX_COLORS:
|
|
37
|
-
raise _invalid(f
|
|
38
|
+
raise _invalid(f"每個外觀最多 {MAX_COLORS} 個顏色。")
|
|
39
|
+
|
|
38
40
|
def entries(items, kind):
|
|
39
41
|
seen, result = set(), []
|
|
40
42
|
for entry in items:
|
|
41
|
-
if
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
if (
|
|
44
|
+
not isinstance(entry, dict)
|
|
45
|
+
or not isinstance(entry.get("key"), str)
|
|
46
|
+
or not KEY.match(entry["key"])
|
|
47
|
+
or entry["key"] in seen
|
|
48
|
+
):
|
|
49
|
+
raise _invalid("字型與顏色的 key 要是不重複的英數字、中文、- 或 _。")
|
|
50
|
+
seen.add(entry["key"])
|
|
51
|
+
label = (
|
|
52
|
+
entry.get("label") if isinstance(entry.get("label"), str) and entry["label"].strip() else entry["key"]
|
|
53
|
+
)
|
|
54
|
+
if kind == "font":
|
|
55
|
+
if entry.get("family") not in FONT_CHOICES:
|
|
56
|
+
raise _invalid("可用的字型:" + "、".join(FONT_CHOICES) + "。")
|
|
57
|
+
result.append({"key": entry["key"], "label": label.strip()[:24], "family": entry["family"]})
|
|
49
58
|
else:
|
|
50
|
-
if not isinstance(entry.get(
|
|
51
|
-
raise _invalid(
|
|
52
|
-
result.append({
|
|
59
|
+
if not isinstance(entry.get("value"), str) or not HEX.match(entry["value"]):
|
|
60
|
+
raise _invalid("顏色要寫成 #rrggbb。")
|
|
61
|
+
result.append({"key": entry["key"], "label": label.strip()[:24], "value": entry["value"].lower()})
|
|
53
62
|
return result
|
|
54
|
-
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
"look_id": value["look_id"],
|
|
66
|
+
"name": name.strip()[:24],
|
|
67
|
+
"fonts": entries(fonts, "font"),
|
|
68
|
+
"colors": entries(colors, "color"),
|
|
69
|
+
}
|
|
55
70
|
|
|
56
71
|
|
|
57
72
|
def _path(tools):
|
|
58
|
-
return tools.repository.projects.root / tools.project_id / f
|
|
73
|
+
return tools.repository.projects.root / tools.project_id / f"component-looks-{tools.run_id}.json"
|
|
59
74
|
|
|
60
75
|
|
|
61
76
|
def stored(tools):
|
|
62
77
|
path = _path(tools)
|
|
63
78
|
if path.is_symlink():
|
|
64
|
-
raise ProjectError(
|
|
79
|
+
raise ProjectError("storage_unsafe", "外觀檔案不安全。", status_code=409)
|
|
65
80
|
if not path.exists():
|
|
66
81
|
return {}
|
|
67
|
-
return {look[
|
|
82
|
+
return {look["look_id"]: look for look in json.loads(path.read_text(encoding="utf-8"))}
|
|
68
83
|
|
|
69
84
|
|
|
70
85
|
def store(tools, looks):
|
|
71
86
|
from .production_media import atomic_json
|
|
87
|
+
|
|
72
88
|
atomic_json(_path(tools), list(looks.values()))
|
|
73
89
|
|
|
74
90
|
|
|
75
91
|
def on_film(tools, timeline=None):
|
|
76
92
|
"""(graphic, profile) for each free design on the film."""
|
|
77
93
|
from .production_media import load_text_styles
|
|
94
|
+
|
|
78
95
|
styles = load_text_styles(tools.repository.projects, tools.project_id)
|
|
79
96
|
timeline = timeline or tools._timeline()
|
|
80
|
-
return [
|
|
81
|
-
|
|
82
|
-
|
|
97
|
+
return [
|
|
98
|
+
(item, styles[item.style_id])
|
|
99
|
+
for track in timeline.tracks
|
|
100
|
+
if track.track_id == "program-components" or track.track_id.startswith("program-components-")
|
|
101
|
+
for item in track.items
|
|
102
|
+
if styles.get(item.style_id, {}).get("component_id") == "custom"
|
|
103
|
+
]
|
|
83
104
|
|
|
84
105
|
|
|
85
106
|
def current(tools):
|
|
86
107
|
"""The run's looks, as the current film has them."""
|
|
87
108
|
looks = stored(tools)
|
|
88
109
|
for _, profile in on_film(tools):
|
|
89
|
-
look = profile.get(
|
|
110
|
+
look = profile.get("look")
|
|
90
111
|
if look:
|
|
91
|
-
looks[look[
|
|
112
|
+
looks[look["look_id"]] = look
|
|
92
113
|
return looks
|
|
93
114
|
|
|
94
115
|
|
|
95
116
|
def public(look, used=0):
|
|
96
117
|
"""A look as the Agent and the review page see it, with the variables a page writes."""
|
|
97
|
-
return {
|
|
98
|
-
|
|
99
|
-
|
|
118
|
+
return {
|
|
119
|
+
**look,
|
|
120
|
+
"used_by": used,
|
|
121
|
+
"fonts": [{**f, "css": f"var(--look-font-{f['key']})"} for f in look["fonts"]],
|
|
122
|
+
"colors": [{**c, "css": f"var(--look-{c['key']})"} for c in look["colors"]],
|
|
123
|
+
}
|
|
100
124
|
|
|
101
125
|
|
|
102
126
|
def listing(tools):
|
|
103
127
|
counts = {}
|
|
104
128
|
for _, profile in on_film(tools):
|
|
105
|
-
if profile.get(
|
|
106
|
-
counts[profile[
|
|
129
|
+
if profile.get("look"):
|
|
130
|
+
counts[profile["look"]["look_id"]] = counts.get(profile["look"]["look_id"], 0) + 1
|
|
107
131
|
return [public(look, counts.get(key, 0)) for key, look in current(tools).items()]
|
|
@@ -1,78 +1,74 @@
|
|
|
1
1
|
"""Content checks that keep programme graphics tied to a moment, not a template."""
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import re
|
|
4
4
|
import unicodedata
|
|
5
|
+
from collections import Counter
|
|
5
6
|
|
|
6
7
|
# Short reactions land on one beat; a long hold reads as a static label.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
RESTATE_RATIO = .5
|
|
10
|
-
SAME_POSITION_DISTANCE = .03
|
|
8
|
+
RESTATE_RATIO = 0.5
|
|
9
|
+
SAME_POSITION_DISTANCE = 0.03
|
|
11
10
|
SAME_POSITION_RUN = 3
|
|
12
|
-
UNIFORM_DURATION_SHARE = .5
|
|
11
|
+
UNIFORM_DURATION_SHARE = 0.5
|
|
13
12
|
UNIFORM_DURATION_MINIMUM = 4
|
|
14
|
-
_PARALLEL = re.compile(r
|
|
15
|
-
_CONCRETE = re.compile(r'[\d¥¥円元$€%]')
|
|
13
|
+
_PARALLEL = re.compile(r"^[^,,・]{2,8}[,,][^,,・]{2,8}$")
|
|
16
14
|
|
|
17
15
|
|
|
18
16
|
def significant(text):
|
|
19
|
-
return
|
|
20
|
-
if unicodedata.category(c)[0] not in 'PZCS')
|
|
17
|
+
return "".join(c for c in unicodedata.normalize("NFKC", text) if unicodedata.category(c)[0] not in "PZCS")
|
|
21
18
|
|
|
22
19
|
|
|
23
20
|
def _bigrams(text):
|
|
24
21
|
text = significant(text)
|
|
25
|
-
return [text[n:n+2] for n in range(len(text)-1)]
|
|
22
|
+
return [text[n : n + 2] for n in range(len(text) - 1)]
|
|
26
23
|
|
|
27
24
|
|
|
28
25
|
def restated_ratio(text, subtitles):
|
|
29
26
|
"""Share of the graphic's character pairs copied from concurrent subtitles."""
|
|
30
27
|
pairs = _bigrams(text)
|
|
31
|
-
spoken = significant(
|
|
32
|
-
return sum(pair in spoken for pair in pairs)/len(pairs) if pairs else 0.
|
|
28
|
+
spoken = significant("".join(subtitles))
|
|
29
|
+
return sum(pair in spoken for pair in pairs) / len(pairs) if pairs else 0.0
|
|
33
30
|
|
|
34
31
|
|
|
35
32
|
def concurrent_subtitles(timeline, start, duration):
|
|
36
|
-
end = start+duration
|
|
37
|
-
return [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
+
]
|
|
44
41
|
|
|
45
42
|
|
|
46
43
|
def design_notes(timeline, elements, styles):
|
|
47
44
|
"""Advisory findings; heuristics never block delivery on their own."""
|
|
48
|
-
fps = timeline.frame_rate.numerator/timeline.frame_rate.denominator
|
|
45
|
+
fps = timeline.frame_rate.numerator / timeline.frame_rate.denominator
|
|
49
46
|
ordered = sorted(elements, key=lambda i: (i.start_frame, i.item_id))
|
|
50
47
|
notes = []
|
|
51
48
|
run = []
|
|
52
49
|
for element in ordered:
|
|
53
50
|
profile = styles.get(element.style_id, {})
|
|
54
|
-
point = (profile.get(
|
|
55
|
-
if run and None not in point and all(abs(a-b) <= SAME_POSITION_DISTANCE
|
|
56
|
-
for a, b in zip(point, run[-1][1])):
|
|
51
|
+
point = (profile.get("x"), profile.get("y"))
|
|
52
|
+
if run and None not in point and all(abs(a - b) <= SAME_POSITION_DISTANCE for a, b in zip(point, run[-1][1])):
|
|
57
53
|
run.append((element.item_id, point))
|
|
58
54
|
else:
|
|
59
55
|
if len(run) >= SAME_POSITION_RUN:
|
|
60
|
-
notes.append({
|
|
56
|
+
notes.append({"code": "component_position_repeated", "item_ids": [i for i, _ in run]})
|
|
61
57
|
run = [(element.item_id, point)] if None not in point else []
|
|
62
58
|
if len(run) >= SAME_POSITION_RUN:
|
|
63
|
-
notes.append({
|
|
59
|
+
notes.append({"code": "component_position_repeated", "item_ids": [i for i, _ in run]})
|
|
64
60
|
if len(ordered) >= UNIFORM_DURATION_MINIMUM:
|
|
65
|
-
duration, count = Counter(round(i.duration_frames/fps*2)/2 for i in ordered).most_common(1)[0]
|
|
66
|
-
if count/len(ordered) > UNIFORM_DURATION_SHARE:
|
|
67
|
-
notes.append({
|
|
61
|
+
duration, count = Counter(round(i.duration_frames / fps * 2) / 2 for i in ordered).most_common(1)[0]
|
|
62
|
+
if count / len(ordered) > UNIFORM_DURATION_SHARE:
|
|
63
|
+
notes.append({"code": "component_duration_uniform", "seconds": duration, "count": count})
|
|
68
64
|
for element in ordered:
|
|
69
|
-
kind = styles.get(element.style_id, {}).get(
|
|
70
|
-
primary = element.text.partition(
|
|
71
|
-
if kind not in {
|
|
72
|
-
notes.append({
|
|
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})
|
|
73
69
|
messages = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
"component_position_repeated": "連續多個元件擺在同一位置。請依每個畫面的人物、物件與空白處重新決定位置。",
|
|
71
|
+
"component_duration_uniform": "多數元件的顯示時長相同,節奏像固定節拍。請依每個瞬間的閱讀需要調整。",
|
|
72
|
+
"component_parallel_phrasing": "「A,B」對句常只是描述畫面。請改成畫面看不出的資訊或觀點,或移除這個元件。",
|
|
77
73
|
}
|
|
78
|
-
return [{**note,
|
|
74
|
+
return [{**note, "message": messages[note["code"]]} for note in notes]
|