seoanything-cli 2.3.0 → 2.4.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 +17 -1
- package/dist/tools.mjs +114 -4
- package/package.json +1 -1
- package/src/cli.js +137 -10
- package/src/cli.test.js +113 -1
- package/src/connect.js +219 -7
- package/src/connect.test.js +176 -2
- package/src/film/scene_auto.py +520 -0
- package/src/mcp.js +1 -1
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
"""Generic scene for any script.json, written by `seoanything connect --video` as scene.py.
|
|
2
|
+
|
|
3
|
+
Each narration line gets one hero, sized to fill the frame above the caption band at the camera zoom
|
|
4
|
+
used for it: BigText for the opening title, section openers and the end line; Counters for typed key
|
|
5
|
+
numbers ("RS 1,000", "MAX 5"); step cards for "1 OPEN · 2 PAY"; otherwise a Card (title and a short
|
|
6
|
+
body), with a Counter under or beside it when the line itself has a key number ("11 points"). On 9:16
|
|
7
|
+
the parts of a hero stack vertically. Heroes run in rows that snake over the board, so every Route
|
|
8
|
+
joins two neighbours across an empty gap and no neighbour sits in the caption band. The camera lands
|
|
9
|
+
on each hero just after it appears, zoomed so it fills the frame above the captions, pushes in gently
|
|
10
|
+
and ends on a composed pull-back over the whole board.
|
|
11
|
+
The look and frame size come from film.json next to this file: {"look": "night", "size": "1080x1920"}.
|
|
12
|
+
All type is measured with the engine's fonts (doc.res()), wrapped at word breaks and shrunk to fit.
|
|
13
|
+
"""
|
|
14
|
+
import json
|
|
15
|
+
import math
|
|
16
|
+
import re
|
|
17
|
+
|
|
18
|
+
from engine import HILITE, INK, LOOKS, MUSTARD, RUST, WHITE, BigText, Card, Counter, Film, PenMark, Route, draw_text, ease_out_back, ramp, text_width
|
|
19
|
+
|
|
20
|
+
LIGHT = {"studio", "paper"}
|
|
21
|
+
ACCENT = {"wall": MUSTARD, "slate": HILITE, "charcoal": HILITE, "paper": RUST, "studio": (198, 92, 46), "blueprint": HILITE, "night": HILITE}
|
|
22
|
+
FW = 3840.0 # frame width in world px at zoom 1, both orientations
|
|
23
|
+
Z_PUSH, ZOOM_MAX = 1.05, 1.8 # push-in over a line; the closest a hero shot gets
|
|
24
|
+
LIFT = 0.11 # camera sits this share of frame height below the hero: captions own the bottom 26%
|
|
25
|
+
SAFE_W, SAFE_H = 0.82, 0.60 # hero box as a share of the frame (still fits after the push-in, 5% margins)
|
|
26
|
+
CARD_BG = (250, 248, 244)
|
|
27
|
+
CARD_INK = (34, 32, 30)
|
|
28
|
+
MONTHS = {m[:3] for m in "january february march april may june july august september october november december".split()}
|
|
29
|
+
DAYS = {d[:3] for d in "monday tuesday wednesday thursday friday saturday sunday".split()}
|
|
30
|
+
IDS = {"qualifier", "season", "round", "step", "part", "phase", "level", "game", "match", "week", "day", "no", "number",
|
|
31
|
+
"chapter", "version", "v", "episode", "vol", "volume", "group", "stage", "test", "gen", "ios", "android", "page"}
|
|
32
|
+
CURRENCY = {"rs", "rs.", "npr", "inr", "usd", "us$", "$", "€", "£", "¥", "eur", "gbp"}
|
|
33
|
+
BREAKS = {"for", "to", "and", "but", "so", "with", "at", "in", "on", "from", "by", "because", "when", "while", "then", "into", "of", "that", "which"}
|
|
34
|
+
ONES = "zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split()
|
|
35
|
+
TENS = "_ _ twenty thirty forty fifty sixty seventy eighty ninety".split()
|
|
36
|
+
NUM = re.compile(r"\d{1,3}(?:,\d{3})+|\d+")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Panel(Card):
|
|
40
|
+
"""A Card whose text the scene lays out: rows of (text, dx, baseline dy, size, font, rgb) from the centre."""
|
|
41
|
+
|
|
42
|
+
def __init__(self, x, y, w, h, t_in, rows, **kw):
|
|
43
|
+
super().__init__(x, y, w, h, t_in, **kw)
|
|
44
|
+
self.rows = rows
|
|
45
|
+
|
|
46
|
+
def draw(self, c, res, t):
|
|
47
|
+
super().draw(c, res, t)
|
|
48
|
+
a = ramp(t, self.t_in, 0.15) * self.fade(t)
|
|
49
|
+
if a <= 0:
|
|
50
|
+
return
|
|
51
|
+
u = ease_out_back(ramp(t, self.t_in, 0.45), 1.2)
|
|
52
|
+
s = 0.92 + 0.08 * u
|
|
53
|
+
c.save(); c.translate(self.x, self.y + (1 - u) * 120); c.rotate(self.rot); c.scale(s, s)
|
|
54
|
+
for k, (txt, dx, dy, size, font, rgb) in enumerate(self.rows):
|
|
55
|
+
draw_text(c, res, txt, dx, dy, size, font, rgb, a * ramp(t, self.t_in + 0.15 + 0.08 * k, 0.3), 0.0)
|
|
56
|
+
c.restore()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def settings(doc):
|
|
60
|
+
try:
|
|
61
|
+
f = json.loads((doc.dir / "film.json").read_text())
|
|
62
|
+
except (OSError, ValueError):
|
|
63
|
+
f = {}
|
|
64
|
+
look = f.get("look") if f.get("look") in LOOKS else "night"
|
|
65
|
+
try:
|
|
66
|
+
w, h = (int(v) for v in str(f.get("size", "1920x1080")).lower().split("x"))
|
|
67
|
+
except ValueError:
|
|
68
|
+
w, h = 1920, 1080
|
|
69
|
+
return look, h / w
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# ---------------------------------------------------------------- type that fits
|
|
73
|
+
def balanced(res, words, n, font, track):
|
|
74
|
+
"""words split into n lines whose widest line is as narrow as possible (widths at size 100)."""
|
|
75
|
+
m = len(words)
|
|
76
|
+
memo = {}
|
|
77
|
+
|
|
78
|
+
def wd(i, j):
|
|
79
|
+
if (i, j) not in memo:
|
|
80
|
+
memo[(i, j)] = text_width(res, " ".join(words[i:j]), 100, font, track)
|
|
81
|
+
return memo[(i, j)]
|
|
82
|
+
best = {(0, 0): (0.0, [])}
|
|
83
|
+
for k in range(1, n + 1):
|
|
84
|
+
for j in range(k, m - (n - k) + 1):
|
|
85
|
+
cand = None
|
|
86
|
+
for i in range(k - 1, j):
|
|
87
|
+
prev = best.get((k - 1, i))
|
|
88
|
+
if prev is not None:
|
|
89
|
+
c = max(prev[0], wd(i, j))
|
|
90
|
+
if cand is None or c < cand[0]:
|
|
91
|
+
cand = (c, prev[1] + [(i, j)])
|
|
92
|
+
if cand:
|
|
93
|
+
best[(k, j)] = cand
|
|
94
|
+
return [" ".join(words[i:j]) for i, j in best[(n, m)][1]]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def fit_rows(res, text, font, track, width, smax, smin, max_lines):
|
|
98
|
+
"""(size, rows): the largest size up to smax at which text fits width in at most max_lines rows.
|
|
99
|
+
Breaks only between words (a ' · ' break is preferred); a single long word shrinks the type instead.
|
|
100
|
+
Far below smin even at max_lines, trailing words give way to an ellipsis."""
|
|
101
|
+
words = text.split()
|
|
102
|
+
if not words:
|
|
103
|
+
return smax, []
|
|
104
|
+
|
|
105
|
+
def size_of(rows):
|
|
106
|
+
return min(smax, 100 * width / max(1.0, max(text_width(res, r, 100, font, track) for r in rows)))
|
|
107
|
+
best = None
|
|
108
|
+
for n in range(1, min(max_lines, len(words)) + 1):
|
|
109
|
+
rows = [r.strip(" ·|") or r for r in balanced(res, words, n, font, track)]
|
|
110
|
+
if n > 1 and any(len(r) <= 2 for r in rows): # no orphan "2" or "v" on a row of its own
|
|
111
|
+
continue
|
|
112
|
+
s = size_of(rows)
|
|
113
|
+
if best is None or s > best[0] * 1.08:
|
|
114
|
+
best = (s, rows)
|
|
115
|
+
if s >= smax:
|
|
116
|
+
break
|
|
117
|
+
parts = [p.strip() for p in re.split(r"\s+[·|]\s+", text) if p.strip()]
|
|
118
|
+
if 1 < len(parts) <= max_lines and size_of(parts) >= best[0] * 0.85:
|
|
119
|
+
best = (size_of(parts), parts)
|
|
120
|
+
if best[0] < smin * 0.7 and len(words) > 3: # shrink first; only far too long text loses its last words
|
|
121
|
+
cut = fit_rows(res, " ".join(words[:-1]).rstrip(" ,;:.·|") + "…", font, track, width, smax, smin, max_lines)
|
|
122
|
+
if cut[0] > best[0]:
|
|
123
|
+
return cut
|
|
124
|
+
return best
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def body_rows(res, text, size, width, max_lines):
|
|
128
|
+
"""Greedy word wrap at a fixed size; past max_lines the last row ends in an ellipsis at a word break."""
|
|
129
|
+
rows = []
|
|
130
|
+
for w in text.split():
|
|
131
|
+
if rows and text_width(res, f"{rows[-1]} {w}", size, "labelm") <= width:
|
|
132
|
+
rows[-1] += f" {w}"
|
|
133
|
+
else:
|
|
134
|
+
rows.append(w)
|
|
135
|
+
if len(rows) > max_lines:
|
|
136
|
+
rows = rows[:max_lines]
|
|
137
|
+
words = rows[-1].split()
|
|
138
|
+
while len(words) > 1 and text_width(res, " ".join(words).rstrip(",;:.") + "…", size, "labelm") > width:
|
|
139
|
+
words.pop()
|
|
140
|
+
rows[-1] = " ".join(words).rstrip(",;:.") + "…"
|
|
141
|
+
return rows
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
# ---------------------------------------------------------------- numbers and spoken words
|
|
145
|
+
def spoken_first(v):
|
|
146
|
+
"""First spoken word of a number (1,000 -> 'one', 32 -> 'thirty'): where its hit lands."""
|
|
147
|
+
while v >= 1000:
|
|
148
|
+
v //= 1000
|
|
149
|
+
if v >= 100:
|
|
150
|
+
v //= 100
|
|
151
|
+
return ONES[v] if v < 20 else TENS[v // 10]
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def key_number(text, need_unit=False):
|
|
155
|
+
"""(kicker, prefix, value, suffix, caption) for the main count or price in text, or None.
|
|
156
|
+
Skips years, dates ('17 NOV', 'TUE 17'), times ('5 PM', '5:00'), decimals and ids ('QUALIFIER 1')."""
|
|
157
|
+
for m in NUM.finditer(text):
|
|
158
|
+
g, a, b = m.group(), m.start(), m.end()
|
|
159
|
+
v = int(g.replace(",", ""))
|
|
160
|
+
if (a and text[a - 1] in ".:/-") or text[b:b + 1] in (".", ":", "/") and text[b + 1:b + 2].isdigit():
|
|
161
|
+
continue
|
|
162
|
+
if (g.startswith("0") and len(g) > 1) or (1900 <= v <= 2100 and "," not in g):
|
|
163
|
+
continue
|
|
164
|
+
before, after = text[:a].split(), text[b:].split()
|
|
165
|
+
prev = re.sub(r"[^\w$€£¥.]", "", before[-1]).lower() if before else ""
|
|
166
|
+
nxt = re.sub(r"[^\w%+]", "", after[0]).lower() if after else ""
|
|
167
|
+
if prev[:3] in MONTHS or prev[:3] in DAYS or nxt[:3] in MONTHS or nxt in ("am", "pm", "a", "p") or prev in IDS:
|
|
168
|
+
continue
|
|
169
|
+
prefix = ""
|
|
170
|
+
if text[a - 1:a] in "$€£¥" and a:
|
|
171
|
+
prefix = text[a - 1]
|
|
172
|
+
before[-1] = before[-1][:-1]
|
|
173
|
+
elif prev in CURRENCY:
|
|
174
|
+
prefix = before.pop().upper().rstrip(".") + " "
|
|
175
|
+
suffix = "%" if text[b:b + 1] == "%" else "+" if text[b:b + 1] == "+" else ""
|
|
176
|
+
if suffix:
|
|
177
|
+
after = [after[0][1:]] + after[1:] if after and after[0][0] in "%+" else after
|
|
178
|
+
caption = " ".join(after).strip(" ,;:.")
|
|
179
|
+
if need_unit:
|
|
180
|
+
if not prefix and not suffix and not (after and re.match(r"^[a-zA-Z]{3,}", after[0])):
|
|
181
|
+
continue
|
|
182
|
+
caption = re.sub(r"[^\w]", "", after[0]).upper() if after and re.match(r"^[a-zA-Z]{3,}", after[0]) else ""
|
|
183
|
+
return "", prefix, v, suffix, caption
|
|
184
|
+
return " ".join(w for w in before if w).strip(" ,;:."), prefix, v, suffix, caption
|
|
185
|
+
return None
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def steps_of(typed):
|
|
189
|
+
"""[(n, label)] when typed reads '1 OPEN · 2 MATCH · 3 PAY', else None."""
|
|
190
|
+
parts = [p.strip() for p in re.split(r"\s*[·|]\s*", typed) if p.strip()]
|
|
191
|
+
out = []
|
|
192
|
+
for k, p in enumerate(parts):
|
|
193
|
+
m = re.match(r"^(\d+)[.)]?\s+(.+)$", p)
|
|
194
|
+
if not m or int(m.group(1)) != k + 1:
|
|
195
|
+
return None
|
|
196
|
+
out.append((k + 1, m.group(2)))
|
|
197
|
+
return out if 2 <= len(out) <= 6 else None
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def word_time(doc, i, word):
|
|
201
|
+
"""doc.W for a whole word of line i's spoken text, or None when it is not said."""
|
|
202
|
+
vo = doc.seg[i]["vo"]
|
|
203
|
+
m = re.search(rf"\b{re.escape(word)}\b", vo, re.I)
|
|
204
|
+
if not m:
|
|
205
|
+
return None
|
|
206
|
+
return doc.W(i, word, vo.lower().count(word.lower(), 0, m.start()))
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def said(doc, i, text):
|
|
210
|
+
"""(word, time) for the longest word of text that line i says, else None."""
|
|
211
|
+
# dict.fromkeys keeps text order, so ties pick the same word in every render process (a set's order changes per hash seed)
|
|
212
|
+
for w in sorted(dict.fromkeys(re.findall(r"\b[A-Za-z][A-Za-z'’]{2,}\b", text)), key=len, reverse=True):
|
|
213
|
+
t = word_time(doc, i, w)
|
|
214
|
+
if t is not None:
|
|
215
|
+
return w, t
|
|
216
|
+
return None
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def title_body(text):
|
|
220
|
+
"""A card title and body from a narration line: the first clause, or the first words up to a natural break."""
|
|
221
|
+
text = text.strip()
|
|
222
|
+
m = re.match(r"^(.{12,}?)[,:;.?!]\s+(.+)$", text)
|
|
223
|
+
title, body = (m.group(1), m.group(2)) if m else (text.rstrip("."), "")
|
|
224
|
+
words = title.split()
|
|
225
|
+
if len(words) > 9:
|
|
226
|
+
cut = max((k for k in range(3, 9) if words[k].lower() in BREAKS), default=7)
|
|
227
|
+
title, body = " ".join(words[:cut]), " ".join(words[cut:]) + (f" {body}" if body else "")
|
|
228
|
+
return title.rstrip(" ,;:."), body.strip()
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
# ---------------------------------------------------------------- the board
|
|
232
|
+
def build_film(doc):
|
|
233
|
+
L, E = doc.L, doc.E
|
|
234
|
+
res = doc.res()
|
|
235
|
+
look, aspect = settings(doc)
|
|
236
|
+
light = look in LIGHT
|
|
237
|
+
accent = ACCENT[look]
|
|
238
|
+
ink = INK if light else WHITE
|
|
239
|
+
tall = aspect > 1
|
|
240
|
+
FH = FW * aspect
|
|
241
|
+
CW, HC = FW * SAFE_W, FH * SAFE_H
|
|
242
|
+
# type sizes at zoom 1 as shares of frame height; the camera then zooms each hero to fill the frame, until
|
|
243
|
+
# its largest type reaches `cap` of frame height (an em of 12% is a cap height of about 9% on 9:16)
|
|
244
|
+
S = dict(title=(0.085, 0.05), card=(0.072, 0.048), body=0.036, num=0.17, num2=0.11, label=0.034, cap=0.12) if tall else \
|
|
245
|
+
dict(title=(0.17, 0.09), card=(0.115, 0.075), body=0.062, num=0.40, num2=0.32, label=0.07, cap=0.2)
|
|
246
|
+
S = {k: tuple(f * FH for f in v) if isinstance(v, tuple) else v * FH for k, v in S.items()}
|
|
247
|
+
film = Film(doc.duration, fps=30, look=look)
|
|
248
|
+
script = json.loads((doc.dir / "script.json").read_text())
|
|
249
|
+
takes = [[ln for ln in take["lines"] if ln["id"] in doc.seg] for take in script["takes"]]
|
|
250
|
+
takes = [t for t in takes if t]
|
|
251
|
+
if not takes:
|
|
252
|
+
raise SystemExit("script.json has no lines with a voice")
|
|
253
|
+
flat = [(ln, j == 0 and k > 0) for k, take in enumerate(takes) for j, ln in enumerate(take)]
|
|
254
|
+
pens = [0]
|
|
255
|
+
|
|
256
|
+
def board_type(text, x, base, size, t, track=0.04, grunge=True):
|
|
257
|
+
film.add(BigText(text, x, base, size, t, rgb=ink, track=track, type_on=0.4 if grunge else 0.0,
|
|
258
|
+
shadow=not light, grunge=grunge and not light))
|
|
259
|
+
|
|
260
|
+
# every builder returns (width, height, place(x, y), largest type size) for a hero centred on (x, y)
|
|
261
|
+
def label_rows(text, width, t):
|
|
262
|
+
"""A small condensed label (kicker or caption) on the board."""
|
|
263
|
+
s, rows = fit_rows(res, text.upper(), "cond", 0.16, width, S["label"], S["label"] * 0.6, 2)
|
|
264
|
+
lh = s * 1.12
|
|
265
|
+
|
|
266
|
+
def place(x, top):
|
|
267
|
+
for r, row in enumerate(rows):
|
|
268
|
+
board_type(row, x, top + 0.78 * s + r * lh, s, t + 0.1 * r, track=0.1, grunge=False)
|
|
269
|
+
w = max((text_width(res, r, s, "cond", 0.16) for r in rows), default=0.0)
|
|
270
|
+
return w, ((len(rows) - 1) * lh + 0.85 * s) if rows else 0.0, place
|
|
271
|
+
|
|
272
|
+
def title_hero(i, text, t):
|
|
273
|
+
s, rows = fit_rows(res, text, "cond", 0.07, CW, *S["title"], 5 if tall else 3)
|
|
274
|
+
lh = s * 1.08
|
|
275
|
+
h = (len(rows) - 1) * lh + 0.8 * s
|
|
276
|
+
w = max(text_width(res, r, s, "cond", 0.07) for r in rows)
|
|
277
|
+
hit = said(doc, i, text)
|
|
278
|
+
|
|
279
|
+
def place(x, y):
|
|
280
|
+
top, marked = y - h / 2, False
|
|
281
|
+
for r, row in enumerate(rows):
|
|
282
|
+
base = top + 0.76 * s + r * lh
|
|
283
|
+
board_type(row, x, base, s, t + 0.15 * r)
|
|
284
|
+
m = hit and not marked and re.search(rf"\b{re.escape(hit[0])}\b", row)
|
|
285
|
+
if m:
|
|
286
|
+
x0 = x - text_width(res, row, s, "cond", 0.04) / 2
|
|
287
|
+
ww = text_width(res, hit[0], s, "cond", 0.04)
|
|
288
|
+
ux = x0 + (text_width(res, row[:m.start()], s, "cond", 0.04) + 0.04 * s if m.start() else 0) + ww / 2
|
|
289
|
+
film.add(PenMark("underline", ux, base + 0.13 * s, ww * 1.06, 0.1 * s, t_in=max(hit[1] - 0.1, t + 0.6),
|
|
290
|
+
dur=0.45, width=max(10, 0.06 * s), rgb=accent))
|
|
291
|
+
marked = True
|
|
292
|
+
return w, h, place, s
|
|
293
|
+
|
|
294
|
+
def counter_block(i, num, maxw, smax, t):
|
|
295
|
+
kicker, prefix, value, suffix, caption = num
|
|
296
|
+
shown = f"{prefix}{value:,}{suffix}"
|
|
297
|
+
s = min(smax, 100 * maxw / text_width(res, shown, 100, "cond", 0.03))
|
|
298
|
+
kw, kh, kplace = label_rows(kicker, maxw, t) if kicker else (0.0, 0.0, None)
|
|
299
|
+
cw, ch, cplace = label_rows(caption, maxw, t + 0.3) if caption else (0.0, 0.0, None)
|
|
300
|
+
gap = 0.12 * s
|
|
301
|
+
h = kh + (gap if kh else 0) + 0.76 * s + (gap if ch else 0) + ch
|
|
302
|
+
w = max(text_width(res, shown, s, "cond", 0.03), kw, cw)
|
|
303
|
+
tn = word_time(doc, i, spoken_first(value)) or word_time(doc, i, str(value)) or t + 0.4
|
|
304
|
+
|
|
305
|
+
def place(x, y):
|
|
306
|
+
top = y - h / 2
|
|
307
|
+
if kplace:
|
|
308
|
+
kplace(x, top)
|
|
309
|
+
top += kh + gap
|
|
310
|
+
film.add(Counter(x, top + 0.74 * s, s, value, max(t, tn - 0.1), dur=0.9, prefix=prefix, suffix=suffix, rgb=accent))
|
|
311
|
+
if cplace:
|
|
312
|
+
cplace(x, top + 0.76 * s + gap)
|
|
313
|
+
return w, h, place, s * 0.45 # a number may stand about twice as tall as title type
|
|
314
|
+
|
|
315
|
+
def stack(parts, gap, across):
|
|
316
|
+
"""Parts (w, h, place, big) in a column, or side by side when across: one composed hero."""
|
|
317
|
+
if across:
|
|
318
|
+
w, h = sum(p[0] for p in parts) + gap * (len(parts) - 1), max(p[1] for p in parts)
|
|
319
|
+
else:
|
|
320
|
+
w, h = max(p[0] for p in parts), sum(p[1] for p in parts) + gap * (len(parts) - 1)
|
|
321
|
+
|
|
322
|
+
def place(x, y):
|
|
323
|
+
u = (x - w / 2) if across else (y - h / 2)
|
|
324
|
+
for pw, ph, pp, _ in parts:
|
|
325
|
+
pp(u + pw / 2, y) if across else pp(x, u + ph / 2)
|
|
326
|
+
u += (pw if across else ph) + gap
|
|
327
|
+
return w, h, place, max(p[3] for p in parts)
|
|
328
|
+
|
|
329
|
+
def counters_hero(i, nums, t):
|
|
330
|
+
n = len(nums)
|
|
331
|
+
smax = S["num"] if n == 1 else S["num2"]
|
|
332
|
+
gap = 0.05 * FH if tall else 0.06 * FW
|
|
333
|
+
maxw = CW if tall else (CW - gap * (n - 1)) / n
|
|
334
|
+
blocks = [counter_block(i, nm, maxw, smax, t) for nm in nums]
|
|
335
|
+
hero = stack(blocks, gap, not tall)
|
|
336
|
+
if hero[1] > HC: # too tall: shrink the numbers once
|
|
337
|
+
blocks = [counter_block(i, nm, maxw, smax * HC / hero[1] * 0.95, t) for nm in nums]
|
|
338
|
+
hero = stack(blocks, gap, not tall)
|
|
339
|
+
return hero
|
|
340
|
+
|
|
341
|
+
def panel(i, title, body, w, t, ts_range=None, pen=False, max_title=4, shrink=True, max_body=3):
|
|
342
|
+
"""A card: title rows and body rows (narration past max_body ends in an ellipsis); narrower than w when its text is short."""
|
|
343
|
+
padx = 0.09 * w
|
|
344
|
+
inner = w - 2 * padx
|
|
345
|
+
ts, trows = fit_rows(res, title, "label", 0.0, inner, *(ts_range or S["card"]), max_title)
|
|
346
|
+
bs = min(S["body"], ts * 0.7)
|
|
347
|
+
if body:
|
|
348
|
+
longest = max(text_width(res, wd, bs, "labelm") for wd in body.split())
|
|
349
|
+
bs = min(bs, bs * inner / longest) # one very long word shrinks the body, never splits
|
|
350
|
+
brows = body_rows(res, body, bs, inner, max_body) if body else []
|
|
351
|
+
if not trows and not brows:
|
|
352
|
+
trows = [" "] # a line of only punctuation: an empty card, never a crash
|
|
353
|
+
if shrink:
|
|
354
|
+
need = max([text_width(res, r, ts, "label") for r in trows] + [text_width(res, r, bs, "labelm") for r in brows])
|
|
355
|
+
w = max(w * 0.5, min(w, need + 2 * padx))
|
|
356
|
+
pad = max(0.6 * ts, 0.05 * w)
|
|
357
|
+
rows, y = [], pad + 0.8 * ts
|
|
358
|
+
for r in trows:
|
|
359
|
+
rows.append((r, -w / 2 + padx, y, ts, "label", CARD_INK))
|
|
360
|
+
y += 1.14 * ts
|
|
361
|
+
y += -1.14 * ts + (0.5 * ts + 1.15 * bs if brows else 0)
|
|
362
|
+
for r in brows:
|
|
363
|
+
rows.append((r, -w / 2 + padx, y, bs, "labelm", CARD_INK))
|
|
364
|
+
y += 1.42 * bs
|
|
365
|
+
h = y - (1.42 * bs if brows else 0) + 0.28 * (bs if brows else ts) + pad
|
|
366
|
+
rows = [(r, dx, dy - h / 2, s, f, c) for r, dx, dy, s, f, c in rows]
|
|
367
|
+
hit = said(doc, i, trows[0]) if pen and trows else None
|
|
368
|
+
|
|
369
|
+
def place(x, y):
|
|
370
|
+
film.add(Panel(x, y, w, h, t, rows, accent=accent, rgb=(255, 255, 255) if light else CARD_BG))
|
|
371
|
+
if hit:
|
|
372
|
+
row = rows[0][0]
|
|
373
|
+
m = re.search(rf"\b{re.escape(hit[0])}\b", row)
|
|
374
|
+
a = m.start() if m else 0
|
|
375
|
+
ww = text_width(res, hit[0], ts, "label")
|
|
376
|
+
ux = x + rows[0][1] + (text_width(res, row[:a], ts, "label") if a else 0) + ww / 2
|
|
377
|
+
film.add(PenMark("underline", ux, y + rows[0][2] + 0.16 * ts, ww * 1.06, 0.1 * ts, t_in=max(hit[1] - 0.1, t + 0.6),
|
|
378
|
+
dur=0.45, width=max(9, 0.07 * ts), rgb=accent, z=60))
|
|
379
|
+
return w, h, place, ts
|
|
380
|
+
|
|
381
|
+
def card_hero(i, title, body, side, t, typed_body=False):
|
|
382
|
+
pens[0] += 1
|
|
383
|
+
pen = pens[0] % 2 == 1 # the pen comes out on every other card
|
|
384
|
+
nb = 5 if typed_body else 3 # the owner's typed words are never cut
|
|
385
|
+
if not side:
|
|
386
|
+
return panel(i, title, body, CW, t, pen=pen, max_body=nb)
|
|
387
|
+
if tall:
|
|
388
|
+
card = panel(i, title, body, CW, t, pen=pen, max_body=nb)
|
|
389
|
+
gap = 0.05 * FH
|
|
390
|
+
num = counter_block(i, side, CW, S["num2"], t)
|
|
391
|
+
if card[1] + gap + num[1] > HC:
|
|
392
|
+
num = counter_block(i, side, CW, S["num2"] * max(0.4, (HC - card[1] - gap) / num[1]), t)
|
|
393
|
+
return stack([card, num], gap, False)
|
|
394
|
+
gap = 0.05 * FW
|
|
395
|
+
card = panel(i, title, body, CW * 0.62, t, pen=pen, max_body=nb)
|
|
396
|
+
return stack([card, counter_block(i, side, CW - card[0] - gap, S["num2"], t)], gap, True)
|
|
397
|
+
|
|
398
|
+
def steps_hero(i, steps, t):
|
|
399
|
+
"""One card per step, each landing on its spoken word: a column on 9:16, one or two rows on 16:9."""
|
|
400
|
+
n = len(steps)
|
|
401
|
+
cols = 1 if tall else n if n <= 3 else (n + 1) // 2
|
|
402
|
+
gap = 0.03 * FH if tall else 0.035 * FW
|
|
403
|
+
w = CW * 0.78 if tall else (CW - gap * (cols - 1)) / cols
|
|
404
|
+
cards = []
|
|
405
|
+
for k, (num, label) in enumerate(steps):
|
|
406
|
+
hit = said(doc, i, label)
|
|
407
|
+
tk = max(t + 0.15 * k, hit[1] - 0.15) if hit else t + 0.3 * k
|
|
408
|
+
cards.append(panel(i, f"{num} {label}", "", w, tk, max_title=1 if tall else 2, shrink=False))
|
|
409
|
+
rows = [stack(cards[r:r + cols], gap, True) for r in range(0, n, cols)]
|
|
410
|
+
return stack(rows, gap, False)
|
|
411
|
+
|
|
412
|
+
# one hero per line, measured before it is placed
|
|
413
|
+
heroes = []
|
|
414
|
+
for k, (ln, opener) in enumerate(flat):
|
|
415
|
+
i = ln["id"]
|
|
416
|
+
t = max(0.0, L(i) - 0.05)
|
|
417
|
+
text = str(ln.get("text") or "").strip()
|
|
418
|
+
typed = str(ln.get("typed") or "").strip() or (str(script.get("title") or "").strip() if k == 0 else "")
|
|
419
|
+
first, last = k == 0, k == len(flat) - 1
|
|
420
|
+
steps = steps_of(typed) if typed else None
|
|
421
|
+
parts = [p.strip() for p in re.split(r"\s+[·|]\s+", typed) if p.strip()]
|
|
422
|
+
nums = [key_number(p) for p in parts]
|
|
423
|
+
if any(nums) and not first: # a part without a number becomes the caption of the one with it
|
|
424
|
+
rest = " · ".join(p for p, nm in zip(parts, nums) if not nm)
|
|
425
|
+
nums = [nm if nm[0] or nm[4] or not rest else (nm[0], nm[1], nm[2], nm[3], rest) for nm in nums if nm][:3]
|
|
426
|
+
else:
|
|
427
|
+
nums = []
|
|
428
|
+
if steps:
|
|
429
|
+
hero = steps_hero(i, steps, t)
|
|
430
|
+
elif nums:
|
|
431
|
+
hero = counters_hero(i, nums, t)
|
|
432
|
+
elif typed and (first or last or opener):
|
|
433
|
+
hero = title_hero(i, typed, t)
|
|
434
|
+
else:
|
|
435
|
+
title, body = (parts[0], " · ".join(parts[1:])) if typed else title_body(text)
|
|
436
|
+
typed_body = bool(body) and bool(typed)
|
|
437
|
+
side = key_number(text, need_unit=True)
|
|
438
|
+
if typed and not body and not side:
|
|
439
|
+
body = text
|
|
440
|
+
hero = card_hero(i, title, body, side, t, typed_body)
|
|
441
|
+
w, h, place, big = hero
|
|
442
|
+
z = min(FW * SAFE_W / w, FH * SAFE_H / h, S["cap"] / big, ZOOM_MAX)
|
|
443
|
+
heroes.append(dict(id=i, w=w, h=h, place=place, z=z))
|
|
444
|
+
|
|
445
|
+
# rows that snake (left to right, then right to left), as many as make the board about the frame's shape.
|
|
446
|
+
# Neighbours sit beside each other, never above or below on the same row, so none lands in the caption band;
|
|
447
|
+
# the gaps keep them out of each other's shots
|
|
448
|
+
gap, pitch = 0.45 * FW, 0.75 * FH + 0.1 * FW
|
|
449
|
+
total = sum(h["w"] for h in heroes) + gap * (len(heroes) - 1)
|
|
450
|
+
nb = min(range(1, len(heroes) + 1), key=lambda b: abs(math.log(total / b / (b * pitch) * aspect)))
|
|
451
|
+
cum, lanes = 0.0, []
|
|
452
|
+
for hr in heroes:
|
|
453
|
+
lanes.append(min(nb - 1, lanes[-1] + 1 if lanes else 0, int((cum + hr["w"] / 2) / (total / nb))))
|
|
454
|
+
cum += hr["w"] + gap
|
|
455
|
+
prev = None
|
|
456
|
+
for hr, lane in zip(heroes, lanes):
|
|
457
|
+
d = 1 if lane % 2 == 0 else -1
|
|
458
|
+
if prev is None:
|
|
459
|
+
x = 0.0
|
|
460
|
+
elif prev["lane"] != lane:
|
|
461
|
+
x = prev["x"]
|
|
462
|
+
else:
|
|
463
|
+
x = prev["x"] + d * (prev["w"] / 2 + gap + hr["w"] / 2)
|
|
464
|
+
hr.update(lane=lane, d=d, x=x, y=lane * pitch)
|
|
465
|
+
hr["place"](hr["x"], hr["y"])
|
|
466
|
+
prev = hr
|
|
467
|
+
|
|
468
|
+
# routes between neighbours, through the empty gap only
|
|
469
|
+
line_rgb = INK if light else (252, 250, 245)
|
|
470
|
+
for a, b in zip(heroes, heroes[1:]):
|
|
471
|
+
m = 0.2 * gap # ends stay clear of the heroes, so a landed shot shows no stub
|
|
472
|
+
if a["lane"] == b["lane"]:
|
|
473
|
+
p, q = (a["x"] + a["d"] * (a["w"] / 2 + m), a["y"]), (b["x"] - a["d"] * (b["w"] / 2 + m), b["y"])
|
|
474
|
+
else:
|
|
475
|
+
p, q = (a["x"], a["y"] + a["h"] / 2 + m), (b["x"], b["y"] - b["h"] / 2 - m)
|
|
476
|
+
film.add(Route(p, q, t_in=L(b["id"]) - 0.35, dur=0.5, bend=0.08, width=20, rgb=line_rgb))
|
|
477
|
+
|
|
478
|
+
# camera: land 0.3 s after each hero appears, at the zoom that fills the frame above the captions, push in
|
|
479
|
+
# while the line plays, then pull back to the whole board
|
|
480
|
+
rolls = (-0.5, 0.4, -0.3, 0.5)
|
|
481
|
+
|
|
482
|
+
def key(t, hr, z, r):
|
|
483
|
+
film.cam(t, hr["x"], hr["y"] + LIFT * FH / z, z, r)
|
|
484
|
+
film.focus(t, hr["x"], hr["y"], math.hypot(hr["w"], hr["h"]) / 2 / 0.72 * 1.05, 0.5)
|
|
485
|
+
key(0.0, heroes[0], heroes[0]["z"] * 0.86, 0.0)
|
|
486
|
+
last_t = 0.0
|
|
487
|
+
for k, hr in enumerate(heroes):
|
|
488
|
+
i = hr["id"]
|
|
489
|
+
land = max(L(i) + 0.3, last_t + 0.2)
|
|
490
|
+
end = max(E(i), land + 0.3)
|
|
491
|
+
if k == len(heroes) - 1: # the last hero only holds briefly: the pull-back must finish before the fade
|
|
492
|
+
end = land + max(0.3, min(1.2, (E(i) - land) / 2))
|
|
493
|
+
key(land, hr, hr["z"], rolls[k % 4])
|
|
494
|
+
key(end, hr, hr["z"] * Z_PUSH, rolls[k % 4] * 0.4)
|
|
495
|
+
last_t = end
|
|
496
|
+
x0 = min(h["x"] - h["w"] / 2 for h in heroes); x1 = max(h["x"] + h["w"] / 2 for h in heroes)
|
|
497
|
+
y0 = min(h["y"] - h["h"] / 2 for h in heroes); y1 = max(h["y"] + h["h"] / 2 for h in heroes)
|
|
498
|
+
bw, bh = x1 - x0, y1 - y0
|
|
499
|
+
zfit = max(0.02, min(FW * SAFE_W / bw, FH * SAFE_H / bh, 1.0)) # the whole board above the caption band
|
|
500
|
+
cx, cy = (x0 + x1) / 2, (y0 + y1) / 2
|
|
501
|
+
film.fade_out = 1.2
|
|
502
|
+
wide = max(last_t + 1.8, E(heroes[-1]["id"]))
|
|
503
|
+
film.cam(wide, cx, cy + LIFT * FH / zfit, zfit, 0.0); film.focus(wide, cx, cy, max(bw, bh), 0.12)
|
|
504
|
+
if doc.duration > wide + 0.2:
|
|
505
|
+
z = zfit / Z_PUSH
|
|
506
|
+
film.cam(doc.duration, cx, cy + LIFT * FH / z, z, 0.0); film.focus(doc.duration, cx, cy, max(bw, bh), 0.1)
|
|
507
|
+
return film
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
if __name__ == "__main__": # self-check of the text rules: PYTHONPATH=<skill>/scripts python3 scene_auto.py
|
|
511
|
+
assert key_number("GENERAL RS 1,000") == ("GENERAL", "RS ", 1000, "", "")
|
|
512
|
+
assert key_number("MAX 5 PER ACCOUNT") == ("MAX", "", 5, "", "PER ACCOUNT")
|
|
513
|
+
assert key_number("QUALIFIER 1") is None and key_number("TUE 17 NOV") is None and key_number("5 PM") is None
|
|
514
|
+
assert key_number("SEASON 2026") is None and key_number("2.5 hours") is None
|
|
515
|
+
assert key_number("top of the table on 11 points, face", need_unit=True)[2:] == (11, "", "POINTS")
|
|
516
|
+
assert steps_of("1 OPEN · 2 MATCH · 3 ZONE") == [(1, "OPEN"), (2, "MATCH"), (3, "ZONE")] and steps_of("A · B") is None
|
|
517
|
+
assert spoken_first(1000) == "one" and spoken_first(32) == "thirty" and spoken_first(400) == "four"
|
|
518
|
+
assert title_body("No separate qualifier price was announced, so check the app first.") == \
|
|
519
|
+
("No separate qualifier price was announced", "so check the app first.")
|
|
520
|
+
print("ok")
|
package/src/mcp.js
CHANGED
|
@@ -3,7 +3,7 @@ import fs from "node:fs";
|
|
|
3
3
|
import { CliError } from "./api.js";
|
|
4
4
|
import { resolveCreds } from "./config.js";
|
|
5
5
|
|
|
6
|
-
export const VERSION = "2.
|
|
6
|
+
export const VERSION = "2.4.0";
|
|
7
7
|
|
|
8
8
|
export async function mcp(flags) {
|
|
9
9
|
const [major, minor] = process.versions.node.split(".").map(Number);
|