@dsh-gis/dsh-video-studio-skill 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -12
- package/docs/styles/demo-results.json +76 -0
- package/docs/styles/sheet-8-styles.png +0 -0
- package/docs/styles/sheet-ai.png +0 -0
- package/docs/styles/sheet-craft.png +0 -0
- package/docs/styles/sheet-night.png +0 -0
- package/package.json +11 -3
- package/schemas/film.schema.json +528 -0
- package/skills/video-studio/SKILL.md +166 -14
- package/skills/video-studio/assets/film.json +84 -23
- package/skills/video-studio/assets/scenes.py +892 -34
- package/skills/video-studio/references/audio.md +29 -1
- package/skills/video-studio/references/change-impact.md +54 -0
- package/skills/video-studio/references/quality-gates.md +1 -1
- package/skills/video-studio/references/style-packs.md +178 -0
- package/skills/video-studio/requirements.txt +11 -0
- package/skills/video-studio/scripts/filmcheck.py +656 -0
- package/skills/video-studio/scripts/filmkit.py +682 -58
- package/skills/video-studio/scripts/gates.py +446 -0
- package/skills/video-studio/scripts/render.py +562 -34
- package/skills/video-studio/scripts/scorekit.py +1642 -25
- package/skills/video-studio/scripts/selfcheck.py +346 -0
- package/skills/video-studio/scripts/stagewatch.py +295 -0
- package/skills/video-studio/scripts/stylekit.py +924 -0
- package/skills/video-studio/scripts/voicekit.py +872 -0
- package/tools/ci_check.py +339 -0
- package/tools/estimate.py +578 -0
|
@@ -0,0 +1,924 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""stylekit.py — 风格包(Style Packs):一个 id 同时决定画风、配乐、旁白与节奏。
|
|
3
|
+
|
|
4
|
+
v0.5.0 新增。解决的问题是 v0.4 及以前的同质化:画风锁死在 scenes.py 的 THEME 常量、
|
|
5
|
+
配乐锁死在 scorekit 的 Dm/120,旁白锁死在 render.py 的单个 voice —— 每部片必然长一个样。
|
|
6
|
+
|
|
7
|
+
设计原则
|
|
8
|
+
--------
|
|
9
|
+
1. 纯数据 + 纯函数:本模块只依赖标准库,不 import filmkit / scorekit / scenes
|
|
10
|
+
(它们反过来 import 我,成环就炸)。因此可以随便单测、追求确定性。
|
|
11
|
+
2. 一个风格包决定三件事:主题(配色/字体/材质/HUD)、配乐(BPM 梯度/调池/情绪/音色组)、
|
|
12
|
+
旁白(声线映射),外加节奏(lead/tail/min_dur/条目落位步长)。不允许互相独立配,
|
|
13
|
+
否则会出现「极简黑白画面 + 史诗管弦」这种打架组合。
|
|
14
|
+
3. 确定性:内容指纹只用 sha1 派生,禁 random / time / hash()(str hash 带随机盐)。
|
|
15
|
+
同一份 film.json 永远解析出同一个风格;换一部片三个指纹大概率都变。
|
|
16
|
+
4. 向后兼容:不写 style 字段 = legacy,此时 render/scorekit/scenes 走 v0.4 原路径,
|
|
17
|
+
配乐逐样本一致(selfcheck 有断言)。
|
|
18
|
+
|
|
19
|
+
三级指纹(专门为了「改个错别字不要换整首曲子」)
|
|
20
|
+
---------------------------------------------
|
|
21
|
+
full 标题 + 所有台词 -> 决定音色细节 / 噪声纹理(seed 派生)
|
|
22
|
+
tempo 标题 + kind 序列 + 体量桶 -> 决定 BPM 与调性
|
|
23
|
+
style 关键词评分 + 指纹破平 -> 决定风格 id
|
|
24
|
+
|
|
25
|
+
用法
|
|
26
|
+
----
|
|
27
|
+
import stylekit as ST
|
|
28
|
+
plan = ST.resolve_script_style(script) # 纯函数,返回可直接落盘的 dict
|
|
29
|
+
th = ST.theme_of(plan["style"]) # 主题字典(元组原样,给 PIL 用)
|
|
30
|
+
ST.theme_lint(th) # 对比度体检,返回问题列表(空 = 过)
|
|
31
|
+
|
|
32
|
+
python stylekit.py --list # 列所有风格
|
|
33
|
+
python stylekit.py --show cinema # 看一套风格的完整字段
|
|
34
|
+
python stylekit.py --lint # 8 套主题全部走对比度门禁
|
|
35
|
+
"""
|
|
36
|
+
from __future__ import annotations
|
|
37
|
+
|
|
38
|
+
import argparse
|
|
39
|
+
import hashlib
|
|
40
|
+
import sys
|
|
41
|
+
|
|
42
|
+
# ============================================================================
|
|
43
|
+
# 一、色彩:WCAG 2.1 对比度(门禁要用,所以放在本模块,纯标准库)
|
|
44
|
+
# ============================================================================
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _srgb_to_lin(v):
|
|
48
|
+
"""sRGB 通道(0..255)-> 线性光。"""
|
|
49
|
+
c = float(v) / 255.0
|
|
50
|
+
return c / 12.92 if c <= 0.04045 else ((c + 0.055) / 1.055) ** 2.4
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def luminance(rgb):
|
|
54
|
+
"""相对亮度(WCAG 定义,0=黑 1=白)。"""
|
|
55
|
+
r, g, b = rgb[0], rgb[1], rgb[2]
|
|
56
|
+
return 0.2126 * _srgb_to_lin(r) + 0.7152 * _srgb_to_lin(g) + 0.0722 * _srgb_to_lin(b)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def contrast(c1, c2):
|
|
60
|
+
"""两色的对比度(1.0 ~ 21.0)。文字门禁用它,比「看截图觉得还行」可靠。"""
|
|
61
|
+
l1, l2 = luminance(c1), luminance(c2)
|
|
62
|
+
hi, lo = (l1, l2) if l1 >= l2 else (l2, l1)
|
|
63
|
+
return (hi + 0.05) / (lo + 0.05)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def midpoint(c1, c2):
|
|
67
|
+
"""两色中点(渐变背景的中位亮度,作为文字对比度的参考底)。"""
|
|
68
|
+
return (int(round((c1[0] + c2[0]) / 2.0)),
|
|
69
|
+
int(round((c1[1] + c2[1]) / 2.0)),
|
|
70
|
+
int(round((c1[2] + c2[2]) / 2.0)))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _rgb(seq):
|
|
74
|
+
t = tuple(int(v) for v in seq[:3])
|
|
75
|
+
if len(t) != 3 or any(v < 0 or v > 255 for v in t):
|
|
76
|
+
raise ValueError("颜色必须是 0..255 的 RGB 三元组,收到 %r" % (seq,))
|
|
77
|
+
return t
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _theme(style_id, label, keywords, palette, material, typ, layout, motion, hud, qa):
|
|
81
|
+
"""把主题字段组装成一个扁平 dict(场景代码直接下标取,不嵌套,读起来快)。"""
|
|
82
|
+
p = {k: _rgb(v) for k, v in palette.items()}
|
|
83
|
+
return {
|
|
84
|
+
"id": style_id,
|
|
85
|
+
"label": label,
|
|
86
|
+
"keywords": tuple(keywords),
|
|
87
|
+
# T0 配色
|
|
88
|
+
"bg": p["bg"], "bg2": p["bg2"], "surface": p["surface"],
|
|
89
|
+
"ink": p["ink"], "muted": p["muted"], "dim": p["dim"],
|
|
90
|
+
"accent": p["accent"], "accent2": p["accent2"],
|
|
91
|
+
"good": p["good"], "bad": p["bad"], "rule": p["rule"],
|
|
92
|
+
# T1 材质
|
|
93
|
+
"vignette": float(material["vignette"]),
|
|
94
|
+
"vignette_tint": _rgb(material["vignette_tint"]),
|
|
95
|
+
"grain": float(material["grain"]),
|
|
96
|
+
"grain_freq": float(material["grain_freq"]),
|
|
97
|
+
"texture": str(material["texture"]),
|
|
98
|
+
"texture_alpha": float(material["texture_alpha"]),
|
|
99
|
+
# T2 排版
|
|
100
|
+
"family": str(typ["family"]),
|
|
101
|
+
"scale": dict(typ["scale"]),
|
|
102
|
+
"line_gap": float(typ.get("line_gap", 1.30)),
|
|
103
|
+
"tracking": float(typ.get("tracking", 0.0)),
|
|
104
|
+
# T3 版式
|
|
105
|
+
"layout": str(layout["layout"]),
|
|
106
|
+
"card": dict(layout["card"]),
|
|
107
|
+
"safe_bias": int(layout.get("safe_bias", 0)),
|
|
108
|
+
# T4 动态
|
|
109
|
+
"ease": str(motion["ease"]),
|
|
110
|
+
"entrance_dx": int(motion["entrance_dx"]),
|
|
111
|
+
"entrance_dy": int(motion["entrance_dy"]),
|
|
112
|
+
"push": float(motion["push"]),
|
|
113
|
+
"item_stagger": float(motion["item_stagger"]),
|
|
114
|
+
"transition": str(motion["transition"]),
|
|
115
|
+
# T5 HUD
|
|
116
|
+
"hud": str(hud["style"]),
|
|
117
|
+
# META
|
|
118
|
+
"qa": dict(qa),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
THEMES = {}
|
|
123
|
+
|
|
124
|
+
THEMES["tech-deep"] = _theme(
|
|
125
|
+
"tech-deep", "科技深蓝",
|
|
126
|
+
("AI", "算法", "代码", "模型", "系统", "数据", "架构", "开源", "编程", "大模型"),
|
|
127
|
+
dict(bg=(7, 14, 26), bg2=(17, 33, 54), surface=(26, 42, 64),
|
|
128
|
+
ink=(240, 245, 252), muted=(150, 174, 200), dim=(120, 142, 168),
|
|
129
|
+
accent=(243, 132, 60), accent2=(86, 170, 232),
|
|
130
|
+
good=(108, 178, 110), bad=(226, 96, 92), rule=(255, 255, 255)),
|
|
131
|
+
dict(vignette=0.40, vignette_tint=(0, 0, 0), grain=5.0, grain_freq=0.31,
|
|
132
|
+
texture="dots", texture_alpha=0.045),
|
|
133
|
+
dict(family="sans", scale={"display": (96, "bold"), "heading": (64, "bold"),
|
|
134
|
+
"sub": (38, "light"), "body": (34, "reg"),
|
|
135
|
+
"kicker": (28, "bold"), "chip": (27, "reg"),
|
|
136
|
+
"brand": (23, "reg")}),
|
|
137
|
+
dict(layout="left-stack",
|
|
138
|
+
card={"radius": 14, "fill_a": 16, "outline_a": 28, "pad": 34, "h": 96, "gap": 118}),
|
|
139
|
+
dict(ease="out3", entrance_dx=0, entrance_dy=26, push=0.04, item_stagger=0.32, transition="black"),
|
|
140
|
+
dict(style="chip-left"),
|
|
141
|
+
dict(luma_max=0.030, flicker_thresh=6.0, dark=True),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
THEMES["magazine"] = _theme(
|
|
145
|
+
"magazine", "杂志暖白",
|
|
146
|
+
("报告", "复盘", "年度", "总结", "研究", "分析", "调研", "白皮书", "趋势", "发布"),
|
|
147
|
+
dict(bg=(250, 246, 238), bg2=(236, 228, 214), surface=(255, 252, 246),
|
|
148
|
+
ink=(28, 26, 24), muted=(88, 82, 74), dim=(112, 104, 94),
|
|
149
|
+
accent=(176, 48, 40), accent2=(38, 86, 128),
|
|
150
|
+
good=(30, 110, 72), bad=(160, 36, 32), rule=(28, 26, 24)),
|
|
151
|
+
dict(vignette=0.10, vignette_tint=(214, 204, 186), grain=3.0, grain_freq=0.27,
|
|
152
|
+
texture="paper", texture_alpha=0.030),
|
|
153
|
+
dict(family="serif", scale={"display": (92, "bold"), "heading": (60, "bold"),
|
|
154
|
+
"sub": (36, "light"), "body": (33, "reg"),
|
|
155
|
+
"kicker": (27, "bold"), "chip": (26, "reg"),
|
|
156
|
+
"brand": (22, "reg")}, line_gap=1.34, tracking=2.0),
|
|
157
|
+
dict(layout="split-right",
|
|
158
|
+
card={"radius": 8, "fill_a": 26, "outline_a": 40, "pad": 30, "h": 92, "gap": 112},
|
|
159
|
+
safe_bias=-8),
|
|
160
|
+
dict(ease="out5", entrance_dx=18, entrance_dy=20, push=0.06, item_stagger=0.38, transition="wash"),
|
|
161
|
+
dict(style="corner-line"),
|
|
162
|
+
dict(luma_max=0.045, flicker_thresh=6.0, dark=False),
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
THEMES["paper"] = _theme(
|
|
166
|
+
"paper", "手绘纸感",
|
|
167
|
+
("手工", "自然", "历史", "传统", "木", "田野", "匠", "古", "茶", "手艺", "山河"),
|
|
168
|
+
dict(bg=(240, 232, 212), bg2=(222, 210, 186), surface=(249, 244, 232),
|
|
169
|
+
ink=(46, 38, 30), muted=(92, 80, 64), dim=(112, 98, 80),
|
|
170
|
+
accent=(42, 72, 116), accent2=(124, 72, 32),
|
|
171
|
+
good=(48, 98, 60), bad=(150, 48, 40), rule=(46, 38, 30)),
|
|
172
|
+
dict(vignette=0.14, vignette_tint=(198, 184, 158), grain=9.0, grain_freq=0.22,
|
|
173
|
+
texture="paper", texture_alpha=0.055),
|
|
174
|
+
dict(family="kai", scale={"display": (92, "bold"), "heading": (60, "bold"),
|
|
175
|
+
"sub": (36, "light"), "body": (33, "reg"),
|
|
176
|
+
"kicker": (27, "bold"), "chip": (26, "reg"),
|
|
177
|
+
"brand": (22, "reg")}, line_gap=1.36, tracking=1.0),
|
|
178
|
+
dict(layout="left-stack",
|
|
179
|
+
card={"radius": 4, "fill_a": 30, "outline_a": 52, "pad": 32, "h": 94, "gap": 116}),
|
|
180
|
+
dict(ease="inOut3", entrance_dx=0, entrance_dy=18, push=0.03, item_stagger=0.42, transition="wash"),
|
|
181
|
+
dict(style="corner-line"),
|
|
182
|
+
dict(luma_max=0.045, flicker_thresh=6.0, dark=False),
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
THEMES["vivid"] = _theme(
|
|
186
|
+
"vivid", "活力撞色",
|
|
187
|
+
("活动", "上新", "招募", "挑战", "年轻", "潮流", "种草", "福利", "开箱", "限量"),
|
|
188
|
+
dict(bg=(20, 18, 34), bg2=(38, 26, 58), surface=(46, 34, 70),
|
|
189
|
+
ink=(255, 252, 246), muted=(206, 196, 224), dim=(168, 158, 190),
|
|
190
|
+
accent=(255, 214, 64), accent2=(120, 224, 255),
|
|
191
|
+
good=(120, 230, 150), bad=(255, 120, 150), rule=(255, 255, 255)),
|
|
192
|
+
dict(vignette=0.24, vignette_tint=(12, 10, 22), grain=4.0, grain_freq=0.35,
|
|
193
|
+
texture="grid", texture_alpha=0.060),
|
|
194
|
+
dict(family="sans", scale={"display": (104, "bold"), "heading": (68, "bold"),
|
|
195
|
+
"sub": (39, "reg"), "body": (35, "reg"),
|
|
196
|
+
"kicker": (30, "bold"), "chip": (27, "reg"),
|
|
197
|
+
"brand": (23, "reg")}, line_gap=1.26, tracking=1.0),
|
|
198
|
+
dict(layout="center-stack",
|
|
199
|
+
card={"radius": 22, "fill_a": 30, "outline_a": 56, "pad": 32, "h": 100, "gap": 122}),
|
|
200
|
+
dict(ease="outBack", entrance_dx=0, entrance_dy=34, push=0.10, item_stagger=0.26, transition="black"),
|
|
201
|
+
dict(style="chip-left"),
|
|
202
|
+
dict(luma_max=0.030, flicker_thresh=8.0, dark=True),
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
THEMES["mono"] = _theme(
|
|
206
|
+
"mono", "极简黑白",
|
|
207
|
+
("观点", "为什么", "本质", "真相", "极简", "反思", "边界", "定义", "取舍"),
|
|
208
|
+
dict(bg=(246, 246, 244), bg2=(222, 222, 220), surface=(255, 255, 255),
|
|
209
|
+
ink=(16, 16, 16), muted=(68, 68, 68), dim=(104, 104, 104),
|
|
210
|
+
accent=(16, 16, 16), accent2=(80, 80, 80),
|
|
211
|
+
good=(38, 92, 52), bad=(150, 36, 36), rule=(16, 16, 16)),
|
|
212
|
+
dict(vignette=0.06, vignette_tint=(214, 214, 212), grain=0.0, grain_freq=0.30,
|
|
213
|
+
texture="none", texture_alpha=0.0),
|
|
214
|
+
dict(family="sans", scale={"display": (104, "bold"), "heading": (66, "bold"),
|
|
215
|
+
"sub": (36, "light"), "body": (33, "reg"),
|
|
216
|
+
"kicker": (26, "bold"), "chip": (25, "reg"),
|
|
217
|
+
"brand": (21, "reg")}, line_gap=1.40, tracking=6.0),
|
|
218
|
+
dict(layout="center-stack",
|
|
219
|
+
card={"radius": 0, "fill_a": 0, "outline_a": 70, "pad": 28, "h": 90, "gap": 108}),
|
|
220
|
+
dict(ease="inOut3", entrance_dx=0, entrance_dy=12, push=0.02, item_stagger=0.55, transition="none"),
|
|
221
|
+
dict(style="corner-line"),
|
|
222
|
+
dict(luma_max=0.045, flicker_thresh=6.0, dark=False),
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
THEMES["cinema"] = _theme(
|
|
226
|
+
"cinema", "电影青橙",
|
|
227
|
+
("故事", "记忆", "城市", "深夜", "旅行", "纪实", "情绪", "时代", "变迁", "命运"),
|
|
228
|
+
dict(bg=(8, 14, 16), bg2=(20, 32, 34), surface=(26, 40, 42),
|
|
229
|
+
ink=(238, 234, 226), muted=(164, 176, 170), dim=(128, 140, 136),
|
|
230
|
+
accent=(232, 126, 58), accent2=(104, 196, 190),
|
|
231
|
+
good=(116, 196, 140), bad=(214, 92, 84), rule=(255, 255, 255)),
|
|
232
|
+
dict(vignette=0.55, vignette_tint=(0, 0, 0), grain=6.0, grain_freq=0.29,
|
|
233
|
+
texture="scanlines", texture_alpha=0.035),
|
|
234
|
+
dict(family="sans", scale={"display": (94, "bold"), "heading": (58, "bold"),
|
|
235
|
+
"sub": (36, "light"), "body": (33, "reg"),
|
|
236
|
+
"kicker": (27, "bold"), "chip": (26, "reg"),
|
|
237
|
+
"brand": (22, "reg")}, line_gap=1.38, tracking=3.0),
|
|
238
|
+
dict(layout="center-stack",
|
|
239
|
+
card={"radius": 2, "fill_a": 14, "outline_a": 30, "pad": 30, "h": 92, "gap": 114}),
|
|
240
|
+
dict(ease="inOut3", entrance_dx=0, entrance_dy=16, push=0.12, item_stagger=0.46, transition="black"),
|
|
241
|
+
dict(style="corner-line"),
|
|
242
|
+
dict(luma_max=0.020, flicker_thresh=6.0, dark=True),
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
THEMES["lo-fi"] = _theme(
|
|
246
|
+
"lo-fi", "暖灰薄荷",
|
|
247
|
+
("深夜", "学习", "效率", "专注", "写作", "整理", "笔记", "书", "日常", "房间"),
|
|
248
|
+
# 冷调灰绿:和 paper(暖牛皮纸)在色相上分开,不靠"亮度差不多"硬撑
|
|
249
|
+
dict(bg=(232, 238, 236), bg2=(210, 220, 216), surface=(244, 248, 246),
|
|
250
|
+
ink=(44, 52, 50), muted=(86, 100, 96), dim=(112, 126, 122),
|
|
251
|
+
accent=(20, 86, 84), accent2=(104, 72, 96),
|
|
252
|
+
good=(40, 100, 72), bad=(146, 52, 50), rule=(44, 52, 50)),
|
|
253
|
+
dict(vignette=0.12, vignette_tint=(206, 200, 190), grain=7.0, grain_freq=0.24,
|
|
254
|
+
texture="paper", texture_alpha=0.048),
|
|
255
|
+
dict(family="sans", scale={"display": (86, "bold"), "heading": (58, "bold"),
|
|
256
|
+
"sub": (35, "light"), "body": (32, "reg"),
|
|
257
|
+
"kicker": (26, "bold"), "chip": (25, "reg"),
|
|
258
|
+
"brand": (21, "reg")}, line_gap=1.36, tracking=1.0),
|
|
259
|
+
dict(layout="left-stack",
|
|
260
|
+
card={"radius": 18, "fill_a": 40, "outline_a": 26, "pad": 34, "h": 98, "gap": 120},
|
|
261
|
+
safe_bias=6),
|
|
262
|
+
dict(ease="out3", entrance_dx=0, entrance_dy=22, push=0.05, item_stagger=0.44, transition="wash"),
|
|
263
|
+
dict(style="chip-left"),
|
|
264
|
+
dict(luma_max=0.045, flicker_thresh=6.0, dark=False),
|
|
265
|
+
)
|
|
266
|
+
|
|
267
|
+
THEMES["epic"] = _theme(
|
|
268
|
+
"epic", "深黑鎏金",
|
|
269
|
+
("史诗", "爆发", "冲击", "巅峰", "决战", "荣耀", "震撼", "传奇", "极限", "突破"),
|
|
270
|
+
dict(bg=(9, 9, 12), bg2=(24, 20, 16), surface=(32, 28, 22),
|
|
271
|
+
ink=(248, 242, 228), muted=(186, 176, 158), dim=(142, 134, 120),
|
|
272
|
+
accent=(222, 178, 84), accent2=(206, 116, 92),
|
|
273
|
+
good=(140, 200, 140), bad=(222, 96, 84), rule=(255, 255, 255)),
|
|
274
|
+
dict(vignette=0.62, vignette_tint=(0, 0, 0), grain=5.0, grain_freq=0.26,
|
|
275
|
+
texture="scanlines", texture_alpha=0.028),
|
|
276
|
+
dict(family="serif", scale={"display": (108, "bold"), "heading": (70, "bold"),
|
|
277
|
+
"sub": (38, "light"), "body": (34, "reg"),
|
|
278
|
+
"kicker": (29, "bold"), "chip": (27, "reg"),
|
|
279
|
+
"brand": (23, "reg")}, line_gap=1.32, tracking=4.0),
|
|
280
|
+
dict(layout="center-stack",
|
|
281
|
+
card={"radius": 6, "fill_a": 20, "outline_a": 44, "pad": 32, "h": 98, "gap": 120}),
|
|
282
|
+
dict(ease="out5", entrance_dx=0, entrance_dy=24, push=0.14, item_stagger=0.34, transition="black"),
|
|
283
|
+
dict(style="corner-line"),
|
|
284
|
+
dict(luma_max=0.018, flicker_thresh=6.0, dark=True),
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
# ============================================================================
|
|
288
|
+
# 三、版式骨架(LAYOUTS):3 种,scenes.py 按名字取几何参数
|
|
289
|
+
# ============================================================================
|
|
290
|
+
#
|
|
291
|
+
# 这是「每屏都长得一样」的解药:同一部片可以按章节在骨架之间轮换,但不换明暗族、不换 accent,
|
|
292
|
+
# 所以整体仍是一部片。几何全部相对于 W/H 与 SAFE,不写死 1920 里的魔法数。
|
|
293
|
+
|
|
294
|
+
LAYOUTS = {
|
|
295
|
+
"left-stack": {
|
|
296
|
+
"label": "左标题 / 右卡片",
|
|
297
|
+
"title_x": 150, "title_y": 300, "title_w": 820,
|
|
298
|
+
"kicker_y": 250, "sub_y": 420, "sub_w": 820,
|
|
299
|
+
"panel_x": 1030, "panel_y": 240, "panel_w": 740, "panel_h": 96, "panel_gap": 118,
|
|
300
|
+
"center": False,
|
|
301
|
+
},
|
|
302
|
+
"center-stack": {
|
|
303
|
+
"label": "居中大字",
|
|
304
|
+
"title_x": None, "title_y": 330, "title_w": 1560,
|
|
305
|
+
"kicker_y": 268, "sub_y": 0, "sub_w": 1400,
|
|
306
|
+
"panel_x": None, "panel_y": 650, "panel_w": 1320, "panel_h": 92, "panel_gap": 108,
|
|
307
|
+
"center": True,
|
|
308
|
+
},
|
|
309
|
+
"split-right": {
|
|
310
|
+
"label": "右标题 / 左卡片",
|
|
311
|
+
"title_x": None, "title_y": 300, "title_w": 820,
|
|
312
|
+
"kicker_y": 250, "sub_y": 420, "sub_w": 820,
|
|
313
|
+
"panel_x": 150, "panel_y": 240, "panel_w": 740, "panel_h": 96, "panel_gap": 118,
|
|
314
|
+
"center": False,
|
|
315
|
+
},
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
LAYOUT_IDS = tuple(LAYOUTS.keys())
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
def layout(name):
|
|
322
|
+
"""取版式几何;未知名字报错并列出可用值(不静默回落)。"""
|
|
323
|
+
if name not in LAYOUTS:
|
|
324
|
+
raise KeyError("未知版式 %r;可用:%s" % (name, " / ".join(LAYOUT_IDS)))
|
|
325
|
+
return LAYOUTS[name]
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
# ============================================================================
|
|
329
|
+
# 四、风格包(STYLES):一个 id = 主题 + 配乐 + 旁白 + 节奏
|
|
330
|
+
# ============================================================================
|
|
331
|
+
#
|
|
332
|
+
# music 字段只放「策展层」(BPM 梯度 / 调池 / 情绪 / 音色组偏好),
|
|
333
|
+
# 具体的和弦进行、鼓型、乐器合成在 scorekit 里(合成层)。两边用同一个 style id 对齐。
|
|
334
|
+
|
|
335
|
+
STYLE_IDS = ("tech-deep", "magazine", "paper", "vivid", "mono", "cinema", "lo-fi", "epic")
|
|
336
|
+
DEFAULT_STYLE = "tech-deep"
|
|
337
|
+
LEGACY_STYLE = "legacy" # 显式老行为:v0.4 的画风 + 配乐 + 单一旁白
|
|
338
|
+
|
|
339
|
+
MINOR_KEYS = ("Dm", "Am", "Em", "Cm")
|
|
340
|
+
MAJOR_KEYS = ("C", "G", "D", "F", "A", "Bb")
|
|
341
|
+
|
|
342
|
+
STYLES = {
|
|
343
|
+
"tech-deep": {
|
|
344
|
+
"name": "科技深蓝",
|
|
345
|
+
"tags": ("AI", "工程", "数据", "科普"),
|
|
346
|
+
"theme": "tech-deep",
|
|
347
|
+
"layouts": ("left-stack", "split-right"),
|
|
348
|
+
"music": {"keys": ("Dm", "Am", "Em", "Cm"), "scale": "minor",
|
|
349
|
+
"bpm_ladder": (100, 108, 116, 124), "mood": "steady"},
|
|
350
|
+
"voice": {"body": "narrator_male", "hook": "young_male",
|
|
351
|
+
"quote": "narrator_female", "outro": "narrator_male"},
|
|
352
|
+
"pacing": {"lead": 0.58, "tail": 0.88, "min_dur": 3.0, "hold": 0.0},
|
|
353
|
+
},
|
|
354
|
+
"magazine": {
|
|
355
|
+
"name": "杂志暖白",
|
|
356
|
+
"tags": ("报告", "复盘", "研究", "出版物"),
|
|
357
|
+
"theme": "magazine",
|
|
358
|
+
"layouts": ("left-stack", "split-right"),
|
|
359
|
+
"music": {"keys": ("C", "G", "D", "F"), "scale": "major",
|
|
360
|
+
"bpm_ladder": (88, 92, 96, 100), "mood": "reflective"},
|
|
361
|
+
"voice": {"body": "narrator_female", "hook": "narrator_female",
|
|
362
|
+
"quote": "authority_male", "outro": "narrator_female"},
|
|
363
|
+
"pacing": {"lead": 0.64, "tail": 0.94, "min_dur": 3.2, "hold": 0.2},
|
|
364
|
+
},
|
|
365
|
+
"paper": {
|
|
366
|
+
"name": "手绘纸感",
|
|
367
|
+
"tags": ("手工", "自然", "历史", "人文"),
|
|
368
|
+
"theme": "paper",
|
|
369
|
+
"layouts": ("left-stack", "center-stack"),
|
|
370
|
+
"music": {"keys": ("G", "D", "C"), "scale": "major",
|
|
371
|
+
"bpm_ladder": (84, 88, 92), "mood": "hopeful"},
|
|
372
|
+
"voice": {"body": "warm_female", "hook": "narrator_female",
|
|
373
|
+
"quote": "narrator_male", "outro": "warm_female"},
|
|
374
|
+
"pacing": {"lead": 0.68, "tail": 1.00, "min_dur": 3.4, "hold": 0.3},
|
|
375
|
+
},
|
|
376
|
+
"vivid": {
|
|
377
|
+
"name": "活力撞色",
|
|
378
|
+
"tags": ("活动", "营销", "年轻", "上新"),
|
|
379
|
+
"theme": "vivid",
|
|
380
|
+
"layouts": ("center-stack", "left-stack"),
|
|
381
|
+
"music": {"keys": ("D", "G", "A"), "scale": "major",
|
|
382
|
+
"bpm_ladder": (120, 126, 132), "mood": "uplifting"},
|
|
383
|
+
"voice": {"body": "narrator_female", "hook": "bright_female",
|
|
384
|
+
"quote": "young_male", "outro": "bright_female"},
|
|
385
|
+
"pacing": {"lead": 0.46, "tail": 0.76, "min_dur": 2.8, "hold": 0.0},
|
|
386
|
+
},
|
|
387
|
+
"mono": {
|
|
388
|
+
"name": "极简黑白",
|
|
389
|
+
"tags": ("观点", "演讲", "思辨", "极简"),
|
|
390
|
+
"theme": "mono",
|
|
391
|
+
"layouts": ("center-stack",),
|
|
392
|
+
"music": {"keys": ("C", "F", "Am"), "scale": "major",
|
|
393
|
+
"bpm_ladder": (60, 64, 68), "mood": "calm"},
|
|
394
|
+
"voice": {"body": "narrator_male", "hook": "authority_male",
|
|
395
|
+
"quote": "narrator_female", "outro": "authority_male"},
|
|
396
|
+
"pacing": {"lead": 0.86, "tail": 1.24, "min_dur": 4.0, "hold": 0.6},
|
|
397
|
+
},
|
|
398
|
+
"cinema": {
|
|
399
|
+
"name": "电影青橙",
|
|
400
|
+
"tags": ("纪录", "叙事", "散文", "城市"),
|
|
401
|
+
"theme": "cinema",
|
|
402
|
+
"layouts": ("center-stack", "left-stack"),
|
|
403
|
+
"music": {"keys": ("Dm", "Am"), "scale": "minor",
|
|
404
|
+
"bpm_ladder": (76, 80, 84), "mood": "reflective"},
|
|
405
|
+
"voice": {"body": "narrator_male", "hook": "authority_male",
|
|
406
|
+
"quote": "narrator_female", "outro": "narrator_male"},
|
|
407
|
+
"pacing": {"lead": 0.76, "tail": 1.10, "min_dur": 3.6, "hold": 0.4},
|
|
408
|
+
},
|
|
409
|
+
"lo-fi": {
|
|
410
|
+
"name": "暖灰薄荷",
|
|
411
|
+
"tags": ("日常", "学习", "专注", "深夜"),
|
|
412
|
+
"theme": "lo-fi",
|
|
413
|
+
"layouts": ("left-stack", "split-right"),
|
|
414
|
+
"music": {"keys": ("C", "F", "G"), "scale": "major",
|
|
415
|
+
"bpm_ladder": (72, 78, 84), "mood": "calm"},
|
|
416
|
+
"voice": {"body": "narrator_female", "hook": "warm_female",
|
|
417
|
+
"quote": "narrator_male", "outro": "narrator_female"},
|
|
418
|
+
"pacing": {"lead": 0.72, "tail": 1.06, "min_dur": 3.4, "hold": 0.4},
|
|
419
|
+
},
|
|
420
|
+
"epic": {
|
|
421
|
+
"name": "深黑鎏金",
|
|
422
|
+
"tags": ("史诗", "宣传", "高潮", "荣耀"),
|
|
423
|
+
"theme": "epic",
|
|
424
|
+
"layouts": ("center-stack",),
|
|
425
|
+
"music": {"keys": ("Cm", "Dm"), "scale": "minor",
|
|
426
|
+
"bpm_ladder": (88, 92, 96), "mood": "driving"},
|
|
427
|
+
"voice": {"body": "authority_male", "hook": "narrator_male",
|
|
428
|
+
"quote": "narrator_female", "outro": "authority_male"},
|
|
429
|
+
"pacing": {"lead": 0.62, "tail": 0.96, "min_dur": 3.2, "hold": 0.2},
|
|
430
|
+
},
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
# 老行为(不写 style 时):画风 = v0.4 的深蓝橙,配乐 = v0.4 的 Dm/120/seed7,旁白 = script.voice
|
|
434
|
+
STYLES[LEGACY_STYLE] = {
|
|
435
|
+
"name": "v0.4 兼容",
|
|
436
|
+
"tags": ("兼容", "老项目"),
|
|
437
|
+
"theme": "tech-deep",
|
|
438
|
+
"layouts": ("left-stack",),
|
|
439
|
+
"music": {"keys": ("Dm", "Am", "Cm", "Em"), "scale": "minor",
|
|
440
|
+
"bpm_ladder": (120,), "mood": "steady", "legacy": True},
|
|
441
|
+
"voice": {"body": None, "hook": None, "quote": None, "outro": None},
|
|
442
|
+
# 必须是 render.py v0.4 的函数默认值(lead=0.55 / tail=0.85 / min_dur=3.0),
|
|
443
|
+
# 否则"没写 lead 字段的老剧本"会悄悄换掉节奏 —— legacy 的含义就是一个字节都不变。
|
|
444
|
+
"pacing": {"lead": 0.55, "tail": 0.85, "min_dur": 3.0, "hold": 0.0},
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
ALL_STYLE_IDS = (LEGACY_STYLE,) + STYLE_IDS
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
def style_ids(include_legacy=True):
|
|
451
|
+
return list(ALL_STYLE_IDS) if include_legacy else list(STYLE_IDS)
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def get(style_id):
|
|
455
|
+
"""取风格包;未知 id 报错并列出可用值(不静默回落,v0.4 的教训)。"""
|
|
456
|
+
sid = str(style_id or "").strip()
|
|
457
|
+
if sid not in STYLES:
|
|
458
|
+
raise KeyError("未知风格 %r;可用:%s" % (style_id, " / ".join(ALL_STYLE_IDS)))
|
|
459
|
+
return STYLES[sid]
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
def theme_of(style_id):
|
|
463
|
+
"""取风格对应的主题字典(元组颜色原样返回,给 PIL 直接下标)。"""
|
|
464
|
+
return THEMES[get(style_id)["theme"]]
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def is_legacy(style_id):
|
|
468
|
+
return str(style_id or LEGACY_STYLE) == LEGACY_STYLE
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
# ============================================================================
|
|
472
|
+
# 五、内容指纹与自动选风格
|
|
473
|
+
# ============================================================================
|
|
474
|
+
|
|
475
|
+
FP_VERSION = "style-fp-v1"
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def _digest(*parts):
|
|
479
|
+
"""sha1 派生的稳定 32 位无符号整数(禁 hash():str hash 每次进程带随机盐)。"""
|
|
480
|
+
h = hashlib.sha1(("|".join(str(p) for p in parts)).encode("utf-8")).hexdigest()
|
|
481
|
+
return int(h[:8], 16)
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
def _text_of(script):
|
|
485
|
+
"""把剧本里所有可读文字摊平(标题权重最高)。"""
|
|
486
|
+
title = str(script.get("title") or "")
|
|
487
|
+
chunks = [title, title] # 标题 x2
|
|
488
|
+
for ln in script.get("lines") or []:
|
|
489
|
+
chunks.append(str(ln.get("chapter") or ln.get("kicker") or ""))
|
|
490
|
+
chunks.append(str(ln.get("text") or ""))
|
|
491
|
+
chunks.append(str(ln.get("sub") or ""))
|
|
492
|
+
for it in ln.get("items") or []:
|
|
493
|
+
if isinstance(it, dict):
|
|
494
|
+
chunks.append(str(it.get("text") or ""))
|
|
495
|
+
else:
|
|
496
|
+
chunks.append(str(it))
|
|
497
|
+
return "".join(chunks)
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
def fingerprint(script):
|
|
501
|
+
"""三级内容指纹。同剧本 -> 同指纹;换一部片 -> 三个都变。"""
|
|
502
|
+
title = str(script.get("title") or "")
|
|
503
|
+
lines = script.get("lines") or []
|
|
504
|
+
texts = [str(ln.get("text") or "") for ln in lines]
|
|
505
|
+
kinds = [str(ln.get("kind") or "body") for ln in lines]
|
|
506
|
+
dur_bucket = int(len("".join(texts)) // 120) # 体量桶:改几个字不动它
|
|
507
|
+
return {
|
|
508
|
+
"version": FP_VERSION,
|
|
509
|
+
"full": "%08x" % _digest(FP_VERSION, "full", title, *texts),
|
|
510
|
+
"tempo": "%08x" % _digest(FP_VERSION, "tempo", title, *kinds, dur_bucket),
|
|
511
|
+
"style": "%08x" % _digest(FP_VERSION, "style", title),
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
def _kind_profile(script):
|
|
516
|
+
"""kind 分布画像:用于给风格打分(题材相近的片子 kind 结构也像)。"""
|
|
517
|
+
kinds = [str(ln.get("kind") or "body") for ln in script.get("lines") or []]
|
|
518
|
+
n = max(1, len(kinds))
|
|
519
|
+
return {
|
|
520
|
+
"hook": kinds.count("hook") / n,
|
|
521
|
+
"body": kinds.count("body") / n,
|
|
522
|
+
"outro": kinds.count("outro") / n,
|
|
523
|
+
"items": sum(1 for ln in script.get("lines") or [] if ln.get("items")) / n,
|
|
524
|
+
"avg_len": sum(len(str(ln.get("text") or "")) for ln in script.get("lines") or []) / n,
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def score_styles(script):
|
|
529
|
+
"""给所有风格打分,返回 [(style_id, score, hits)],按分数降序(同分按 STYLE_IDS 顺序)。"""
|
|
530
|
+
text = _text_of(script)
|
|
531
|
+
prof = _kind_profile(script)
|
|
532
|
+
fp = fingerprint(script)
|
|
533
|
+
rows = []
|
|
534
|
+
for sid in STYLE_IDS:
|
|
535
|
+
th = THEMES[STYLES[sid]["theme"]]
|
|
536
|
+
hits = []
|
|
537
|
+
score = 0.0
|
|
538
|
+
for kw in th["keywords"]:
|
|
539
|
+
c = text.count(str(kw))
|
|
540
|
+
if c:
|
|
541
|
+
score += 3.0 * c
|
|
542
|
+
hits.append(str(kw))
|
|
543
|
+
if prof["items"] >= 0.5:
|
|
544
|
+
score += 1.5 if sid in ("tech-deep", "magazine", "vivid") else 0.0
|
|
545
|
+
if prof["avg_len"] >= 28:
|
|
546
|
+
score += 1.0 if sid in ("cinema", "paper", "mono") else 0.0
|
|
547
|
+
if prof["hook"] > 0 and prof["outro"] > 0:
|
|
548
|
+
score += 0.5 if sid in ("tech-deep", "vivid", "epic") else 0.0
|
|
549
|
+
score += (int(fp["style"][:4], 16) % 7) * 0.0001 # 指纹破平
|
|
550
|
+
rows.append((sid, round(score, 4), hits))
|
|
551
|
+
rows.sort(key=lambda r: (-r[1], STYLE_IDS.index(r[0])))
|
|
552
|
+
return rows
|
|
553
|
+
|
|
554
|
+
|
|
555
|
+
def pick_style(script):
|
|
556
|
+
"""内容驱动选风格。返回 (style_id, reason[list[str], 给用户看的理由])。"""
|
|
557
|
+
rows = score_styles(script)
|
|
558
|
+
best_id, best_score, best_hits = rows[0]
|
|
559
|
+
fp = fingerprint(script)
|
|
560
|
+
if best_score >= 1.0:
|
|
561
|
+
reason = ["关键词命中:%s" % "、".join(dict.fromkeys(best_hits))[:80]]
|
|
562
|
+
else:
|
|
563
|
+
pool = list(STYLE_IDS)
|
|
564
|
+
best_id = pool[int(fp["tempo"], 16) % len(pool)]
|
|
565
|
+
reason = ["无关键词命中,按内容指纹落桶(%s)" % fp["tempo"][:8]]
|
|
566
|
+
return best_id, reason
|
|
567
|
+
|
|
568
|
+
|
|
569
|
+
# ============================================================================
|
|
570
|
+
# 六、解析:把 script 里所有显式覆盖 + 自动结果合成一份「最终计划」
|
|
571
|
+
# ============================================================================
|
|
572
|
+
|
|
573
|
+
|
|
574
|
+
def _pick_from_pool(pool, fp_hex, salt=""):
|
|
575
|
+
"""从池里按指纹稳定取一个。
|
|
576
|
+
|
|
577
|
+
salt 用来把"风格 id"混进选择:不同风格即便指纹相同,也会落到池里不同位置。
|
|
578
|
+
没有 salt 时会出现 paper 与 lo-fi 都选到 84BPM / G 调这种"风格不同但基础参数撞车",
|
|
579
|
+
听感上就打了折扣 —— 这正是 v0.4 同质化的另一种形态。
|
|
580
|
+
"""
|
|
581
|
+
seq = [p for p in pool if p]
|
|
582
|
+
if not seq:
|
|
583
|
+
return None
|
|
584
|
+
v = int(fp_hex, 16)
|
|
585
|
+
if salt:
|
|
586
|
+
v += _digest("pick", salt)
|
|
587
|
+
return seq[v % len(seq)]
|
|
588
|
+
|
|
589
|
+
|
|
590
|
+
def _as_bool(v, default=False):
|
|
591
|
+
if v is None:
|
|
592
|
+
return default
|
|
593
|
+
if isinstance(v, str):
|
|
594
|
+
return v.strip().lower() not in ("0", "false", "no", "off", "")
|
|
595
|
+
return bool(v)
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
def resolve_script_style(script):
|
|
599
|
+
"""解析整份剧本的最终风格计划(纯函数、确定性、可直接 json.dump)。
|
|
600
|
+
|
|
601
|
+
优先级(从高到低):
|
|
602
|
+
1. script["style"] 全片锁定(不是 "auto" 就生效)
|
|
603
|
+
2. script["visual"]["theme"] 等价于锁 style(主题与风格 1:1)
|
|
604
|
+
3. 自动:关键词 + 指纹
|
|
605
|
+
配乐 BPM / 调性 / 情绪、旁白声线映射、节奏都能被 film.json 单独覆盖。
|
|
606
|
+
"""
|
|
607
|
+
fp = fingerprint(script)
|
|
608
|
+
vis = script.get("visual") if isinstance(script.get("visual"), dict) else {}
|
|
609
|
+
mus = script.get("music") if isinstance(script.get("music"), dict) else {}
|
|
610
|
+
voce = script.get("voice") if isinstance(script.get("voice"), dict) else {}
|
|
611
|
+
|
|
612
|
+
has_style_field = "style" in script
|
|
613
|
+
raw = script.get("style")
|
|
614
|
+
raw_s = str(raw).strip().lower() if raw is not None else ""
|
|
615
|
+
if not has_style_field and not vis.get("theme") and not mus.get("style"):
|
|
616
|
+
# 老项目(film.json 里根本没有 style 字段)-> legacy:配乐逐样本一致,v0.4 原路径
|
|
617
|
+
sid, source, reason = LEGACY_STYLE, "legacy", ["film.json 没有 style 字段,走 v0.4 兼容路径"]
|
|
618
|
+
elif raw_s in ("", "auto", "default"):
|
|
619
|
+
if vis.get("theme"):
|
|
620
|
+
sid = str(vis["theme"])
|
|
621
|
+
source = "visual.theme"
|
|
622
|
+
reason = ["film.json visual.theme 指定"]
|
|
623
|
+
else:
|
|
624
|
+
sid, reason = pick_style(script)
|
|
625
|
+
source = "auto"
|
|
626
|
+
else:
|
|
627
|
+
sid = str(raw).strip()
|
|
628
|
+
source = "explicit"
|
|
629
|
+
reason = ["film.json style 指定"]
|
|
630
|
+
get(sid) # 未知 id 在这里就炸,不要等到渲染 300 帧后
|
|
631
|
+
pack = STYLES[sid]
|
|
632
|
+
|
|
633
|
+
# ---- 配乐:风格 / BPM / 调性 / 情绪 ----
|
|
634
|
+
music_style = str(mus.get("style") or "").strip().lower()
|
|
635
|
+
if music_style in ("", "auto", "default"):
|
|
636
|
+
music_style = sid if not is_legacy(sid) else LEGACY_STYLE
|
|
637
|
+
mpack = pack["music"]
|
|
638
|
+
ladder = tuple(mpack["bpm_ladder"])
|
|
639
|
+
bpm_raw = mus.get("bpm", script.get("bpm"))
|
|
640
|
+
if isinstance(bpm_raw, str) and bpm_raw.strip().lower() == "auto":
|
|
641
|
+
bpm_raw = "auto"
|
|
642
|
+
if bpm_raw in (None, "", "auto"):
|
|
643
|
+
if is_legacy(sid):
|
|
644
|
+
bpm, bpm_source = 120.0, "legacy" # v0.4 的缺省值,必须是 120
|
|
645
|
+
else:
|
|
646
|
+
bpm = float(_pick_from_pool(ladder, fp["tempo"], salt="bpm:" + sid))
|
|
647
|
+
bpm_source = "style_ladder"
|
|
648
|
+
else:
|
|
649
|
+
bpm, bpm_source = float(bpm_raw), "explicit"
|
|
650
|
+
|
|
651
|
+
key_raw = mus.get("key")
|
|
652
|
+
if key_raw in (None, "", "auto"):
|
|
653
|
+
if is_legacy(sid):
|
|
654
|
+
key, key_source = "Dm", "legacy" # v0.4 的缺省值,必须是 Dm
|
|
655
|
+
else:
|
|
656
|
+
key = _pick_from_pool(mpack["keys"], fp["tempo"], salt="key:" + sid) or "Dm"
|
|
657
|
+
key_source = "style_pool"
|
|
658
|
+
else:
|
|
659
|
+
key, key_source = str(key_raw), "explicit"
|
|
660
|
+
|
|
661
|
+
mood = str(mus.get("mood") or "").strip().lower()
|
|
662
|
+
if mood in ("", "auto", "default"):
|
|
663
|
+
mood, mood_source = str(mpack.get("mood") or "steady"), "style"
|
|
664
|
+
else:
|
|
665
|
+
mood_source = "explicit"
|
|
666
|
+
|
|
667
|
+
seed_raw = mus.get("seed", script.get("seed", 7))
|
|
668
|
+
try:
|
|
669
|
+
seed = abs(int(seed_raw if seed_raw is not None else 7))
|
|
670
|
+
except (TypeError, ValueError):
|
|
671
|
+
seed = 7
|
|
672
|
+
seed_from_content = _as_bool(mus.get("seed_from_content"), default=(not is_legacy(sid)))
|
|
673
|
+
if seed_from_content:
|
|
674
|
+
seed_effective = (seed * 1000003 + int(fp["full"], 16)) % (2 ** 31 - 1)
|
|
675
|
+
else:
|
|
676
|
+
seed_effective = seed
|
|
677
|
+
|
|
678
|
+
# ---- 旁白:声线映射 + 策略 ----
|
|
679
|
+
style_voice = pack["voice"]
|
|
680
|
+
voice_map = {}
|
|
681
|
+
if not is_legacy(sid):
|
|
682
|
+
for kind in ("hook", "body", "quote", "outro"):
|
|
683
|
+
dv = style_voice.get(kind)
|
|
684
|
+
if dv:
|
|
685
|
+
voice_map[kind] = dv
|
|
686
|
+
explicit_map = voce.get("map") if isinstance(voce.get("map"), dict) else {}
|
|
687
|
+
voice_map.update({str(k): str(v) for k, v in explicit_map.items() if v})
|
|
688
|
+
policy = {
|
|
689
|
+
"auto": _as_bool(voce.get("auto"), default=(not is_legacy(sid))),
|
|
690
|
+
"jitter": float(voce.get("jitter", 0.0 if is_legacy(sid) else 0.35)),
|
|
691
|
+
"max_distinct": int(voce.get("max_distinct", 2 if is_legacy(sid) else 3)),
|
|
692
|
+
"rate_range": (-15, 12),
|
|
693
|
+
"pitch_range": (-8, 8),
|
|
694
|
+
"cps_band": (3.6, 5.6),
|
|
695
|
+
}
|
|
696
|
+
if isinstance(voce.get("rate_range"), (list, tuple)) and len(voce["rate_range"]) == 2:
|
|
697
|
+
policy["rate_range"] = (int(voce["rate_range"][0]), int(voce["rate_range"][1]))
|
|
698
|
+
if isinstance(voce.get("cps_band"), (list, tuple)) and len(voce["cps_band"]) == 2:
|
|
699
|
+
policy["cps_band"] = (float(voce["cps_band"][0]), float(voce["cps_band"][1]))
|
|
700
|
+
|
|
701
|
+
# ---- 节奏 ----
|
|
702
|
+
sp = pack["pacing"]
|
|
703
|
+
pacing = {
|
|
704
|
+
"lead": float(script.get("lead", sp["lead"])),
|
|
705
|
+
"tail": float(script.get("tail", sp["tail"])),
|
|
706
|
+
"min_dur": float(script.get("min_dur", sp["min_dur"])),
|
|
707
|
+
"hold": float(script.get("hold", sp["hold"])),
|
|
708
|
+
"item_stagger": float(THEMES[pack["theme"]]["item_stagger"]),
|
|
709
|
+
}
|
|
710
|
+
explicit_pace = script.get("pacing") if isinstance(script.get("pacing"), dict) else {}
|
|
711
|
+
for k in ("lead", "tail", "min_dur", "hold", "item_stagger"):
|
|
712
|
+
if explicit_pace.get(k) is not None:
|
|
713
|
+
pacing[k] = float(explicit_pace[k])
|
|
714
|
+
|
|
715
|
+
# ---- 版式轮换:按 chapter 轮换骨架(同一章节内不变,避免每句都跳) ----
|
|
716
|
+
layouts = list(pack["layouts"]) or ["left-stack"]
|
|
717
|
+
chapters = []
|
|
718
|
+
for ln in script.get("lines") or []:
|
|
719
|
+
ch = str(ln.get("chapter") or "")
|
|
720
|
+
if ch not in chapters:
|
|
721
|
+
chapters.append(ch)
|
|
722
|
+
explicit_layout = str(vis.get("layout") or "").strip()
|
|
723
|
+
if explicit_layout:
|
|
724
|
+
layout(explicit_layout)
|
|
725
|
+
chap_layout = {ch: explicit_layout for ch in chapters}
|
|
726
|
+
else:
|
|
727
|
+
chap_layout = {ch: layouts[i % len(layouts)] for i, ch in enumerate(chapters)}
|
|
728
|
+
|
|
729
|
+
theme = dict(THEMES[pack["theme"]])
|
|
730
|
+
for k, v in (vis.get("theme_overrides") or {}).items():
|
|
731
|
+
if k in theme and isinstance(v, (int, float, str)):
|
|
732
|
+
theme[k] = v
|
|
733
|
+
elif k in theme and isinstance(v, (list, tuple)) and len(v) == 3:
|
|
734
|
+
theme[k] = _rgb(v)
|
|
735
|
+
|
|
736
|
+
return {
|
|
737
|
+
"version": 1,
|
|
738
|
+
"generator": "stylekit 0.5.0",
|
|
739
|
+
"style": sid,
|
|
740
|
+
"style_name": pack["name"],
|
|
741
|
+
"style_source": source,
|
|
742
|
+
"style_reason": list(reason),
|
|
743
|
+
"legacy": bool(is_legacy(sid)),
|
|
744
|
+
"fingerprint": fp,
|
|
745
|
+
"theme_id": pack["theme"],
|
|
746
|
+
"theme_label": THEMES[pack["theme"]]["label"],
|
|
747
|
+
# 主题字典随计划一起返回:scenes.py 的 _scene_theme 优先用它(含 theme_overrides),
|
|
748
|
+
# 也方便 render.py 直接传给 draw_subtitle/write_ass,不必再按 id 查一次。
|
|
749
|
+
"theme": theme,
|
|
750
|
+
"layout_default": layouts[0],
|
|
751
|
+
"chapter_layout": chap_layout,
|
|
752
|
+
"music": {
|
|
753
|
+
"style": music_style,
|
|
754
|
+
"bpm": bpm, "bpm_source": bpm_source,
|
|
755
|
+
"key": key, "key_source": key_source,
|
|
756
|
+
"mood": mood, "mood_source": mood_source,
|
|
757
|
+
"seed": int(seed), "seed_effective": int(seed_effective),
|
|
758
|
+
"seed_from_content": bool(seed_from_content),
|
|
759
|
+
},
|
|
760
|
+
"voice": {
|
|
761
|
+
"map": voice_map,
|
|
762
|
+
"default": voce.get("default"),
|
|
763
|
+
"policy": policy,
|
|
764
|
+
},
|
|
765
|
+
"pacing": pacing,
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
|
|
769
|
+
# ============================================================================
|
|
770
|
+
# 七、门禁:主题体检(对比度 / 明暗 / 结构)
|
|
771
|
+
# ============================================================================
|
|
772
|
+
#
|
|
773
|
+
# 阈值不是拍脑袋:以 v0.4 现行主题实测值当基线(ink 16.3 / muted 7.8 / accent 7.0)。
|
|
774
|
+
|
|
775
|
+
LINT_LIMITS = {
|
|
776
|
+
"ink": 7.0, # 正文级(WCAG AAA 正文线)
|
|
777
|
+
"muted": 4.5, # 次级正文(WCAG AA)
|
|
778
|
+
"dim": 3.0, # 装饰级(HUD 小字、页脚)
|
|
779
|
+
"accent": 4.5, # 强调色常作文字
|
|
780
|
+
"accent2": 4.5, # 第二色相也常作文字
|
|
781
|
+
"good": 3.0, # 只承载图形(圆点靠位置+颜色双编码)
|
|
782
|
+
"bad": 3.0,
|
|
783
|
+
"lum_gap": 0.002, # bg 与 bg2 的亮度差(防纯色底)
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
def theme_lint(th):
|
|
788
|
+
"""主题体检,返回问题列表(空 = 过)。坏主题在 load 阶段就拦,别等渲完 300 帧。"""
|
|
789
|
+
if not isinstance(th, dict):
|
|
790
|
+
return ["主题不是 dict:%r" % (th,)]
|
|
791
|
+
bad = []
|
|
792
|
+
bgs = midpoint(th["bg"], th["bg2"])
|
|
793
|
+
for role, need in (("ink", LINT_LIMITS["ink"]), ("muted", LINT_LIMITS["muted"]),
|
|
794
|
+
("dim", LINT_LIMITS["dim"]), ("accent", LINT_LIMITS["accent"]),
|
|
795
|
+
("accent2", LINT_LIMITS["accent2"])):
|
|
796
|
+
got = contrast(th[role], bgs)
|
|
797
|
+
if got < need:
|
|
798
|
+
bad.append("%s 对背景对比度 %.2f < %.1f" % (role, got, need))
|
|
799
|
+
for role in ("good", "bad"):
|
|
800
|
+
got = contrast(th[role], th["surface"])
|
|
801
|
+
if got < LINT_LIMITS[role]:
|
|
802
|
+
bad.append("%s 对卡片底色对比度 %.2f < %.1f" % (role, got, LINT_LIMITS[role]))
|
|
803
|
+
gap = abs(luminance(th["bg"]) - luminance(th["bg2"]))
|
|
804
|
+
if gap < LINT_LIMITS["lum_gap"]:
|
|
805
|
+
bad.append("bg/bg2 亮度差 %.4f 太小(会像纯色底)" % gap)
|
|
806
|
+
if luminance(th["bg"]) < 0.02 and float(th.get("qa", {}).get("luma_max", 0.045)) > 0.03:
|
|
807
|
+
bad.append("暗色主题 bg 亮度 %.3f 贴空窗阈值,请把 qa.luma_max 降到 0.03 以下"
|
|
808
|
+
% luminance(th["bg"]))
|
|
809
|
+
if th.get("layout") not in LAYOUTS:
|
|
810
|
+
bad.append("layout=%r 不在 LAYOUTS 里" % th.get("layout"))
|
|
811
|
+
if th.get("hud") not in ("chip-left", "corner-line", "none"):
|
|
812
|
+
bad.append("hud=%r 不认识" % th.get("hud"))
|
|
813
|
+
if not isinstance(th.get("item_stagger"), (int, float)) or th["item_stagger"] <= 0:
|
|
814
|
+
bad.append("item_stagger 必须是正数")
|
|
815
|
+
return bad
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
def lint_all():
|
|
819
|
+
"""全部内置主题体检,返回 {style_id: [问题...]}(只有有问题的才在里面)。"""
|
|
820
|
+
out = {}
|
|
821
|
+
for sid in STYLE_IDS:
|
|
822
|
+
bad = theme_lint(THEMES[STYLES[sid]["theme"]])
|
|
823
|
+
if bad:
|
|
824
|
+
out[sid] = bad
|
|
825
|
+
return out
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
# ============================================================================
|
|
829
|
+
# 八、片内一致性:明暗族判定(段界不许跨族,否则必触发闪烁门禁)
|
|
830
|
+
# ============================================================================
|
|
831
|
+
|
|
832
|
+
|
|
833
|
+
def is_dark(th):
|
|
834
|
+
return luminance(th["bg"]) < 0.35
|
|
835
|
+
|
|
836
|
+
|
|
837
|
+
def family_compatible(a, b):
|
|
838
|
+
"""两主题能否出现在同一部片里(同明暗族)。跨族=两部片,不是两段。"""
|
|
839
|
+
return is_dark(a) == is_dark(b)
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
def blend_theme(a, b, p):
|
|
843
|
+
"""按 p in [0,1] 线性插值两套主题(同族时用于段界缓变,避免整片换底触发闪烁门禁)。"""
|
|
844
|
+
if not family_compatible(a, b):
|
|
845
|
+
raise ValueError("不能混合明暗族不同的主题:%s / %s" % (a.get("id"), b.get("id")))
|
|
846
|
+
q = max(0.0, min(1.0, float(p)))
|
|
847
|
+
out = dict(a)
|
|
848
|
+
for k, va in a.items():
|
|
849
|
+
vb = b.get(k, va)
|
|
850
|
+
if isinstance(va, tuple) and len(va) == 3 and isinstance(vb, tuple) and len(vb) == 3:
|
|
851
|
+
out[k] = tuple(int(round(va[i] * (1 - q) + vb[i] * q)) for i in range(3))
|
|
852
|
+
elif (isinstance(va, (int, float)) and not isinstance(va, bool)
|
|
853
|
+
and isinstance(vb, (int, float))):
|
|
854
|
+
out[k] = type(va)(round(va * (1 - q) + vb * q, 4))
|
|
855
|
+
return out
|
|
856
|
+
|
|
857
|
+
|
|
858
|
+
# ============================================================================
|
|
859
|
+
# 九、CLI:看风格、看主题、跑门禁
|
|
860
|
+
# ============================================================================
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
def _describe(sid):
|
|
864
|
+
pack = STYLES[sid]
|
|
865
|
+
th = THEMES[pack["theme"]]
|
|
866
|
+
bgs = midpoint(th["bg"], th["bg2"])
|
|
867
|
+
lines = [
|
|
868
|
+
"[%s] %s (theme=%s / layouts=%s)" % (sid, pack["name"], pack["theme"],
|
|
869
|
+
",".join(pack["layouts"])),
|
|
870
|
+
" tags : %s" % "、".join(pack["tags"]),
|
|
871
|
+
" keywords : %s" % "、".join(th["keywords"]),
|
|
872
|
+
" music : %s 调池=%s BPM 梯度=%s mood=%s"
|
|
873
|
+
% (pack["music"]["scale"], ",".join(pack["music"]["keys"]),
|
|
874
|
+
",".join(str(b) for b in pack["music"]["bpm_ladder"]), pack["music"]["mood"]),
|
|
875
|
+
" voice : %s" % ", ".join("%s=%s" % (k, v) for k, v in pack["voice"].items() if v),
|
|
876
|
+
" pacing : lead=%.2f tail=%.2f min_dur=%.1f"
|
|
877
|
+
% (pack["pacing"]["lead"], pack["pacing"]["tail"], pack["pacing"]["min_dur"]),
|
|
878
|
+
" palette : bg=%s bg2=%s ink=%s accent=%s"
|
|
879
|
+
% (th["bg"], th["bg2"], th["ink"], th["accent"]),
|
|
880
|
+
" contrast : ink %.2f / muted %.2f / dim %.2f / accent %.2f"
|
|
881
|
+
% (contrast(th["ink"], bgs), contrast(th["muted"], bgs),
|
|
882
|
+
contrast(th["dim"], bgs), contrast(th["accent"], bgs)),
|
|
883
|
+
" font : family=%s display=%spx hud=%s"
|
|
884
|
+
% (th["family"], th["scale"]["display"][0], th["hud"]),
|
|
885
|
+
]
|
|
886
|
+
bad = theme_lint(th)
|
|
887
|
+
lines.append(" lint : %s" % ("PASS" if not bad else "FAIL -> " + ";".join(bad)))
|
|
888
|
+
return "\n".join(lines)
|
|
889
|
+
|
|
890
|
+
|
|
891
|
+
def main(argv=None):
|
|
892
|
+
ap = argparse.ArgumentParser(description="风格包:列出 / 查看 / 体检")
|
|
893
|
+
ap.add_argument("--list", action="store_true", help="列出所有风格")
|
|
894
|
+
ap.add_argument("--show", metavar="ID", help="查看某个风格的完整字段")
|
|
895
|
+
ap.add_argument("--lint", action="store_true", help="全部内置主题走对比度门禁")
|
|
896
|
+
ap.add_argument("--json", action="store_true", help="配合 --show 输出 JSON")
|
|
897
|
+
a = ap.parse_args(argv)
|
|
898
|
+
try:
|
|
899
|
+
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
900
|
+
except Exception: # noqa: BLE001
|
|
901
|
+
pass
|
|
902
|
+
if a.show:
|
|
903
|
+
if a.json:
|
|
904
|
+
import json
|
|
905
|
+
print(json.dumps({"style": STYLES[a.show],
|
|
906
|
+
"theme": THEMES[STYLES[a.show]["theme"]]},
|
|
907
|
+
ensure_ascii=False, indent=1, default=str))
|
|
908
|
+
else:
|
|
909
|
+
print(_describe(a.show))
|
|
910
|
+
return 0
|
|
911
|
+
if a.lint:
|
|
912
|
+
bad = lint_all()
|
|
913
|
+
for sid in STYLE_IDS:
|
|
914
|
+
print(("FAIL " if sid in bad else "PASS ") + sid
|
|
915
|
+
+ ("" if sid not in bad else " " + ";".join(bad[sid])))
|
|
916
|
+
return 1 if bad else 0
|
|
917
|
+
for sid in ALL_STYLE_IDS:
|
|
918
|
+
print(_describe(sid))
|
|
919
|
+
print("")
|
|
920
|
+
return 0
|
|
921
|
+
|
|
922
|
+
|
|
923
|
+
if __name__ == "__main__":
|
|
924
|
+
sys.exit(main())
|