@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.
Files changed (132) hide show
  1. package/README.md +56 -48
  2. package/apps/web/dist/assets/{index-D5D2HiB1.js → index-DPHwA954.js} +1 -1
  3. package/apps/web/dist/index.html +1 -1
  4. package/bin/clipen.js +1 -1
  5. package/package.json +7 -6
  6. package/pyproject.toml +18 -2
  7. package/requirements/dev.txt +2 -0
  8. package/src/clipen/__init__.py +1 -1
  9. package/src/clipen/analysis/__init__.py +7 -7
  10. package/src/clipen/analysis/artifacts.py +4 -10
  11. package/src/clipen/analysis/audio.py +10 -8
  12. package/src/clipen/analysis/evidence_service.py +345 -167
  13. package/src/clipen/analysis/image_similarity.py +5 -14
  14. package/src/clipen/analysis/keyframes.py +5 -17
  15. package/src/clipen/analysis/models.py +5 -7
  16. package/src/clipen/analysis/qwen_worker.py +19 -54
  17. package/src/clipen/analysis/resources.py +2 -1
  18. package/src/clipen/analysis/runtime.py +1 -3
  19. package/src/clipen/analysis/service.py +16 -48
  20. package/src/clipen/analysis/setup.py +11 -25
  21. package/src/clipen/analysis/setup_cli.py +5 -15
  22. package/src/clipen/analysis/storage.py +96 -278
  23. package/src/clipen/analysis/transcription.py +40 -82
  24. package/src/clipen/analysis/visual.py +109 -48
  25. package/src/clipen/annotations/__init__.py +5 -2
  26. package/src/clipen/annotations/models.py +1 -1
  27. package/src/clipen/annotations/storage.py +132 -84
  28. package/src/clipen/annotations/suggestions.py +3 -8
  29. package/src/clipen/asr_release.py +4 -11
  30. package/src/clipen/bootstrap.py +71 -61
  31. package/src/clipen/{planning/models.py → candidates.py} +29 -47
  32. package/src/clipen/cli.py +4 -9
  33. package/src/clipen/controller/app.py +401 -214
  34. package/src/clipen/controller/server.py +28 -38
  35. package/src/clipen/domain/__init__.py +1 -1
  36. package/src/clipen/domain/media_time.py +3 -10
  37. package/src/clipen/domain/timeline.py +45 -47
  38. package/src/clipen/domain/validation.py +0 -1
  39. package/src/clipen/editing/__init__.py +1 -1
  40. package/src/clipen/editing/agent_models.py +4 -11
  41. package/src/clipen/editing/agent_repository.py +393 -172
  42. package/src/clipen/editing/agent_tools.py +180 -99
  43. package/src/clipen/editing/alignment.py +92 -52
  44. package/src/clipen/editing/alignment_setup.py +118 -70
  45. package/src/clipen/editing/alignment_worker.py +11 -9
  46. package/src/clipen/editing/change_report.py +95 -38
  47. package/src/clipen/editing/compiler.py +0 -1
  48. package/src/clipen/editing/component_looks.py +58 -34
  49. package/src/clipen/editing/component_review.py +34 -38
  50. package/src/clipen/editing/coordinator.py +213 -92
  51. package/src/clipen/editing/editorial_review.py +217 -95
  52. package/src/clipen/editing/evidence_jobs.py +457 -200
  53. package/src/clipen/editing/history_changes.py +129 -68
  54. package/src/clipen/editing/music_choices.py +8 -5
  55. package/src/clipen/editing/production_catalog.py +573 -136
  56. package/src/clipen/editing/production_limits.py +43 -17
  57. package/src/clipen/editing/production_media.py +376 -167
  58. package/src/clipen/editing/production_preview.py +322 -129
  59. package/src/clipen/editing/production_progress.py +164 -69
  60. package/src/clipen/editing/production_requirements.py +106 -39
  61. package/src/clipen/editing/production_tools.py +1064 -462
  62. package/src/clipen/editing/program_audio.py +211 -81
  63. package/src/clipen/editing/program_direction.py +59 -25
  64. package/src/clipen/editing/program_story.py +83 -45
  65. package/src/clipen/editing/program_subtitles.py +194 -96
  66. package/src/clipen/editing/programme_review.py +98 -50
  67. package/src/clipen/editing/prompt_history.py +64 -27
  68. package/src/clipen/editing/recut.py +65 -25
  69. package/src/clipen/editing/refinement_references.py +176 -86
  70. package/src/clipen/editing/resolve_export.py +449 -218
  71. package/src/clipen/editing/resolve_titles.py +162 -105
  72. package/src/clipen/editing/skill_tools.py +530 -154
  73. package/src/clipen/editing/source_dialogue.py +177 -67
  74. package/src/clipen/editing/speech_coverage.py +42 -22
  75. package/src/clipen/editing/speech_quality.py +6 -1
  76. package/src/clipen/editing/tool_receipts.py +78 -32
  77. package/src/clipen/editing/versions.py +122 -64
  78. package/src/clipen/editing/visual_preview.py +157 -61
  79. package/src/clipen/editing/workbench.py +104 -42
  80. package/src/clipen/finishing/audio.py +69 -30
  81. package/src/clipen/finishing/catalog.py +176 -93
  82. package/src/clipen/finishing/models.py +1 -1
  83. package/src/clipen/finishing/renderer.py +33 -14
  84. package/src/clipen/mcp_editing/__main__.py +3 -1
  85. package/src/clipen/mcp_editing/server.py +77 -34
  86. package/src/clipen/media/__init__.py +3 -3
  87. package/src/clipen/media/discovery.py +7 -20
  88. package/src/clipen/media/models.py +7 -18
  89. package/src/clipen/media/preview.py +14 -24
  90. package/src/clipen/media/probe.py +16 -44
  91. package/src/clipen/media/service.py +6 -19
  92. package/src/clipen/media/storage.py +33 -81
  93. package/src/clipen/music_vocabulary.py +33 -4
  94. package/src/clipen/power.py +8 -3
  95. package/src/clipen/projects/__init__.py +1 -1
  96. package/src/clipen/projects/deletion.py +19 -32
  97. package/src/clipen/projects/finishing_schema.py +3 -1
  98. package/src/clipen/projects/models.py +2 -5
  99. package/src/clipen/projects/picker.py +13 -37
  100. package/src/clipen/projects/service.py +8 -24
  101. package/src/clipen/projects/storage.py +226 -246
  102. package/src/clipen/provider_registry.py +9 -20
  103. package/src/clipen/providers/account.py +86 -35
  104. package/src/clipen/providers/claude.py +59 -25
  105. package/src/clipen/providers/claude_editing.py +14 -7
  106. package/src/clipen/providers/codex.py +73 -118
  107. package/src/clipen/providers/codex_editing.py +2 -2
  108. package/src/clipen/providers/editing_agent.py +19 -17
  109. package/src/clipen/providers/recovery.py +7 -8
  110. package/src/clipen/rendering/cover.py +18 -5
  111. package/src/clipen/rendering/custom_components.py +167 -79
  112. package/src/clipen/rendering/custom_render.py +62 -41
  113. package/src/clipen/rendering/production_effects.py +77 -45
  114. package/src/clipen/rendering/program_components.py +134 -73
  115. package/src/clipen/rendering/program_creator.py +432 -277
  116. package/src/clipen/rendering/program_identities.py +277 -182
  117. package/src/clipen/rendering/program_motion.py +140 -95
  118. package/src/clipen/rendering/program_studio.py +175 -116
  119. package/src/clipen/rendering/program_styles.py +231 -145
  120. package/src/clipen/rendering/program_subtitles.py +71 -34
  121. package/src/clipen/rendering/renderer.py +150 -121
  122. package/src/clipen/rendering/storage.py +9 -22
  123. package/src/clipen/rendering/titles.py +193 -86
  124. package/src/clipen/skills/__init__.py +1 -0
  125. package/src/clipen/skills/catalog.py +151 -55
  126. package/src/clipen/skills/library.py +13 -7
  127. package/src/clipen/skills/package.py +46 -23
  128. package/src/clipen/skills/visual_styles.py +29 -18
  129. package/src/clipen/workspace.py +15 -44
  130. package/install +0 -25
  131. package/src/clipen/planning/__init__.py +0 -9
  132. 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 = {'done': '已處理', 'partly': '部分處理', 'not_done': '沒有處理', 'kept': '照你說的保留'}
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 = {'needs_you': '需要你決定或提供', 'cannot': 'Clipen 目前做不到'}
9
- UNFINISHED = 'change_report_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('change_report_invalid', message, status_code=422)
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('changes')
23
- if not isinstance(changes, list) or not 1 <= len(changes) <= 20 or not all(
24
- isinstance(c, dict) and set(c) <= {'what', 'why'} and _text(c.get('what'), 200) and _text(c.get('why'), 300) for c in changes):
25
- raise _invalid('finish_edit 要附上修改說明:changes 列出 1–20 項,每項寫 what(改了什麼,200 字內)與 why(為什麼,300 字內),用觀眾看得懂的話。')
26
- not_done = arguments.get('not_done', [])
27
- if not isinstance(not_done, list) or len(not_done) > 10 or not all(
28
- isinstance(item, dict) and set(item) <= {'what', 'reason', 'detail'} and item.get('reason') in REASONS
29
- and _text(item.get('what'), 200) and _text(item.get('detail'), 300) for item in not_done):
30
- raise _invalid('not_done 每項要有 what(沒做到什麼)、reason 與 detail,最多 10 項。reason 只能是 needs_you'
31
- '(detail 寫使用者要決定或提供什麼)或 cannot(detail 寫是哪個工具限制做不到)。'
32
- '你的工具做得到的事不能列在這裡,要先做完。')
33
- request = intent.get('latest_revision_request') or {}
34
- sent = {item['reference_id'] for item in (request.get('references') or {}).get('items', []) if isinstance(item, dict) and 'reference_id' in item}
35
- notes = arguments.get('notes', [])
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
- isinstance(n, dict) and set(n) <= {'reference_id', 'outcome', 'explanation', 'reason'} and n.get('outcome') in OUTCOMES
38
- and _text(n.get('explanation'), 300) and isinstance(n.get('reference_id'), str) for n in notes):
39
- raise _invalid('notes 每項要有 reference_id、outcome(done/partly/not_done/kept)與 explanation(300 字內)。')
40
- if any(n['outcome'] in ('partly', 'not_done') and n.get('reason') not in REASONS for n in notes):
41
- raise _invalid('outcome 是 partly 或 not_done 的注記要附 reason:needs_you(需要使用者決定或提供)或 cannot(工具做不到)。'
42
- '你的工具做得到的就先做完,再回報 done。')
43
- answered = [n['reference_id'] for n in notes]
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(f'使用者這次送了 {len(sent)} 筆注記,notes 要逐筆回應每一筆(reference_id 不重複、不多不少)'
47
- + (f';還有 {missing} 筆沒回應。' if missing else '。'))
48
- return {'changes': [{'what': c['what'].strip(), 'why': c['why'].strip()} for c in changes],
49
- 'notes': [{'reference_id': n['reference_id'], 'outcome': n['outcome'], 'explanation': n['explanation'].strip(),
50
- **({'reason': n['reason']} if n['outcome'] in ('partly', 'not_done') else {})} for n in notes],
51
- 'not_done': [{'what': i['what'].strip(), 'reason': i['reason'], 'detail': i['detail'].strip()} for i in not_done]}
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 ([f"注記 {n['reference_id']}:{n['explanation']}" for n in report['notes'] if n['outcome'] in ('partly', 'not_done')]
57
- + [f"{i['what']}({i['detail']})" for i in report['not_done']])
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(UNFINISHED, '修改說明裡還有沒做完的地方:' + ';'.join(left)[:900]
64
- + '。用你的工具做得到的,現在就做完並改回報 done;只有真的需要使用者決定或提供、或工具確實做不到的才保留,'
65
- '確認後再呼叫一次 finish_edit。', status_code=409)
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 [{'what': i['what'], 'reason': i['reason'], 'detail': i['detail']} for i in report.get('not_done', [])
71
- if isinstance(i, dict) and i.get('reason') in REASONS]
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
+ ]
@@ -4,7 +4,6 @@ from __future__ import annotations
4
4
 
5
5
  from dataclasses import dataclass
6
6
 
7
-
8
7
  _PRESETS = {
9
8
  "landscape_1080p": (1920, 1080),
10
9
  "portrait_1080p": (1080, 1920),
@@ -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'^[A-Za-z0-9_\-一-鿿]{1,24}$')
20
- HEX = re.compile(r'^#[0-9a-fA-F]{6}$')
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('component_look_invalid', message, status_code=422)
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('look_id'), str) or not KEY.match(value['look_id']):
31
- raise _invalid('look_id 要是 1–24 個字的英數字、中文、- 或 _。')
32
- name = value.get('name') if isinstance(value.get('name'), str) and value['name'].strip() else value['look_id']
33
- fonts, colors = value.get('fonts'), value.get('colors', [])
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'每個外觀要有 1–{MAX_FONTS} 套字型。')
36
+ raise _invalid(f"每個外觀要有 1–{MAX_FONTS} 套字型。")
36
37
  if not isinstance(colors, list) or len(colors) > MAX_COLORS:
37
- raise _invalid(f'每個外觀最多 {MAX_COLORS} 個顏色。')
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 not isinstance(entry, dict) or not isinstance(entry.get('key'), str) or not KEY.match(entry['key']) or entry['key'] in seen:
42
- raise _invalid('字型與顏色的 key 要是不重複的英數字、中文、- 或 _。')
43
- seen.add(entry['key'])
44
- label = entry.get('label') if isinstance(entry.get('label'), str) and entry['label'].strip() else entry['key']
45
- if kind == 'font':
46
- if entry.get('family') not in FONT_CHOICES:
47
- raise _invalid('可用的字型:' + '、'.join(FONT_CHOICES) + '。')
48
- result.append({'key': entry['key'], 'label': label.strip()[:24], 'family': entry['family']})
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('value'), str) or not HEX.match(entry['value']):
51
- raise _invalid('顏色要寫成 #rrggbb。')
52
- result.append({'key': entry['key'], 'label': label.strip()[:24], 'value': entry['value'].lower()})
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
- return {'look_id': value['look_id'], 'name': name.strip()[:24], 'fonts': entries(fonts, 'font'), 'colors': entries(colors, 'color')}
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'component-looks-{tools.run_id}.json'
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('storage_unsafe', '外觀檔案不安全。', status_code=409)
79
+ raise ProjectError("storage_unsafe", "外觀檔案不安全。", status_code=409)
65
80
  if not path.exists():
