@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,64 +1,96 @@
1
1
  """Trusted filter builders for timed masks, transitions, grade and camera sound."""
2
+
2
3
  import math
4
+
3
5
  from clipen.projects import ProjectError
4
6
 
5
7
 
6
- def mosaic_filters(filters,label,item,timeline,index):
7
- fps=timeline.frame_rate.numerator/timeline.frame_rate.denominator
8
- regions=[r for e in item.effects if e.effect_id=='video.mosaic' for r in e.parameters['regions']]
9
- for n,r in enumerate(regions):
10
- if not all(isinstance(r[k],(int,float)) and not isinstance(r[k],bool) and math.isfinite(r[k]) for k in ('x','y','width','height','block_size','start_frame','duration_frames')):
11
- raise ProjectError('agent_mosaic_invalid','馬賽克參數必須是有限數字。',status_code=422)
12
- if not (0<=r['x']<1 and 0<=r['y']<1 and 0<r['width']<=1-r['x'] and 0<r['height']<=1-r['y'] and 4<=r['block_size']<=96 and 0<=r['start_frame']<item.duration_frames and 0<r['duration_frames']<=item.duration_frames-r['start_frame']):
13
- raise ProjectError('agent_mosaic_invalid','馬賽克區域或時間超出範圍。',status_code=422)
14
- width=max(2,min(timeline.width,round(timeline.width*r['width'])//2*2));height=max(2,min(timeline.height,round(timeline.height*r['height'])//2*2))
15
- x=min(timeline.width-width,round(timeline.width*r['x'])//2*2);y=min(timeline.height-height,round(timeline.height*r['y'])//2*2)
16
- small_w=max(1,math.ceil(width/r['block_size']));small_h=max(1,math.ceil(height/r['block_size']))
17
- stem=f'mosaic{index}_{n}';output=stem+'out'
18
- filters.append(f'[{label}]split=2[{stem}base][{stem}crop]')
19
- filters.append(f'[{stem}crop]crop={width}:{height}:{x}:{y},scale={small_w}:{small_h}:flags=area,scale={width}:{height}:flags=neighbor[{stem}pixel]')
20
- start=r['start_frame']/fps;end=(r['start_frame']+r['duration_frames'])/fps
21
- filters.append(f"[{stem}base][{stem}pixel]overlay={x}:{y}:enable='gte(t,{start:.9f})*lt(t,{end:.9f})'[{output}]")
22
- label=output
8
+ def mosaic_filters(filters, label, item, timeline, index):
9
+ fps = timeline.frame_rate.numerator / timeline.frame_rate.denominator
10
+ regions = [r for e in item.effects if e.effect_id == "video.mosaic" for r in e.parameters["regions"]]
11
+ for n, r in enumerate(regions):
12
+ if not all(
13
+ isinstance(r[k], (int, float)) and not isinstance(r[k], bool) and math.isfinite(r[k])
14
+ for k in ("x", "y", "width", "height", "block_size", "start_frame", "duration_frames")
15
+ ):
16
+ raise ProjectError("agent_mosaic_invalid", "馬賽克參數必須是有限數字。", status_code=422)
17
+ if not (
18
+ 0 <= r["x"] < 1
19
+ and 0 <= r["y"] < 1
20
+ and 0 < r["width"] <= 1 - r["x"]
21
+ and 0 < r["height"] <= 1 - r["y"]
22
+ and 4 <= r["block_size"] <= 96
23
+ and 0 <= r["start_frame"] < item.duration_frames
24
+ and 0 < r["duration_frames"] <= item.duration_frames - r["start_frame"]
25
+ ):
26
+ raise ProjectError("agent_mosaic_invalid", "馬賽克區域或時間超出範圍。", status_code=422)
27
+ width = max(2, min(timeline.width, round(timeline.width * r["width"]) // 2 * 2))
28
+ height = max(2, min(timeline.height, round(timeline.height * r["height"]) // 2 * 2))
29
+ x = min(timeline.width - width, round(timeline.width * r["x"]) // 2 * 2)
30
+ y = min(timeline.height - height, round(timeline.height * r["y"]) // 2 * 2)
31
+ small_w = max(1, math.ceil(width / r["block_size"]))
32
+ small_h = max(1, math.ceil(height / r["block_size"]))
33
+ stem = f"mosaic{index}_{n}"
34
+ output = stem + "out"
35
+ filters.append(f"[{label}]split=2[{stem}base][{stem}crop]")
36
+ filters.append(
37
+ f"[{stem}crop]crop={width}:{height}:{x}:{y},scale={small_w}:{small_h}:flags=area,scale={width}:{height}:flags=neighbor[{stem}pixel]"
38
+ )
39
+ start = r["start_frame"] / fps
40
+ end = (r["start_frame"] + r["duration_frames"]) / fps
41
+ filters.append(
42
+ f"[{stem}base][{stem}pixel]overlay={x}:{y}:enable='gte(t,{start:.9f})*lt(t,{end:.9f})'[{output}]"
43
+ )
44
+ label = output
23
45
  return label
24
46
 
25
47
 
26
48
  def grade_filters(item):
27
- grade=next((e.parameters for e in item.effects if e.effect_id=='video.grade'),None)
28
- if grade is None:return ''
29
- values=(float(grade['contrast']),float(grade['saturation']),float(grade['brightness']))
30
- if not (.5<=values[0]<=2 and 0<=values[1]<=2 and -.3<=values[2]<=.3):raise ValueError('invalid grade')
31
- return f',eq=contrast={values[0]:.6f}:saturation={values[1]:.6f}:brightness={values[2]:.6f}'
49
+ grade = next((e.parameters for e in item.effects if e.effect_id == "video.grade"), None)
50
+ if grade is None:
51
+ return ""
52
+ values = (float(grade["contrast"]), float(grade["saturation"]), float(grade["brightness"]))
53
+ if not (0.5 <= values[0] <= 2 and 0 <= values[1] <= 2 and -0.3 <= values[2] <= 0.3):
54
+ raise ValueError("invalid grade")
55
+ return f",eq=contrast={values[0]:.6f}:saturation={values[1]:.6f}:brightness={values[2]:.6f}"
32
56
 
33
57
 
34
- def transition_filters(item,following,timeline):
35
- fps=timeline.frame_rate.numerator/timeline.frame_rate.denominator
36
- incoming=next((e.parameters for e in item.effects if e.effect_id=='video.transition'),None)
37
- outgoing=next((e.parameters for e in following.effects if e.effect_id=='video.transition'),None) if following else next((e.parameters for e in item.effects if e.effect_id=='video.transition_out'),None)
38
- result=''
39
- for kind,p in (('in',incoming),('out',outgoing)):
58
+ def transition_filters(item, following, timeline):
59
+ fps = timeline.frame_rate.numerator / timeline.frame_rate.denominator
60
+ incoming = next((e.parameters for e in item.effects if e.effect_id == "video.transition"), None)
61
+ outgoing = (
62
+ next((e.parameters for e in following.effects if e.effect_id == "video.transition"), None)
63
+ if following
64
+ else next((e.parameters for e in item.effects if e.effect_id == "video.transition_out"), None)
65
+ )
66
+ result = ""
67
+ for kind, p in (("in", incoming), ("out", outgoing)):
40
68
  if p:
41
- duration=p['duration_frames']/fps/2
42
- start=0 if kind=='in' else max(0,item.duration_frames/fps-duration)
43
- color='white' if p['kind']=='dip_white' else 'black'
44
- result+=f',fade=t={kind}:st={start:.9f}:d={duration:.9f}:color={color}'
45
- fade=next((e.parameters for e in item.effects if e.effect_id=='video.fade'),None)
69
+ duration = p["duration_frames"] / fps / 2
70
+ start = 0 if kind == "in" else max(0, item.duration_frames / fps - duration)
71
+ color = "white" if p["kind"] == "dip_white" else "black"
72
+ result += f",fade=t={kind}:st={start:.9f}:d={duration:.9f}:color={color}"
73
+ fade = next((e.parameters for e in item.effects if e.effect_id == "video.fade"), None)
46
74
  if fade:
47
- for kind,key in (('in','fade_in_frames'),('out','fade_out_frames')):
48
- frames=fade[key]
49
- if isinstance(frames,bool) or not isinstance(frames,int) or frames<0:raise ValueError('invalid fade')
75
+ for kind, key in (("in", "fade_in_frames"), ("out", "fade_out_frames")):
76
+ frames = fade[key]
77
+ if isinstance(frames, bool) or not isinstance(frames, int) or frames < 0:
78
+ raise ValueError("invalid fade")
50
79
  if frames:
51
- duration=frames/fps
52
- start=0 if kind=='in' else item.duration_frames/fps-duration
53
- if start<0:raise ValueError('fade exceeds clip')
54
- result+=f',fade=t={kind}:st={start:.9f}:d={duration:.9f}:color=black'
80
+ duration = frames / fps
81
+ start = 0 if kind == "in" else item.duration_frames / fps - duration
82
+ if start < 0:
83
+ raise ValueError("fade exceeds clip")
84
+ result += f",fade=t={kind}:st={start:.9f}:d={duration:.9f}:color=black"
55
85
  return result
56
86
 
57
87
 
58
88
  def camera_audio_filters(item):
59
- policy=next((e.parameters for e in item.effects if e.effect_id=='audio.source'),None)
60
- if policy is None:return ''
61
- gain=-120 if policy['mode']=='mute' else policy['gain_db']
62
- result=f',volume={float(gain):.6f}dB'
63
- if policy['mode']=='dialogue':result+=',highpass=f=85,lowpass=f=11000,acompressor=threshold=0.125:ratio=2'
89
+ policy = next((e.parameters for e in item.effects if e.effect_id == "audio.source"), None)
90
+ if policy is None:
91
+ return ""
92
+ gain = -120 if policy["mode"] == "mute" else policy["gain_db"]
93
+ result = f",volume={float(gain):.6f}dB"
94
+ if policy["mode"] == "dialogue":
95
+ result += ",highpass=f=85,lowpass=f=11000,acompressor=threshold=0.125:ratio=2"
64
96
  return result
@@ -1,29 +1,38 @@
1
1
  """Deterministic in-picture graphics for versioned programme skill packages."""
2
+
2
3
  import math
3
4
 
4
5
  from PIL import Image, ImageDraw
5
6
 
7
+ from . import custom_components, program_creator, program_identities
8
+ from .program_motion import FAMILIES, draw_motion_graphic, layout, motion_frames
9
+ from .program_styles import draw_styled_graphic, load_style_font, skin, style_font, styled_text_length, type_outline
6
10
  from .titles import TitleRenderError
7
- from .program_motion import FAMILIES, layout, motion_frames, draw_motion_graphic
8
- from .program_styles import skin, style_font, load_style_font, styled_text_length, draw_styled_graphic, type_outline
9
- from . import program_identities
10
- from . import program_creator
11
- from . import custom_components
12
11
 
13
12
 
14
13
  def animation_boundaries(item, profile, timeline=None):
15
14
  if custom_components.is_custom(profile):
16
15
  # A free design can change on any frame; the frames themselves say where.
17
- return custom_components.changes(timeline, item, profile) if timeline is not None else set(range(item.start_frame, item.start_frame+item.duration_frames+1))
16
+ return (
17
+ custom_components.changes(timeline, item, profile)
18
+ if timeline is not None
19
+ else set(range(item.start_frame, item.start_frame + item.duration_frames + 1))
20
+ )
18
21
  motion = profile["presets"]["motion"]
19
22
  if program_creator.is_creator(profile):
20
23
  entry_length, exit_length = program_creator.frames(profile)
21
24
  else:
22
- entry_length, exit_length = motion_frames(profile["component_id"],profile) if profile["component_id"] in FAMILIES else (motion["entry_frames"], motion["exit_frames"])
25
+ entry_length, exit_length = (
26
+ motion_frames(profile["component_id"], profile)
27
+ if profile["component_id"] in FAMILIES
28
+ else (motion["entry_frames"], motion["exit_frames"])
29
+ )
23
30
  entry = min(entry_length, item.duration_frames)
24
31
  exit_frames = min(exit_length, item.duration_frames)
25
- return {item.start_frame+n for n in
26
- (*range(entry+1), *range(item.duration_frames-exit_frames, item.duration_frames+1))}
32
+ return {
33
+ item.start_frame + n
34
+ for n in (*range(entry + 1), *range(item.duration_frames - exit_frames, item.duration_frames + 1))
35
+ }
27
36
 
28
37
 
29
38
  def _bounds(draw, font_path, timeline, item, profile):
@@ -31,27 +40,40 @@ def _bounds(draw, font_path, timeline, item, profile):
31
40
  return program_creator.layout(draw, font_path, timeline, item, profile)
32
41
  if program_identities.identity(profile):
33
42
  return program_identities.layout(draw, font_path, timeline, item, profile)
34
- if profile['component_id'] in FAMILIES:
43
+ if profile["component_id"] in FAMILIES:
35
44
  return layout(draw, font_path, timeline, item, profile)
36
- if skin(profile) == 'studio':
45
+ if skin(profile) == "studio":
37
46
  from .program_studio import layout as studio_layout
47
+
38
48
  return studio_layout(draw, font_path, timeline, item, profile)
39
- font_path=style_font(font_path,profile)
40
- typography=profile['presets'].get('typography',{})
41
- scale = typography.get('reaction',.064) if profile["component_id"] == "reaction" else typography.get('component_primary',.038)
42
- font = load_style_font(font_path,max(14,round(timeline.height*scale)),profile)
43
- primary,_,detail=item.text.partition('\n')
44
- detail_font=load_style_font(font_path,max(12,round(timeline.height*typography.get('component_detail',.024))),profile,role='detail')
45
- width = max(styled_text_length(primary,font), styled_text_length(detail,detail_font) if detail else 0)
46
- pad = max(8, round(timeline.height*.016))
47
- x, y = round(timeline.width*profile["x"]), round(timeline.height*profile["y"])
48
- box_width=max(math.ceil(width)+pad*2,round(timeline.width*.15))
49
- box_height=round(timeline.height*scale*1.65)+pad
50
- if profile['component_id']!='reaction':box_height+=round(timeline.height*.025)
51
- if detail:box_height+=round(timeline.height*.038)
52
- if box_width > timeline.width*.58 or x+box_width > timeline.width*.95 or y+box_height > timeline.height*.77:
49
+ font_path = style_font(font_path, profile)
50
+ typography = profile["presets"].get("typography", {})
51
+ scale = (
52
+ typography.get("reaction", 0.064)
53
+ if profile["component_id"] == "reaction"
54
+ else typography.get("component_primary", 0.038)
55
+ )
56
+ font = load_style_font(font_path, max(14, round(timeline.height * scale)), profile)
57
+ primary, _, detail = item.text.partition("\n")
58
+ detail_font = load_style_font(
59
+ font_path, max(12, round(timeline.height * typography.get("component_detail", 0.024))), profile, role="detail"
60
+ )
61
+ width = max(styled_text_length(primary, font), styled_text_length(detail, detail_font) if detail else 0)
62
+ pad = max(8, round(timeline.height * 0.016))
63
+ x, y = round(timeline.width * profile["x"]), round(timeline.height * profile["y"])
64
+ box_width = max(math.ceil(width) + pad * 2, round(timeline.width * 0.15))
65
+ box_height = round(timeline.height * scale * 1.65) + pad
66
+ if profile["component_id"] != "reaction":
67
+ box_height += round(timeline.height * 0.025)
68
+ if detail:
69
+ box_height += round(timeline.height * 0.038)
70
+ if (
71
+ box_width > timeline.width * 0.58
72
+ or x + box_width > timeline.width * 0.95
73
+ or y + box_height > timeline.height * 0.77
74
+ ):
53
75
  raise TitleRenderError("program_component_overflow")
54
- return (x, y, x+box_width, y+box_height), font, pad
76
+ return (x, y, x + box_width, y + box_height), font, pad
55
77
 
56
78
 
57
79
  def _draw(draw, font_path, timeline, item, profile, relative_frame=None):
@@ -63,11 +85,11 @@ def _draw(draw, font_path, timeline, item, profile, relative_frame=None):
63
85
  bounds, font, pad = _bounds(draw, font_path, timeline, item, profile)
64
86
  motion = profile["presets"]["motion"]
65
87
  relative = motion["entry_frames"] if relative_frame is None else relative_frame
66
- entering = min(1., max(0., (relative+1)/motion["entry_frames"]))
67
- leaving = min(1., (item.duration_frames-relative)/motion["exit_frames"])
88
+ entering = min(1.0, max(0.0, (relative + 1) / motion["entry_frames"]))
89
+ leaving = min(1.0, (item.duration_frames - relative) / motion["exit_frames"])
68
90
  opacity = min(entering, leaving)
69
- eased = 1-(1-entering)**3
70
- dx = round((1-eased)*timeline.width*motion["entry_distance_ratio"])
91
+ eased = 1 - (1 - entering) ** 3
92
+ dx = round((1 - eased) * timeline.width * motion["entry_distance_ratio"])
71
93
  x, y, right, bottom = bounds
72
94
  x -= dx
73
95
  right -= dx
@@ -75,65 +97,102 @@ def _draw(draw, font_path, timeline, item, profile, relative_frame=None):
75
97
 
76
98
  def color(name):
77
99
  r, g, b, a = palette[name]
78
- return (r, g, b, round(a*opacity))
100
+ return (r, g, b, round(a * opacity))
79
101
 
80
102
  kind = profile["component_id"]
81
- primary,_,detail=item.text.partition('\n')
82
- stroke = max(2, round(timeline.height*.004))
103
+ primary, _, detail = item.text.partition("\n")
104
+ stroke = max(2, round(timeline.height * 0.004))
83
105
  if identity:
84
- program_identities.draw_graphic(draw,font_path,timeline,item,profile,bounds,font,pad,relative_frame)
85
- elif skin(profile)!="variety":
86
- draw_styled_graphic(draw,font_path,timeline,item,profile,bounds,font,pad,relative_frame)
106
+ program_identities.draw_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame)
107
+ elif skin(profile) != "variety":
108
+ draw_styled_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame)
87
109
  elif kind == "reaction":
88
- draw.text((x+pad, y+pad//2), primary, font=font, fill=color("accent"),
89
- stroke_width=type_outline(profile,font,stroke*2), stroke_fill=color("ink"))
110
+ draw.text(
111
+ (x + pad, y + pad // 2),
112
+ primary,
113
+ font=font,
114
+ fill=color("accent"),
115
+ stroke_width=type_outline(profile, font, stroke * 2),
116
+ stroke_fill=color("ink"),
117
+ )
90
118
  if detail:
91
- detail_font=load_style_font(font_path,max(12,round(timeline.height*.024)),profile,role='detail')
92
- draw.text((x+pad,y+pad+round(timeline.height*.075)),detail,font=detail_font,fill=color('paper'),
93
- stroke_width=stroke,stroke_fill=color('ink'))
119
+ detail_font = load_style_font(font_path, max(12, round(timeline.height * 0.024)), profile, role="detail")
120
+ draw.text(
121
+ (x + pad, y + pad + round(timeline.height * 0.075)),
122
+ detail,
123
+ font=detail_font,
124
+ fill=color("paper"),
125
+ stroke_width=stroke,
126
+ stroke_fill=color("ink"),
127
+ )
94
128
  # A short pair of ticks gives an actual reaction a shared programme
95
129
  # accent without turning every dialogue line into a reaction graphic.
96
- draw.line((x-pad//2,y+pad,x-pad,y-pad//2),fill=color('accent'),width=stroke)
97
- draw.line((right+pad//2,y+pad,right+pad,y-pad//2),fill=color('accent'),width=stroke)
130
+ draw.line((x - pad // 2, y + pad, x - pad, y - pad // 2), fill=color("accent"), width=stroke)
131
+ draw.line((right + pad // 2, y + pad, right + pad, y - pad // 2), fill=color("accent"), width=stroke)
98
132
  else:
99
133
  # Narrow editorial labels sit inside the footage, with no full-screen
100
134
  # background. A shared accent edge and typography form programme identity.
101
- draw.rectangle((x+3, y+4, right+3, bottom+4), fill=(0, 0, 0, round(75*opacity)))
135
+ draw.rectangle((x + 3, y + 4, right + 3, bottom + 4), fill=(0, 0, 0, round(75 * opacity)))
102
136
  draw.rectangle((x, y, right, bottom), fill=color("ink"))
103
- draw.rectangle((x, y, x+stroke*2, bottom), fill=color("secondary" if kind == "person" else "accent"))
104
- typography=profile['presets'].get('typography',{})
105
- kicker_font=load_style_font(font_path,max(10,round(timeline.height*typography.get('component_kicker',.017))),profile,role='detail')
106
- kicker=profile.get('eyebrow') or {'location':'現場','person':'人物','fact':'資訊','pointer':'看這裡','circle':'細節'}[kind]
107
- draw.text((x+pad,y+pad//2),kicker,font=kicker_font,fill=color('secondary' if kind=='person' else 'accent'))
108
- primary_y=y+pad//2+round(timeline.height*.027)
109
- draw.text((x+pad,primary_y),primary,font=font,fill=color("paper"))
137
+ draw.rectangle((x, y, x + stroke * 2, bottom), fill=color("secondary" if kind == "person" else "accent"))
138
+ typography = profile["presets"].get("typography", {})
139
+ kicker_font = load_style_font(
140
+ font_path,
141
+ max(10, round(timeline.height * typography.get("component_kicker", 0.017))),
142
+ profile,
143
+ role="detail",
144
+ )
145
+ kicker = (
146
+ profile.get("eyebrow")
147
+ or {"location": "現場", "person": "人物", "fact": "資訊", "pointer": "看這裡", "circle": "細節"}[kind]
148
+ )
149
+ draw.text(
150
+ (x + pad, y + pad // 2), kicker, font=kicker_font, fill=color("secondary" if kind == "person" else "accent")
151
+ )
152
+ primary_y = y + pad // 2 + round(timeline.height * 0.027)
153
+ draw.text((x + pad, primary_y), primary, font=font, fill=color("paper"))
110
154
  if detail:
111
- detail_font=load_style_font(font_path,max(12,round(timeline.height*typography.get('component_detail',.024))),profile,role='detail')
112
- draw.text((x+pad,primary_y+round(timeline.height*.052)),detail,font=detail_font,fill=color('paper'))
113
- draw.line((x+pad,bottom-pad//2,right-pad,bottom-pad//2),fill=color("accent"),width=max(1,stroke//2))
155
+ detail_font = load_style_font(
156
+ font_path,
157
+ max(12, round(timeline.height * typography.get("component_detail", 0.024))),
158
+ profile,
159
+ role="detail",
160
+ )
161
+ draw.text(
162
+ (x + pad, primary_y + round(timeline.height * 0.052)), detail, font=detail_font, fill=color("paper")
163
+ )
164
+ draw.line(
165
+ (x + pad, bottom - pad // 2, right - pad, bottom - pad // 2),
166
+ fill=color("accent"),
167
+ width=max(1, stroke // 2),
168
+ )
114
169
  if kind not in {"pointer", "circle"}:
115
170
  return bounds
116
171
  target = profile["target"]
117
- tx, ty = target["x"]*timeline.width, target["y"]*timeline.height
118
- radius = target["radius"]*min(timeline.width, timeline.height)
172
+ tx, ty = target["x"] * timeline.width, target["y"] * timeline.height
173
+ radius = target["radius"] * min(timeline.width, timeline.height)
119
174
  if kind == "circle":
120
- rect = (tx-radius, ty-radius, tx+radius, ty+radius)
121
- draw.arc(rect, -90, -90+max(2, round(360*eased)), fill=color("accent"), width=stroke*2)
175
+ rect = (tx - radius, ty - radius, tx + radius, ty + radius)
176
+ draw.arc(rect, -90, -90 + max(2, round(360 * eased)), fill=color("accent"), width=stroke * 2)
122
177
  else:
123
- origin = (right, (y+bottom)/2)
124
- angle = math.atan2(ty-origin[1], tx-origin[0])
125
- tip = (origin[0]+(tx-origin[0])*eased, origin[1]+(ty-origin[1])*eased)
126
- draw.line((origin, tip), fill=color("ink"), width=stroke*3)
178
+ origin = (right, (y + bottom) / 2)
179
+ angle = math.atan2(ty - origin[1], tx - origin[0])
180
+ tip = (origin[0] + (tx - origin[0]) * eased, origin[1] + (ty - origin[1]) * eased)
181
+ draw.line((origin, tip), fill=color("ink"), width=stroke * 3)
127
182
  draw.line((origin, tip), fill=color("accent"), width=stroke)
128
- size = max(9, timeline.height*.025)
129
- points = [tip, (tip[0]-size*math.cos(angle-.45), tip[1]-size*math.sin(angle-.45)),
130
- (tip[0]-size*math.cos(angle+.45), tip[1]-size*math.sin(angle+.45))]
183
+ size = max(9, timeline.height * 0.025)
184
+ points = [
185
+ tip,
186
+ (tip[0] - size * math.cos(angle - 0.45), tip[1] - size * math.sin(angle - 0.45)),
187
+ (tip[0] - size * math.cos(angle + 0.45), tip[1] - size * math.sin(angle + 0.45)),
188
+ ]
131
189
  draw.polygon(points, fill=color("accent"))
132
190
  return bounds
133
191
 
134
192
 
135
193
  class _Canvas:
136
194
  """A timeline seen at another size, so every style's own proportions scale with it."""
195
+
137
196
  def __init__(self, timeline, width, height):
138
197
  self._timeline, self.width, self.height = timeline, width, height
139
198
 
@@ -147,25 +206,27 @@ def _scaled(timeline, profile):
147
206
  scale = profile.get("scale", 1)
148
207
  if scale == 1:
149
208
  return None
150
- canvas = _Canvas(timeline, max(2, round(timeline.width*scale)), max(2, round(timeline.height*scale)))
151
- return canvas, (round(timeline.width*profile["x"]) - round(canvas.width*profile["x"]),
152
- round(timeline.height*profile["y"]) - round(canvas.height*profile["y"]))
209
+ canvas = _Canvas(timeline, max(2, round(timeline.width * scale)), max(2, round(timeline.height * scale)))
210
+ return canvas, (
211
+ round(timeline.width * profile["x"]) - round(canvas.width * profile["x"]),
212
+ round(timeline.height * profile["y"]) - round(canvas.height * profile["y"]),
213
+ )
153
214
 
154
215
 
155
216
  def component_bounds(draw, font_path, timeline, item, profile):
156
217
  """The graphic's box on the picture, after any size a person chose."""
157
218
  if custom_components.is_custom(profile):
158
219
  box = custom_components.bounds(timeline, item, profile)
159
- dx, dy = round(profile.get("x", 0)*timeline.width), round(profile.get("y", 0)*timeline.height)
220
+ dx, dy = round(profile.get("x", 0) * timeline.width), round(profile.get("y", 0) * timeline.height)
160
221
  return (box or (dx, dy, dx, dy)), None, 0
161
222
  scaled = _scaled(timeline, profile)
162
223
  if scaled is None:
163
224
  return _bounds(draw, font_path, timeline, item, profile)
164
225
  canvas, (dx, dy) = scaled
165
226
  (left, top, right, bottom), font, pad = _bounds(draw, font_path, canvas, item, profile)
166
- box = (left+dx, top+dy, right+dx, bottom+dy)
227
+ box = (left + dx, top + dy, right + dx, bottom + dy)
167
228
  # Enlarged, it must still clear the picture's edge and the subtitles at the bottom.
168
- if box[0] < 0 or box[1] < 0 or box[2] > timeline.width*.97 or box[3] > timeline.height*.8:
229
+ if box[0] < 0 or box[1] < 0 or box[2] > timeline.width * 0.97 or box[3] > timeline.height * 0.8:
169
230
  raise TitleRenderError("program_component_overflow")
170
231
  return box, font, pad
171
232
 
@@ -183,9 +244,9 @@ def draw_program_component(draw, font_path, timeline, item, profile, relative_fr
183
244
  result = _draw(ImageDraw.Draw(layer), font_path, canvas, item, profile, relative_frame)
184
245
  target = draw._image
185
246
  sx, sy, tx, ty = max(0, -dx), max(0, -dy), max(0, dx), max(0, dy)
186
- width, height = min(layer.width-sx, target.width-tx), min(layer.height-sy, target.height-ty)
247
+ width, height = min(layer.width - sx, target.width - tx), min(layer.height - sy, target.height - ty)
187
248
  if width > 0 and height > 0:
188
- piece = layer.crop((sx, sy, sx+width, sy+height))
249
+ piece = layer.crop((sx, sy, sx + width, sy + height))
189
250
  if target.mode == "RGBA":
190
251
  target.alpha_composite(piece, (tx, ty))
191
252
  else: