@clipen/clipen-cli 1.0.0 → 1.0.1

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 (127) hide show
  1. package/README.md +60 -50
  2. package/package.json +7 -4
  3. package/pyproject.toml +18 -2
  4. package/requirements/dev.txt +2 -0
  5. package/src/clipen/__init__.py +1 -1
  6. package/src/clipen/analysis/__init__.py +7 -7
  7. package/src/clipen/analysis/artifacts.py +4 -10
  8. package/src/clipen/analysis/audio.py +10 -8
  9. package/src/clipen/analysis/evidence_service.py +345 -167
  10. package/src/clipen/analysis/image_similarity.py +5 -14
  11. package/src/clipen/analysis/keyframes.py +5 -17
  12. package/src/clipen/analysis/models.py +5 -7
  13. package/src/clipen/analysis/qwen_worker.py +19 -54
  14. package/src/clipen/analysis/resources.py +2 -1
  15. package/src/clipen/analysis/runtime.py +1 -3
  16. package/src/clipen/analysis/service.py +16 -48
  17. package/src/clipen/analysis/setup.py +11 -25
  18. package/src/clipen/analysis/setup_cli.py +5 -15
  19. package/src/clipen/analysis/storage.py +96 -278
  20. package/src/clipen/analysis/transcription.py +40 -82
  21. package/src/clipen/analysis/visual.py +109 -48
  22. package/src/clipen/annotations/__init__.py +5 -2
  23. package/src/clipen/annotations/models.py +1 -1
  24. package/src/clipen/annotations/storage.py +132 -84
  25. package/src/clipen/annotations/suggestions.py +3 -8
  26. package/src/clipen/asr_release.py +4 -11
  27. package/src/clipen/bootstrap.py +65 -54
  28. package/src/clipen/{planning/models.py → candidates.py} +29 -47
  29. package/src/clipen/cli.py +2 -2
  30. package/src/clipen/controller/app.py +401 -214
  31. package/src/clipen/controller/server.py +28 -38
  32. package/src/clipen/domain/__init__.py +1 -1
  33. package/src/clipen/domain/media_time.py +3 -10
  34. package/src/clipen/domain/timeline.py +45 -47
  35. package/src/clipen/domain/validation.py +0 -1
  36. package/src/clipen/editing/__init__.py +1 -1
  37. package/src/clipen/editing/agent_models.py +4 -11
  38. package/src/clipen/editing/agent_repository.py +391 -170
  39. package/src/clipen/editing/agent_tools.py +180 -99
  40. package/src/clipen/editing/alignment.py +92 -52
  41. package/src/clipen/editing/alignment_setup.py +118 -70
  42. package/src/clipen/editing/alignment_worker.py +11 -9
  43. package/src/clipen/editing/change_report.py +95 -38
  44. package/src/clipen/editing/compiler.py +0 -1
  45. package/src/clipen/editing/component_looks.py +58 -34
  46. package/src/clipen/editing/component_review.py +34 -38
  47. package/src/clipen/editing/coordinator.py +213 -90
  48. package/src/clipen/editing/editorial_review.py +217 -95
  49. package/src/clipen/editing/evidence_jobs.py +457 -200
  50. package/src/clipen/editing/history_changes.py +129 -68
  51. package/src/clipen/editing/music_choices.py +8 -5
  52. package/src/clipen/editing/production_catalog.py +573 -136
  53. package/src/clipen/editing/production_limits.py +43 -17
  54. package/src/clipen/editing/production_media.py +376 -167
  55. package/src/clipen/editing/production_preview.py +322 -129
  56. package/src/clipen/editing/production_progress.py +164 -69
  57. package/src/clipen/editing/production_requirements.py +106 -39
  58. package/src/clipen/editing/production_tools.py +1064 -462
  59. package/src/clipen/editing/program_audio.py +211 -81
  60. package/src/clipen/editing/program_direction.py +59 -25
  61. package/src/clipen/editing/program_story.py +83 -45
  62. package/src/clipen/editing/program_subtitles.py +194 -96
  63. package/src/clipen/editing/programme_review.py +98 -50
  64. package/src/clipen/editing/prompt_history.py +64 -27
  65. package/src/clipen/editing/recut.py +65 -25
  66. package/src/clipen/editing/refinement_references.py +176 -86
  67. package/src/clipen/editing/resolve_export.py +449 -218
  68. package/src/clipen/editing/resolve_titles.py +162 -105
  69. package/src/clipen/editing/skill_tools.py +530 -154
  70. package/src/clipen/editing/source_dialogue.py +177 -67
  71. package/src/clipen/editing/speech_coverage.py +42 -22
  72. package/src/clipen/editing/speech_quality.py +6 -1
  73. package/src/clipen/editing/tool_receipts.py +78 -32
  74. package/src/clipen/editing/versions.py +122 -64
  75. package/src/clipen/editing/visual_preview.py +157 -61
  76. package/src/clipen/editing/workbench.py +104 -42
  77. package/src/clipen/finishing/audio.py +69 -30
  78. package/src/clipen/finishing/catalog.py +176 -93
  79. package/src/clipen/finishing/models.py +1 -1
  80. package/src/clipen/finishing/renderer.py +33 -14
  81. package/src/clipen/mcp_editing/__main__.py +3 -1
  82. package/src/clipen/mcp_editing/server.py +77 -34
  83. package/src/clipen/media/__init__.py +3 -3
  84. package/src/clipen/media/discovery.py +7 -20
  85. package/src/clipen/media/models.py +7 -18
  86. package/src/clipen/media/preview.py +14 -24
  87. package/src/clipen/media/probe.py +16 -44
  88. package/src/clipen/media/service.py +6 -19
  89. package/src/clipen/media/storage.py +33 -81
  90. package/src/clipen/music_vocabulary.py +33 -4
  91. package/src/clipen/power.py +8 -3
  92. package/src/clipen/projects/__init__.py +1 -1
  93. package/src/clipen/projects/deletion.py +19 -32
  94. package/src/clipen/projects/finishing_schema.py +3 -1
  95. package/src/clipen/projects/models.py +2 -5
  96. package/src/clipen/projects/picker.py +13 -37
  97. package/src/clipen/projects/service.py +8 -24
  98. package/src/clipen/projects/storage.py +226 -246
  99. package/src/clipen/provider_registry.py +4 -2
  100. package/src/clipen/providers/account.py +86 -35
  101. package/src/clipen/providers/claude.py +59 -25
  102. package/src/clipen/providers/claude_editing.py +14 -7
  103. package/src/clipen/providers/codex.py +73 -118
  104. package/src/clipen/providers/codex_editing.py +2 -2
  105. package/src/clipen/providers/editing_agent.py +19 -17
  106. package/src/clipen/providers/recovery.py +7 -8
  107. package/src/clipen/rendering/cover.py +18 -5
  108. package/src/clipen/rendering/custom_components.py +167 -79
  109. package/src/clipen/rendering/custom_render.py +62 -41
  110. package/src/clipen/rendering/production_effects.py +77 -45
  111. package/src/clipen/rendering/program_components.py +134 -73
  112. package/src/clipen/rendering/program_creator.py +432 -277
  113. package/src/clipen/rendering/program_identities.py +277 -182
  114. package/src/clipen/rendering/program_motion.py +140 -95
  115. package/src/clipen/rendering/program_studio.py +175 -116
  116. package/src/clipen/rendering/program_styles.py +231 -145
  117. package/src/clipen/rendering/program_subtitles.py +71 -34
  118. package/src/clipen/rendering/renderer.py +150 -121
  119. package/src/clipen/rendering/storage.py +9 -22
  120. package/src/clipen/rendering/titles.py +193 -86
  121. package/src/clipen/skills/__init__.py +1 -0
  122. package/src/clipen/skills/catalog.py +151 -55
  123. package/src/clipen/skills/library.py +13 -7
  124. package/src/clipen/skills/package.py +46 -23
  125. package/src/clipen/skills/visual_styles.py +29 -18
  126. package/src/clipen/workspace.py +15 -44
  127. package/src/clipen/planning/__init__.py +0 -9
@@ -1,235 +1,321 @@
1
1
  """Distinct, trusted art directions for the same semantic programme components."""
2
- import os
2
+
3
3
  import hashlib
4
+ import os
5
+ from functools import lru_cache
4
6
  from importlib.resources import files
5
7
  from pathlib import Path
6
- from functools import lru_cache
8
+
7
9
  from PIL import ImageFont
8
10
 
9
11
 
10
12
  def skin(profile):
11
- return profile.get('presets',{}).get('appearance',{}).get('skin','variety')
13
+ return profile.get("presets", {}).get("appearance", {}).get("skin", "variety")
12
14
 
13
15
 
14
16
  def style_font(font_path, profile):
15
- if os.environ.get('CLIPEN_TITLE_FONT') or profile['presets'].get('appearance',{}).get('font_family')!='serif':
17
+ if os.environ.get("CLIPEN_TITLE_FONT") or profile["presets"].get("appearance", {}).get("font_family") != "serif":
16
18
  return font_path
17
- for path in ('/System/Library/Fonts/Supplemental/Songti.ttc',
18
- '/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc',
19
- 'C:/Windows/Fonts/simsun.ttc'):
20
- if Path(path).is_file():return Path(path)
19
+ for path in (
20
+ "/System/Library/Fonts/Supplemental/Songti.ttc",
21
+ "/usr/share/fonts/opentype/noto/NotoSerifCJK-Regular.ttc",
22
+ "C:/Windows/Fonts/simsun.ttc",
23
+ ):
24
+ if Path(path).is_file():
25
+ return Path(path)
21
26
  return font_path
22
27
 
23
28
 
24
-
25
29
  @lru_cache(maxsize=32)
26
30
  def _font_face(path, direction):
27
- preferred='Light' if direction=='cinema' else 'Regular'
28
- fallback=None
31
+ preferred = "Light" if direction == "cinema" else "Regular"
32
+ fallback = None
29
33
  for index in range(16):
30
- try:family,weight=ImageFont.truetype(path,12,index=index).getname()
31
- except OSError:break
32
- if family in {'Songti TC','Noto Serif CJK TC','NotoSerifCJKtc'}:
33
- if weight==preferred:return index
34
- if fallback is None:fallback=index
34
+ try:
35
+ family, weight = ImageFont.truetype(path, 12, index=index).getname()
36
+ except OSError:
37
+ break
38
+ if family in {"Songti TC", "Noto Serif CJK TC", "NotoSerifCJKtc"}:
39
+ if weight == preferred:
40
+ return index
41
+ if fallback is None:
42
+ fallback = index
35
43
  return fallback or 0
36
44
 
37
45
 
38
46
  def font_role(profile):
39
- kind=profile.get('component_id')
40
- return 'impact' if kind in {'impact','burst','reaction'} else 'title' if kind in {'program_title','headline','chapter'} else 'information'
47
+ kind = profile.get("component_id")
48
+ return (
49
+ "impact"
50
+ if kind in {"impact", "burst", "reaction"}
51
+ else "title"
52
+ if kind in {"program_title", "headline", "chapter"}
53
+ else "information"
54
+ )
41
55
 
42
56
 
43
57
  @lru_cache(maxsize=64)
44
58
  def _role_face(path, weight):
45
- preferred={'bold':('Bold','W6','Semibold','Heavy','Black'), 'medium':('Medium','W6','Regular'),
46
- 'light':('Light','W3','Regular'), 'regular':('Regular','W3','Medium')}[weight]
47
- faces=[]
59
+ preferred = {
60
+ "bold": ("Bold", "W6", "Semibold", "Heavy", "Black"),
61
+ "medium": ("Medium", "W6", "Regular"),
62
+ "light": ("Light", "W3", "Regular"),
63
+ "regular": ("Regular", "W3", "Medium"),
64
+ }[weight]
65
+ faces = []
48
66
  for index in range(32):
49
- try:family,face=ImageFont.truetype(path,12,index=index).getname()
50
- except OSError:break
67
+ try:
68
+ family, face = ImageFont.truetype(path, 12, index=index).getname()
69
+ except OSError:
70
+ break
51
71
  # Prefer Traditional Chinese faces when a collection contains both.
52
- if ' SC' not in family and 'Interface' not in family and family!='STSong':
53
- faces.append((index,face,family.endswith(' TC')))
72
+ if " SC" not in family and "Interface" not in family and family != "STSong":
73
+ faces.append((index, face, family.endswith(" TC")))
54
74
  # Taiwan forms first when a collection also ships HK or other regional faces.
55
- faces=[(index,face) for index,face,_ in sorted(faces,key=lambda entry:not entry[2])]
75
+ faces = [(index, face) for index, face, _ in sorted(faces, key=lambda entry: not entry[2])]
56
76
  for desired in preferred:
57
- for index,face in faces:
58
- if face==desired:return index
77
+ for index, face in faces:
78
+ if face == desired:
79
+ return index
59
80
  return faces[0][0] if faces else 0
60
81
 
61
82
 
62
83
  @lru_cache(maxsize=16)
63
84
  def _verify_font(path, expected, modified_ns, length):
64
85
  from .titles import TitleRenderError
65
- if hashlib.sha256(Path(path).read_bytes()).hexdigest()!=expected:
66
- raise TitleRenderError('program_font_unavailable')
86
+
87
+ if hashlib.sha256(Path(path).read_bytes()).hexdigest() != expected:
88
+ raise TitleRenderError("program_font_unavailable")
67
89
  return path
68
90
 
69
91
 
70
92
  def bundled_font(specification):
71
93
  from .titles import TitleRenderError
72
- identifier=specification['bundled_font']
73
- if identifier not in {'chenyu','iansui'}:
74
- raise TitleRenderError('program_font_unavailable')
75
- path=Path(str(files('clipen.rendering').joinpath('fonts',identifier+'.ttf')))
94
+
95
+ identifier = specification["bundled_font"]
96
+ if identifier not in {"chenyu", "iansui"}:
97
+ raise TitleRenderError("program_font_unavailable")
98
+ path = Path(str(files("clipen.rendering").joinpath("fonts", identifier + ".ttf")))
76
99
  try:
77
- stat=path.stat()
78
- return _verify_font(str(path),specification['sha256'],stat.st_mtime_ns,stat.st_size)
79
- except (OSError,KeyError) as error:
80
- raise TitleRenderError('program_font_unavailable') from error
100
+ stat = path.stat()
101
+ return _verify_font(str(path), specification["sha256"], stat.st_mtime_ns, stat.st_size)
102
+ except (OSError, KeyError) as error:
103
+ raise TitleRenderError("program_font_unavailable") from error
81
104
 
82
105
 
83
106
  @lru_cache(maxsize=8)
84
107
  def _system_asset(name):
85
108
  """macOS installs some fonts on demand under a hashed asset folder."""
86
109
  from glob import glob
87
- return tuple(sorted(glob('/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*.asset/AssetData/'+name)))[:1]
110
+
111
+ return tuple(sorted(glob("/System/Library/AssetsV2/com_apple_MobileAsset_Font*/*.asset/AssetData/" + name)))[:1]
88
112
 
89
113
 
90
114
  def type_outline(profile, font, fallback):
91
- specification=profile['presets'].get('font_roles',{}).get(font_role(profile),{})
92
- ratio=specification.get('outline_em')
93
- return fallback if ratio is None else max(1,round(font.size*ratio))
115
+ specification = profile["presets"].get("font_roles", {}).get(font_role(profile), {})
116
+ ratio = specification.get("outline_em")
117
+ return fallback if ratio is None else max(1, round(font.size * ratio))
94
118
 
95
119
 
96
120
  def load_style_font(font_path, size, profile, role=None):
97
- specification=profile['presets'].get('font_roles',{}).get(role or font_role(profile))
121
+ specification = profile["presets"].get("font_roles", {}).get(role or font_role(profile))
98
122
  if specification:
99
- if specification.get('bundled_font') and not os.environ.get('CLIPEN_TITLE_FONT'):
100
- return ImageFont.truetype(bundled_font(specification),size)
101
- family=specification['family']
102
- if family=='handwriting':family='sans'
103
- candidates={
104
- 'gothic':('/System/Library/Fonts/Hiragino Sans GB.ttc','/System/Library/Fonts/STHeiti Medium.ttc'),
105
- 'sans':('/System/Library/Fonts/STHeiti Medium.ttc','/System/Library/Fonts/Hiragino Sans GB.ttc'),
106
- 'serif':('/System/Library/Fonts/Supplemental/Songti.ttc',),
123
+ if specification.get("bundled_font") and not os.environ.get("CLIPEN_TITLE_FONT"):
124
+ return ImageFont.truetype(bundled_font(specification), size)
125
+ family = specification["family"]
126
+ if family == "handwriting":
127
+ family = "sans"
128
+ candidates = {
129
+ "gothic": ("/System/Library/Fonts/Hiragino Sans GB.ttc", "/System/Library/Fonts/STHeiti Medium.ttc"),
130
+ "sans": ("/System/Library/Fonts/STHeiti Medium.ttc", "/System/Library/Fonts/Hiragino Sans GB.ttc"),
131
+ "serif": ("/System/Library/Fonts/Supplemental/Songti.ttc",),
107
132
  # PingFang is the clean system sans creators expect on macOS; it is
108
133
  # an on-demand system asset, so fall back to Hiragino Sans GB.
109
- 'modern':_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc','/System/Library/Fonts/STHeiti Medium.ttc'),
134
+ "modern": _system_asset("PingFang.ttc")
135
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc", "/System/Library/Fonts/STHeiti Medium.ttc"),
110
136
  # Display faces popular in Taiwanese variety and vlog packaging.
111
- 'lantinghei':_system_asset('Lantinghei.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
112
- 'wawa':_system_asset('WawaTC-Regular.otf')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
113
- 'hannotate':_system_asset('Hannotate.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
114
- 'hanzipen':_system_asset('Hanzipen.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
115
- 'yuanti':_system_asset('Yuanti.ttc')+_system_asset('PingFang.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
116
- 'kaiti':_system_asset('Kaiti.ttc')+('/System/Library/Fonts/Supplemental/Songti.ttc',),
117
- 'lingwai':_system_asset('LingWaiTC-Medium.otf')+('/System/Library/Fonts/Supplemental/Songti.ttc',),
118
- 'weibei':_system_asset('WeibeiTC-Bold.otf')+_system_asset('Lantinghei.ttc')+('/System/Library/Fonts/Hiragino Sans GB.ttc',),
137
+ "lantinghei": _system_asset("Lantinghei.ttc")
138
+ + _system_asset("PingFang.ttc")
139
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
140
+ "wawa": _system_asset("WawaTC-Regular.otf")
141
+ + _system_asset("PingFang.ttc")
142
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
143
+ "hannotate": _system_asset("Hannotate.ttc")
144
+ + _system_asset("PingFang.ttc")
145
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
146
+ "hanzipen": _system_asset("Hanzipen.ttc")
147
+ + _system_asset("PingFang.ttc")
148
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
149
+ "yuanti": _system_asset("Yuanti.ttc")
150
+ + _system_asset("PingFang.ttc")
151
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
152
+ "kaiti": _system_asset("Kaiti.ttc") + ("/System/Library/Fonts/Supplemental/Songti.ttc",),
153
+ "lingwai": _system_asset("LingWaiTC-Medium.otf") + ("/System/Library/Fonts/Supplemental/Songti.ttc",),
154
+ "weibei": _system_asset("WeibeiTC-Bold.otf")
155
+ + _system_asset("Lantinghei.ttc")
156
+ + ("/System/Library/Fonts/Hiragino Sans GB.ttc",),
119
157
  }[family]
120
- candidates+=('/usr/share/fonts/opentype/noto/Noto'+('Serif' if family=='serif' else 'Sans')+'CJK-Regular.ttc',
121
- 'C:/Windows/Fonts/'+('simsun.ttc' if family=='serif' else 'msjh.ttc'))
158
+ candidates += (
159
+ "/usr/share/fonts/opentype/noto/Noto" + ("Serif" if family == "serif" else "Sans") + "CJK-Regular.ttc",
160
+ "C:/Windows/Fonts/" + ("simsun.ttc" if family == "serif" else "msjh.ttc"),
161
+ )
122
162
  # The explicit local font override still has priority. No arbitrary font
123
163
  # paths or remote URLs can be supplied through the editing MCP tools.
124
- path=str(font_path) if os.environ.get('CLIPEN_TITLE_FONT') else next((p for p in candidates if Path(p).is_file()),str(font_path))
125
- return ImageFont.truetype(path,size,index=_role_face(path,specification['weight']))
126
- path=str(style_font(font_path,profile))
127
- face=_font_face(path,skin(profile)) if profile['presets'].get('appearance',{}).get('font_family')=='serif' else 0
128
- return ImageFont.truetype(path,size,index=face)
129
-
164
+ path = (
165
+ str(font_path)
166
+ if os.environ.get("CLIPEN_TITLE_FONT")
167
+ else next((p for p in candidates if Path(p).is_file()), str(font_path))
168
+ )
169
+ return ImageFont.truetype(path, size, index=_role_face(path, specification["weight"]))
170
+ path = str(style_font(font_path, profile))
171
+ face = (
172
+ _font_face(path, skin(profile)) if profile["presets"].get("appearance", {}).get("font_family") == "serif" else 0
173
+ )
174
+ return ImageFont.truetype(path, size, index=face)
130
175
 
131
176
 
132
177
  @lru_cache(maxsize=2048)
133
178
  def _has_glyph(path, size, index, character):
134
- if character.isspace():return True
135
- font=ImageFont.truetype(path,size,index=index)
136
- glyph=font.getmask(character)
137
- missing=font.getmask('\U0010ffff')
138
- return glyph.getbbox() is not None and (glyph.size!=missing.size or bytes(glyph)!=bytes(missing))
179
+ if character.isspace():
180
+ return True
181
+ font = ImageFont.truetype(path, size, index=index)
182
+ glyph = font.getmask(character)
183
+ missing = font.getmask("\U0010ffff")
184
+ return glyph.getbbox() is not None and (glyph.size != missing.size or bytes(glyph) != bytes(missing))
139
185
 
140
186
 
141
187
  def _text_runs(value, font):
142
- from .titles import TitleCardRenderer,TitleRenderError
143
- fallback=None;runs=[]
188
+ from .titles import TitleCardRenderer, TitleRenderError
189
+
190
+ fallback = None
191
+ runs = []
144
192
  for char in value:
145
- selected=font
146
- if not _has_glyph(str(font.path),font.size,font.index,char):
193
+ selected = font
194
+ if not _has_glyph(str(font.path), font.size, font.index, char):
147
195
  if fallback is None:
148
- path=TitleCardRenderer._font_path()
149
- if path is None:raise TitleRenderError('program_component_missing_glyph')
150
- fallback=ImageFont.truetype(str(path),font.size)
151
- if not _has_glyph(str(fallback.path),fallback.size,fallback.index,char):
152
- raise TitleRenderError('program_component_missing_glyph')
153
- selected=fallback
154
- if runs and runs[-1][1] is selected:runs[-1]=(runs[-1][0]+char,selected)
155
- else:runs.append((char,selected))
196
+ path = TitleCardRenderer._font_path()
197
+ if path is None:
198
+ raise TitleRenderError("program_component_missing_glyph")
199
+ fallback = ImageFont.truetype(str(path), font.size)
200
+ if not _has_glyph(str(fallback.path), fallback.size, fallback.index, char):
201
+ raise TitleRenderError("program_component_missing_glyph")
202
+ selected = fallback
203
+ if runs and runs[-1][1] is selected:
204
+ runs[-1] = (runs[-1][0] + char, selected)
205
+ else:
206
+ runs.append((char, selected))
156
207
  return runs
157
208
 
158
209
 
159
- def styled_text_length(value,font):
160
- return sum(selected.getlength(part) for part,selected in _text_runs(value,font))
210
+ def styled_text_length(value, font):
211
+ return sum(selected.getlength(part) for part, selected in _text_runs(value, font))
161
212
 
162
213
 
163
- def draw_style_text(draw,position,value,font,fill,stroke_width=0,stroke_fill=None):
164
- if not value:return
214
+ def draw_style_text(draw, position, value, font, fill, stroke_width=0, stroke_fill=None):
215
+ if not value:
216
+ return
165
217
  # Share a real baseline across font runs so a fallback middle dot stays in
166
218
  # the middle of CJK type rather than jumping to the top of the line.
167
- baseline=position[1]-font.getbbox(value,anchor='ls')[1]
168
- x=position[0]
169
- for part,selected in _text_runs(value,font):
170
- draw.text((x,baseline),part,font=selected,fill=fill,anchor='ls',
171
- stroke_width=stroke_width,stroke_fill=stroke_fill)
172
- x+=selected.getlength(part)
219
+ baseline = position[1] - font.getbbox(value, anchor="ls")[1]
220
+ x = position[0]
221
+ for part, selected in _text_runs(value, font):
222
+ draw.text(
223
+ (x, baseline),
224
+ part,
225
+ font=selected,
226
+ fill=fill,
227
+ anchor="ls",
228
+ stroke_width=stroke_width,
229
+ stroke_fill=stroke_fill,
230
+ )
231
+ x += selected.getlength(part)
173
232
 
174
233
 
175
234
  def draw_styled_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame=None):
176
- if skin(profile) == 'studio':
235
+ if skin(profile) == "studio":
177
236
  from .program_studio import draw_graphic
178
- return draw_graphic(draw,font_path,timeline,item,profile,bounds,font,pad,relative_frame)
179
- kind=profile['component_id'];hero=kind in {'program_title','headline','impact','chapter','burst'}
180
- appearance=profile['presets'].get('appearance',{})
181
- motion=profile['presets']['motion']
182
- entry=appearance.get('hero_entry_frames',18) if hero else motion['entry_frames']
183
- exit_frames=appearance.get('hero_exit_frames',8) if hero else motion['exit_frames']
184
- relative=entry if relative_frame is None else relative_frame
185
- progress=min(1.,max(0.,(relative+1)/entry));ease=1-(1-progress)**3
186
- opacity=min(progress,min(1.,max(0.,(item.duration_frames-relative)/exit_frames)))
187
- x,y,right,bottom=bounds;w=right-x;h=bottom-y
237
+
238
+ return draw_graphic(draw, font_path, timeline, item, profile, bounds, font, pad, relative_frame)
239
+ kind = profile["component_id"]
240
+ hero = kind in {"program_title", "headline", "impact", "chapter", "burst"}
241
+ appearance = profile["presets"].get("appearance", {})
242
+ motion = profile["presets"]["motion"]
243
+ entry = appearance.get("hero_entry_frames", 18) if hero else motion["entry_frames"]
244
+ exit_frames = appearance.get("hero_exit_frames", 8) if hero else motion["exit_frames"]
245
+ relative = entry if relative_frame is None else relative_frame
246
+ progress = min(1.0, max(0.0, (relative + 1) / entry))
247
+ ease = 1 - (1 - progress) ** 3
248
+ opacity = min(progress, min(1.0, max(0.0, (item.duration_frames - relative) / exit_frames)))
249
+ x, y, right, bottom = bounds
250
+ w = right - x
251
+ h = bottom - y
188
252
  # The full entrance remains within the validated static footprint.
189
- y+=round((1-ease)*pad*.35)
190
- primary,_,detail=item.text.partition('\n')
191
- font_path=style_font(font_path,profile)
192
- small=load_style_font(font_path,max(12,round(timeline.height*.024)),profile,role='detail')
193
- line=max(1,round(timeline.height*.002))
194
- palette=profile['presets']['palette']
195
- def color(name,alpha=1.):
196
- r,g,b,a=palette[name]
197
- return r,g,b,round(a*opacity*alpha)
198
- def text(position,value,selected=font,fill='ink',shadow=False):
253
+ y += round((1 - ease) * pad * 0.35)
254
+ primary, _, detail = item.text.partition("\n")
255
+ font_path = style_font(font_path, profile)
256
+ small = load_style_font(font_path, max(12, round(timeline.height * 0.024)), profile, role="detail")
257
+ line = max(1, round(timeline.height * 0.002))
258
+ palette = profile["presets"]["palette"]
259
+
260
+ def color(name, alpha=1.0):
261
+ r, g, b, a = palette[name]
262
+ return r, g, b, round(a * opacity * alpha)
263
+
264
+ def text(position, value, selected=font, fill="ink", shadow=False):
199
265
  if shadow:
200
- draw_style_text(draw,(position[0]+line,position[1]+line),value,selected,color('ink'),line,color('ink'))
201
- draw_style_text(draw,position,value,selected,color(fill))
202
- if skin(profile)=='editorial':
266
+ draw_style_text(
267
+ draw, (position[0] + line, position[1] + line), value, selected, color("ink"), line, color("ink")
268
+ )
269
+ draw_style_text(draw, position, value, selected, color(fill))
270
+
271
+ if skin(profile) == "editorial":
203
272
  # Paper, ink and seal geometry: no slanted yellow panels or comic strokes.
204
- draw.rounded_rectangle((x,y,right,bottom),radius=max(2,pad//3),fill=color('paper'),outline=color('ink'),width=line)
205
- if kind=='burst':
206
- cx,cy=(x+right)/2,y+h*.43;radius=min(w*.45,h*.40)
207
- draw.ellipse((cx-radius,cy-radius,cx+radius,cy+radius),outline=color('accent'),width=line*2)
208
- draw.ellipse((cx-radius+line*4,cy-radius+line*4,cx+radius-line*4,cy+radius-line*4),outline=color('accent'),width=line)
209
- elif kind=='program_title':
210
- draw.rectangle((x+pad,y+pad*.65,x+pad*2,y+pad*1.5),fill=color('accent'))
211
- draw.line((x+pad*2.5,y+pad*1.1,x+w*ease-pad,y+pad*1.1),fill=color('ink'),width=line)
212
- elif kind in {'headline','impact'}:
213
- draw.line((x+pad,bottom-pad*.6,x+(w-pad)*ease,bottom-pad*.6),fill=color('accent'),width=line*3)
273
+ draw.rounded_rectangle(
274
+ (x, y, right, bottom), radius=max(2, pad // 3), fill=color("paper"), outline=color("ink"), width=line
275
+ )
276
+ if kind == "burst":
277
+ cx, cy = (x + right) / 2, y + h * 0.43
278
+ radius = min(w * 0.45, h * 0.40)
279
+ draw.ellipse((cx - radius, cy - radius, cx + radius, cy + radius), outline=color("accent"), width=line * 2)
280
+ draw.ellipse(
281
+ (cx - radius + line * 4, cy - radius + line * 4, cx + radius - line * 4, cy + radius - line * 4),
282
+ outline=color("accent"),
283
+ width=line,
284
+ )
285
+ elif kind == "program_title":
286
+ draw.rectangle((x + pad, y + pad * 0.65, x + pad * 2, y + pad * 1.5), fill=color("accent"))
287
+ draw.line((x + pad * 2.5, y + pad * 1.1, x + w * ease - pad, y + pad * 1.1), fill=color("ink"), width=line)
288
+ elif kind in {"headline", "impact"}:
289
+ draw.line(
290
+ (x + pad, bottom - pad * 0.6, x + (w - pad) * ease, bottom - pad * 0.6),
291
+ fill=color("accent"),
292
+ width=line * 3,
293
+ )
214
294
  else:
215
- draw.rectangle((x,y,x+line*3,bottom),fill=color('accent'))
216
- ty=y+h*(.31 if kind=='program_title' else .23 if hero else .22)
217
- text((x+pad*1.5,ty),primary,fill='accent' if kind in {'impact','burst'} else 'ink')
218
- if detail:text((x+pad*1.5,bottom-pad*1.9),detail,small)
295
+ draw.rectangle((x, y, x + line * 3, bottom), fill=color("accent"))
296
+ ty = y + h * (0.31 if kind == "program_title" else 0.23 if hero else 0.22)
297
+ text((x + pad * 1.5, ty), primary, fill="accent" if kind in {"impact", "burst"} else "ink")
298
+ if detail:
299
+ text((x + pad * 1.5, bottom - pad * 1.9), detail, small)
219
300
  else:
220
301
  # Quiet lower-third grammar, hairline brackets and serif type. The small
221
302
  # translucent backing preserves contrast on bright source footage.
222
- draw.rectangle((x,y,right,bottom),fill=color('ink',.30))
223
- length=min(pad*2,w*.16)*ease
224
- if kind=='chapter':
225
- draw.line((x,y+pad*.5,x+pad*.8,bottom-pad*.5),fill=color('accent'),width=line*2)
226
- elif kind in {'program_title','burst'}:
227
- for cx,cy,sx,sy in ((x,y,1,1),(right,bottom,-1,-1)):
228
- draw.line((cx,cy,cx+sx*length,cy),fill=color('accent'),width=line)
229
- draw.line((cx,cy,cx,cy+sy*length),fill=color('accent'),width=line)
303
+ draw.rectangle((x, y, right, bottom), fill=color("ink", 0.30))
304
+ length = min(pad * 2, w * 0.16) * ease
305
+ if kind == "chapter":
306
+ draw.line((x, y + pad * 0.5, x + pad * 0.8, bottom - pad * 0.5), fill=color("accent"), width=line * 2)
307
+ elif kind in {"program_title", "burst"}:
308
+ for cx, cy, sx, sy in ((x, y, 1, 1), (right, bottom, -1, -1)):
309
+ draw.line((cx, cy, cx + sx * length, cy), fill=color("accent"), width=line)
310
+ draw.line((cx, cy, cx, cy + sy * length), fill=color("accent"), width=line)
230
311
  else:
231
- draw.line((x+pad,bottom-pad*.6,x+(w-pad)*ease,bottom-pad*.6),fill=color('accent'),width=line)
232
- ty=y+h*(.30 if kind=='program_title' else .23 if hero else .22)
233
- text((x+pad*1.5,ty),primary,fill='paper',shadow=True)
234
- if detail:text((x+pad*1.5,bottom-pad*1.9),detail,small,fill='paper',shadow=True)
312
+ draw.line(
313
+ (x + pad, bottom - pad * 0.6, x + (w - pad) * ease, bottom - pad * 0.6),
314
+ fill=color("accent"),
315
+ width=line,
316
+ )
317
+ ty = y + h * (0.30 if kind == "program_title" else 0.23 if hero else 0.22)
318
+ text((x + pad * 1.5, ty), primary, fill="paper", shadow=True)
319
+ if detail:
320
+ text((x + pad * 1.5, bottom - pad * 1.9), detail, small, fill="paper", shadow=True)
235
321
  return bounds
@@ -3,50 +3,87 @@
3
3
  Rendered as native RGBA events, so the pipeline does not depend on libass being
4
4
  installed in the user's FFmpeg build. No text box, chapter card or logo is drawn.
5
5
  """
6
+
6
7
  from PIL import ImageFont
7
8
 
8
9
 
9
10
  def animation_boundaries(item):
10
- return {item.start_frame+n for n in (0,2,4,7,item.duration_frames-2,item.duration_frames) if 0<=n<=item.duration_frames}
11
+ return {
12
+ item.start_frame + n
13
+ for n in (0, 2, 4, 7, item.duration_frames - 2, item.duration_frames)
14
+ if 0 <= n <= item.duration_frames
15
+ }
11
16
 
12
17
 
13
- def draw_program_subtitle(draw,font_path,timeline,item,profile,relative_frame=None):
14
- relative=7 if relative_frame is None or profile.get('motion')=='none' else relative_frame
15
- scale=.88 if relative<2 else 1.06 if relative<4 else .98 if relative<7 else 1.
16
- size=max(16,round(timeline.height*profile.get('font_size_ratio',.052)*scale))
17
- index=0
18
+ def draw_program_subtitle(draw, font_path, timeline, item, profile, relative_frame=None):
19
+ relative = 7 if relative_frame is None or profile.get("motion") == "none" else relative_frame
20
+ scale = 0.88 if relative < 2 else 1.06 if relative < 4 else 0.98 if relative < 7 else 1.0
21
+ size = max(16, round(timeline.height * profile.get("font_size_ratio", 0.052) * scale))
22
+ index = 0
18
23
  # Hiragino's W6 face is heavier than W3. Other families use their configured
19
24
  # face and a small foreground stroke rather than assuming a TTC index.
20
25
  try:
21
- candidate=ImageFont.truetype(str(font_path),size,index=2)
22
- if 'W6' in candidate.getname()[1]:index=2
23
- except OSError:pass
24
- font=ImageFont.truetype(str(font_path),size,index=index)
25
- layout_font=ImageFont.truetype(str(font_path),max(16,round(timeline.height*profile.get('font_size_ratio',.052)*1.06)),index=index)
26
- text=item.text.replace('\n',' ');maximum=timeline.width*.86
27
- lines=[];line=''
26
+ candidate = ImageFont.truetype(str(font_path), size, index=2)
27
+ if "W6" in candidate.getname()[1]:
28
+ index = 2
29
+ except OSError:
30
+ pass
31
+ font = ImageFont.truetype(str(font_path), size, index=index)
32
+ layout_font = ImageFont.truetype(
33
+ str(font_path), max(16, round(timeline.height * profile.get("font_size_ratio", 0.052) * 1.06)), index=index
34
+ )
35
+ text = item.text.replace("\n", " ")
36
+ maximum = timeline.width * 0.86
37
+ lines = []
38
+ line = ""
28
39
  for character in text:
29
- if line and draw.textlength(line+character,font=layout_font)>maximum:
30
- lines.append(line);line=''
31
- line+=character
32
- if line:lines.append(line)
33
- if len(lines)>2:
40
+ if line and draw.textlength(line + character, font=layout_font) > maximum:
41
+ lines.append(line)
42
+ line = ""
43
+ line += character
44
+ if line:
45
+ lines.append(line)
46
+ if len(lines) > 2:
34
47
  from .titles import TitleRenderError
35
- raise TitleRenderError('program_subtitle_overflow')
36
- highlighted=set()
37
- for word in profile.get('emphasis',[]):
38
- start=0
39
- while (start:=text.find(word,start))>=0:
40
- highlighted.update(range(start,start+len(word)));start+=len(word)
41
- opacity=255 if item.duration_frames-relative>2 else 180
42
- stroke=max(2,round(size*.095));line_height=round(size*1.35)
43
- baseline=round(timeline.height*.90)-(len(lines)-1)*line_height
44
- offset=0
48
+
49
+ raise TitleRenderError("program_subtitle_overflow")
50
+ highlighted = set()
51
+ for word in profile.get("emphasis", []):
52
+ start = 0
53
+ while (start := text.find(word, start)) >= 0:
54
+ highlighted.update(range(start, start + len(word)))
55
+ start += len(word)
56
+ opacity = 255 if item.duration_frames - relative > 2 else 180
57
+ stroke = max(2, round(size * 0.095))
58
+ line_height = round(size * 1.35)
59
+ baseline = round(timeline.height * 0.90) - (len(lines) - 1) * line_height
60
+ offset = 0
45
61
  for line in lines:
46
- x=(timeline.width-draw.textlength(line,font=font))/2
62
+ x = (timeline.width - draw.textlength(line, font=font)) / 2
47
63
  for character in line:
48
- color=tuple(profile.get('emphasis_color',[255,217,55,255])[:3])+(opacity,) if offset in highlighted else (255,255,255,opacity)
49
- draw.text((x+2,baseline+3),character,font=font,anchor='ls',fill=(0,0,0,110),stroke_width=stroke+1,stroke_fill=(0,0,0,110))
50
- draw.text((x,baseline),character,font=font,anchor='ls',fill=color,stroke_width=stroke,stroke_fill=tuple(profile.get('outline_color',[10,10,14,255])[:3])+(opacity,))
51
- x+=draw.textlength(character,font=font);offset+=1
52
- baseline+=line_height
64
+ color = (
65
+ tuple(profile.get("emphasis_color", [255, 217, 55, 255])[:3]) + (opacity,)
66
+ if offset in highlighted
67
+ else (255, 255, 255, opacity)
68
+ )
69
+ draw.text(
70
+ (x + 2, baseline + 3),
71
+ character,
72
+ font=font,
73
+ anchor="ls",
74
+ fill=(0, 0, 0, 110),
75
+ stroke_width=stroke + 1,
76
+ stroke_fill=(0, 0, 0, 110),
77
+ )
78
+ draw.text(
79
+ (x, baseline),
80
+ character,
81
+ font=font,
82
+ anchor="ls",
83
+ fill=color,
84
+ stroke_width=stroke,
85
+ stroke_fill=tuple(profile.get("outline_color", [10, 10, 14, 255])[:3]) + (opacity,),
86
+ )
87
+ x += draw.textlength(character, font=font)
88
+ offset += 1
89
+ baseline += line_height