66
81
  return {}
67
- return {look['look_id']: look for look in json.loads(path.read_text(encoding='utf-8'))}
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 [(item, styles[item.style_id]) for track in timeline.tracks
81
- if track.track_id == 'program-components' or track.track_id.startswith('program-components-')
82
- for item in track.items if styles.get(item.style_id, {}).get('component_id') == 'custom']
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('look')
110
+ look = profile.get("look")
90
111
  if look:
91
- looks[look['look_id']] = 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 {**look, 'used_by': used,
98
- 'fonts': [{**f, 'css': f'var(--look-font-{f["key"]})'} for f in look['fonts']],
99
- 'colors': [{**c, 'css': f'var(--look-{c["key"]})'} for c in look['colors']]}
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('look'):
106
- counts[profile['look']['look_id']] = counts.get(profile['look']['look_id'], 0) + 1
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
- from collections import Counter
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
- REACTION_COMPONENTS = frozenset({'reaction', 'impact', 'burst'})
8
- REACTION_MAX_SECONDS = 2
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'^[^,,・]{2,8}[,,][^,,・]{2,8}$')
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 ''.join(c for c in unicodedata.normalize('NFKC', text)
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(''.join(subtitles))
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 [i.text for t in timeline.tracks if t.track_id == 'agent-subtitles' for i in t.items
38
- if i.start_frame < end and start < i.start_frame+i.duration_frames]
39
-
40
-
41
- def fact_has_information(text, detail):
42
- """A fact carries a grounded detail line or a concrete number/price."""
43
- return bool(detail.strip()) or bool(_CONCRETE.search(text))
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('x'), profile.get('y'))
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({'code': 'component_position_repeated', 'item_ids': [i for i, _ in run]})
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({'code': 'component_position_repeated', 'item_ids': [i for i, _ in run]})
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({'code': 'component_duration_uniform', 'seconds': duration, 'count': count})
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('component_id')
70
- primary = element.text.partition('\n')[0]
71
- if kind not in {'program_title'} and _PARALLEL.match(primary):
72
- notes.append({'code': 'component_parallel_phrasing', 'item_id': element.item_id, 'text': primary})
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
- 'component_position_repeated': '連續多個元件擺在同一位置。請依每個畫面的人物、物件與空白處重新決定位置。',
75
- 'component_duration_uniform': '多數元件的顯示時長相同,節奏像固定節拍。請依每個瞬間的閱讀需要調整。',
76
- 'component_parallel_phrasing': '「A,B」對句常只是描述畫面。請改成畫面看不出的資訊或觀點,或移除這個元件。',
70
+ "component_position_repeated": "連續多個元件擺在同一位置。請依每個畫面的人物、物件與空白處重新決定位置。",
71
+ "component_duration_uniform": "多數元件的顯示時長相同,節奏像固定節拍。請依每個瞬間的閱讀需要調整。",
72
+ "component_parallel_phrasing": "「A,B」對句常只是描述畫面。請改成畫面看不出的資訊或觀點,或移除這個元件。",
77
73
  }
78
- return [{**note, 'message': messages[note['code']]} for note in notes]
74
+ return [{**note, "message": messages[note["code"]]} for note in notes]