dsh-watch-together 0.2.6 → 0.2.7
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/CHANGELOG.md +53 -0
- package/dsh.plugin.json +12 -12
- package/examples/floating-chat/glass_window_gpu.py +6 -0
- package/examples/floating-chat/window.py +63 -2
- package/lib/client.js +74 -17
- package/package.json +115 -115
- package/src/chat-server.js +49 -11
- package/src/chat-view.js +3 -0
- package/src/index.js +9 -1
- package/src/settings/config.js +2 -0
- package/src/settings/deps.js +5 -4
- package/src/tts-interface.js +3 -1
- package/src/watch-lines.js +11 -3
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,59 @@
|
|
|
3
3
|
All notable changes to **dsh-watch-together** are documented here.
|
|
4
4
|
This package starts its own version line at `0.0.7` — it is not a continuation of `dsh-video-storyboard`.
|
|
5
5
|
|
|
6
|
+
## [0.2.7] - 2026-11-03
|
|
7
|
+
|
|
8
|
+
> 五个社区 PR 一起收(都是 @ggfgfgf-on 提的),外加录屏模式的两个真 bug。
|
|
9
|
+
|
|
10
|
+
### Fixed — 录屏/截图根本拍不到窗口
|
|
11
|
+
|
|
12
|
+
窗口一直开着 `WDA_EXCLUDEFROMCAPTURE`(防截图/直播泄露,这是对的),
|
|
13
|
+
但社区贡献者要调玻璃管线就必须能录。原来只有环境变量 `DSH_GLASS_WDA=0` 一个入口,
|
|
14
|
+
**而插件拉起窗口时不会传环境变量** —— 于是用户在 `~/.dsh/watch-window.json` 里写了
|
|
15
|
+
`"capturable": true` 也没人读,录出来永远是空桌面。
|
|
16
|
+
|
|
17
|
+
现在 `capturable()` 真的读配置:环境变量(临时)→ 配置项(持久)→ 默认排除。
|
|
18
|
+
|
|
19
|
+
### Fixed — 录屏模式下"字一直在闪"、拖尾越滚越浓
|
|
20
|
+
|
|
21
|
+
`capturable: true` 关掉 WDA 之后,**mss 抓背景时把窗口自己也抓进去了**。玻璃拿它当背景
|
|
22
|
+
等于"透过自己看自己",形成反馈回路:背景里带着上一帧的字 → 亮度判据一直抖 → 字色来回翻;
|
|
23
|
+
背景一直在变 → `moved` 一直为真 → 一直混合上一帧 → 越滚越浓的假拖尾(静止画面也在"动")。
|
|
24
|
+
|
|
25
|
+
现在录屏模式下把窗口矩形用**周边均值**刷平(试过按上下边缘插值,相邻列颜色不同会变成
|
|
26
|
+
一根根竖条,更难看)。窗口外 PAD 一圈仍是真背景,边缘透镜照常。
|
|
27
|
+
实测同一位置连续 6 帧:帧差从"每次都在变"降到 **0.00**。
|
|
28
|
+
|
|
29
|
+
### Added — 窗口心跳
|
|
30
|
+
|
|
31
|
+
`<cache>/window-heartbeat`,`_tick` 里每秒最多写一次。宿主那侧靠它区分"进程还在"和
|
|
32
|
+
"窗口真的在画"——只看 pid 的话,pid 被复用或界面卡死时永远认为窗还开着,于是再也不重开。
|
|
33
|
+
|
|
34
|
+
### Fixed — GPU 抓屏越界(合 PR #40,作者 @ggfgfgf-on,fixes #39)
|
|
35
|
+
|
|
36
|
+
GPU 路径的 `capture_gpu()` 有自己一份 `sct.grab()`,没做 `gr-gl/gb-gt` 守卫;
|
|
37
|
+
窗口被拖出屏幕时每帧抛 `Region has zero or negative size`,被 `_work()` 吞掉后背景永久停在旧帧。
|
|
38
|
+
补上和 CPU 路径一样的检查。
|
|
39
|
+
|
|
40
|
+
### Fixed — 台词 `at: null` 被存成第 0 秒(合 PR #38,作者 @ggfgfgf-on)
|
|
41
|
+
|
|
42
|
+
`Number(null) === 0`,显式写 `at: null` 的台词全被当成"第 0 秒",回读时挤在片头。
|
|
43
|
+
|
|
44
|
+
### Fixed — 本机 API 的 CORS 与聊天游标(合 PR #35,作者 @ggfgfgf-on,fixes #33 #34)
|
|
45
|
+
|
|
46
|
+
- 聊天/位置 API 原来对**任意网页**放开 CORS,可被跨站写入;改成只认白名单。
|
|
47
|
+
- `chat.jsonl` 被清短之后,聊天页的游标永久卡在越界位置;改成越界自动归零。
|
|
48
|
+
- 新增 `test/chat-server-guards.test.mjs`。
|
|
49
|
+
|
|
50
|
+
### Fixed — 卸载时没 detach voice adapter(合 PR #31,作者 @ggfgfgf-on,fixes #30)
|
|
51
|
+
|
|
52
|
+
适配器订阅了 speech bus,插件卸载却没退订 —— `speechSubscribers()` 一直 > 0,
|
|
53
|
+
重载后循环误以为"有人会念",模型再也不会被叫醒。
|
|
54
|
+
|
|
55
|
+
### Added — 设置页自动保存(合 PR #32,作者 @ggfgfgf-on)
|
|
56
|
+
|
|
57
|
+
改一项存一项,不用再点保存;顺带补了声音环境变量提示与连接状态。
|
|
58
|
+
|
|
6
59
|
## [0.2.6] - 2026-11-02
|
|
7
60
|
|
|
8
61
|
> 陪看的声音还差最后一步:到点才开始合成。这一轮把"合成"从关键路径上挪开。
|
package/dsh.plugin.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-watch-together",
|
|
3
|
-
"description": "Watch a video together with a text-only agent: follow the user's real playback position and hand over one segment at a time, just before the segment ends.",
|
|
4
|
-
"version": "0.2.
|
|
5
|
-
"entry": {
|
|
6
|
-
"name": "dsh-watch-together",
|
|
7
|
-
"inject": [
|
|
8
|
-
"tools",
|
|
9
|
-
"attachments"
|
|
10
|
-
]
|
|
11
|
-
}
|
|
12
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-watch-together",
|
|
3
|
+
"description": "Watch a video together with a text-only agent: follow the user's real playback position and hand over one segment at a time, just before the segment ends.",
|
|
4
|
+
"version": "0.2.7",
|
|
5
|
+
"entry": {
|
|
6
|
+
"name": "dsh-watch-together",
|
|
7
|
+
"inject": [
|
|
8
|
+
"tools",
|
|
9
|
+
"attachments"
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -448,6 +448,12 @@ def capture_gpu(self, sct):
|
|
|
448
448
|
gt = max(0, t - G.PAD)
|
|
449
449
|
gr = min(self._sw, r + G.PAD)
|
|
450
450
|
gb = min(self._sh, b + G.PAD)
|
|
451
|
+
# 和 window.py 的 CPU 路径保持一致:多显示器 / DPI 变化 / 被别的程序
|
|
452
|
+
# 挪出屏幕时,钳位后的宽高可能 <= 0;mss 会抛
|
|
453
|
+
# "Region has zero or negative size",而 _work() 会每帧吞掉它 ——
|
|
454
|
+
# 表现就是日志每帧刷一条、背景永久停在旧帧。没有可抓的区域就别抓。
|
|
455
|
+
if gr - gl <= 0 or gb - gt <= 0:
|
|
456
|
+
return None
|
|
451
457
|
shot = sct.grab({"left": gl, "top": gt, "width": gr - gl, "height": gb - gt})
|
|
452
458
|
factor = 1.0 if _gpu.native else 4.0
|
|
453
459
|
px = int(round((l - gl) / factor))
|
|
@@ -95,6 +95,38 @@ HEARTBEAT = cache_dir() / "window-heartbeat"
|
|
|
95
95
|
HEARTBEAT_EVERY = 1.0
|
|
96
96
|
|
|
97
97
|
|
|
98
|
+
def _fill_own_rect(im, box):
|
|
99
|
+
"""把「窗口自己」在抓屏帧里占的那块填掉。
|
|
100
|
+
|
|
101
|
+
**为什么必须填**:`capturable: true` 关掉了 `WDA_EXCLUDEFROMCAPTURE`,于是 mss
|
|
102
|
+
抓背景时**把窗口自己也抓进去了**。玻璃再拿这张图当背景,就等于"透过自己看自己":
|
|
103
|
+
|
|
104
|
+
- 背景里带着上一帧的字 → 亮度判据一直抖 → **字色来回翻**(看起来就是"字在闪");
|
|
105
|
+
- 背景一直在变 → `moved` 一直为真 → 一直混合上一帧 → **越滚越浓的拖尾**
|
|
106
|
+
(那种"黏黏的"感觉其实是自激,不是真的动态模糊);
|
|
107
|
+
- 静止画面上也会出现"画面在自己动"。
|
|
108
|
+
|
|
109
|
+
填法是拿这块上、下各一行像素做纵向线性插值 —— 得到一片渐变,像磨砂玻璃透出的
|
|
110
|
+
环境色,不会有细节更不会有自己的内容。窗口外的 `PAD` 一圈仍然是真背景,
|
|
111
|
+
边缘透镜照常能取到框外的料。
|
|
112
|
+
"""
|
|
113
|
+
x0, y0, x1, y1 = (int(v) for v in box)
|
|
114
|
+
arr = np.asarray(im)
|
|
115
|
+
h, w = arr.shape[:2]
|
|
116
|
+
x0, x1 = max(1, min(w - 1, x0)), max(1, min(w - 1, x1))
|
|
117
|
+
y0, y1 = max(1, min(h - 2, y0)), max(1, min(h - 2, y1))
|
|
118
|
+
n = y1 - y0
|
|
119
|
+
if x1 <= x0 or n <= 0:
|
|
120
|
+
return im
|
|
121
|
+
out = arr.copy()
|
|
122
|
+
top = arr[y0 - 1, x0:x1].astype(np.float32)
|
|
123
|
+
bot = arr[y1, x0:x1].astype(np.float32)
|
|
124
|
+
t = ((np.arange(n, dtype=np.float32) + 1.0) / (n + 1.0))[:, None, None]
|
|
125
|
+
grad = top[None, :, :] * (1.0 - t) + bot[None, :, :] * t
|
|
126
|
+
out[y0:y1, x0:x1] = np.clip(grad, 0, 255).astype(np.uint8)
|
|
127
|
+
return Image.fromarray(out)
|
|
128
|
+
|
|
129
|
+
|
|
98
130
|
def read_config():
|
|
99
131
|
try:
|
|
100
132
|
return json.loads(CONFIG.read_text(encoding="utf-8")) or {}
|
|
@@ -102,6 +134,28 @@ def read_config():
|
|
|
102
134
|
return {}
|
|
103
135
|
|
|
104
136
|
|
|
137
|
+
def capturable():
|
|
138
|
+
"""录屏 / 截图能不能拍到窗口。
|
|
139
|
+
|
|
140
|
+
默认**不能** —— 走 `WDA_EXCLUDEFROMCAPTURE`,窗口不会出现在截图、直播、共享屏幕里。
|
|
141
|
+
要给别人看效果、或者自己录一段发出来,就打开:
|
|
142
|
+
|
|
143
|
+
```json
|
|
144
|
+
// ~/.dsh/watch-window.json
|
|
145
|
+
{ "capturable": true }
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
环境变量 `DSH_GLASS_WDA=0` 也能打开,但它只对**这一次启动**有效(插件拉起窗口时不会传它),
|
|
149
|
+
所以配置项才是那个"开关"。改完要重启窗口才生效。
|
|
150
|
+
"""
|
|
151
|
+
if os.environ.get("DSH_GLASS_WDA") == "0":
|
|
152
|
+
return True
|
|
153
|
+
try:
|
|
154
|
+
return read_config().get("capturable") is True
|
|
155
|
+
except Exception:
|
|
156
|
+
return False
|
|
157
|
+
|
|
158
|
+
|
|
105
159
|
def write_config(patch):
|
|
106
160
|
cfg = read_config()
|
|
107
161
|
cfg.update(patch or {})
|
|
@@ -484,6 +538,9 @@ class LiveGlass:
|
|
|
484
538
|
self._bg = None
|
|
485
539
|
self._hwnd = None
|
|
486
540
|
self._excluded = False
|
|
541
|
+
# 录屏模式(capturable)下 mss 会抓到窗口自己,必须每帧挖掉,见 _fill_own_rect。
|
|
542
|
+
# 缓存起来:读配置是磁盘 IO,不能每帧做。
|
|
543
|
+
self._cappable = capturable()
|
|
487
544
|
self._drag = None
|
|
488
545
|
self._resize = None
|
|
489
546
|
self._preview_at = 0.0
|
|
@@ -515,7 +572,7 @@ class LiveGlass:
|
|
|
515
572
|
self._text_items = [i for i in self.canvas.find_all()
|
|
516
573
|
if self.canvas.type(i) == "text"
|
|
517
574
|
and i not in shadow_ids]
|
|
518
|
-
self._set_exclude(
|
|
575
|
+
self._set_exclude(not capturable())
|
|
519
576
|
self._worker.start()
|
|
520
577
|
self.root.lift()
|
|
521
578
|
self.root.after(80, self.root.lift)
|
|
@@ -909,6 +966,10 @@ class LiveGlass:
|
|
|
909
966
|
shot = sct.grab({"left": gl, "top": gt,
|
|
910
967
|
"width": gr - gl, "height": gb - gt})
|
|
911
968
|
im = Image.frombytes("RGB", shot.size, shot.rgb)
|
|
969
|
+
# **录屏模式必须挖掉自己**:WDA 关了之后 mss 会把窗口也抓进来,
|
|
970
|
+
# 玻璃拿它当背景就变成自我反馈(字闪 / 假拖尾 / 静止画面在动)。
|
|
971
|
+
if self._cappable:
|
|
972
|
+
im = _fill_own_rect(im, (l - gl, t - gt, r - gl, b - gt))
|
|
912
973
|
sw4, sh4 = max(2, (gr - gl) // 4), max(2, (gb - gt) // 4)
|
|
913
974
|
# 60fps 路径:只在 1/4 分辨率做一次模糊和折射,再放大。
|
|
914
975
|
# cv2 的 resize 比 PIL 快一个数量级;没有 OpenCV 时无感回退。
|
|
@@ -1681,7 +1742,7 @@ class LiveGlass:
|
|
|
1681
1742
|
# 底部圆角/暗边会闪一下,看起来像渲染错位。
|
|
1682
1743
|
self.root.after(INTERVAL_MS, self._tick)
|
|
1683
1744
|
return
|
|
1684
|
-
if not self._excluded and
|
|
1745
|
+
if not self._excluded and not capturable():
|
|
1685
1746
|
self._set_exclude(True)
|
|
1686
1747
|
self._pause.clear()
|
|
1687
1748
|
|
package/lib/client.js
CHANGED
|
@@ -87,6 +87,7 @@ window.__ModuleLoader__.load({
|
|
|
87
87
|
browserPort: video.browserPort ? String(video.browserPort) : '',
|
|
88
88
|
chatPort: watch.chatPort ? String(watch.chatPort) : '9377',
|
|
89
89
|
adapter: typeof voice.adapter === 'string' ? voice.adapter : '',
|
|
90
|
+
voiceEnvOverrides: Array.isArray(voice.envOverrides) ? voice.envOverrides : [],
|
|
90
91
|
};
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -126,10 +127,14 @@ window.__ModuleLoader__.load({
|
|
|
126
127
|
useInjectedStyle();
|
|
127
128
|
const [form, setForm] = useState(null);
|
|
128
129
|
const [checks, setChecks] = useState([]);
|
|
129
|
-
const [busy, setBusy] = useState(false);
|
|
130
130
|
const [checking, setChecking] = useState(false);
|
|
131
131
|
const [error, setError] = useState('');
|
|
132
132
|
const [notice, setNotice] = useState('');
|
|
133
|
+
const formRef = React.useRef(null);
|
|
134
|
+
const firstRender = React.useRef(true);
|
|
135
|
+
const saving = React.useRef(false);
|
|
136
|
+
const pending = React.useRef(false);
|
|
137
|
+
formRef.current = form;
|
|
133
138
|
|
|
134
139
|
async function runCheck(api) {
|
|
135
140
|
const target = api || apiConfig();
|
|
@@ -157,50 +162,86 @@ window.__ModuleLoader__.load({
|
|
|
157
162
|
setError('设置接口未注入,请重启 DSH。');
|
|
158
163
|
return undefined;
|
|
159
164
|
}
|
|
160
|
-
setBusy(true);
|
|
161
165
|
apiCall(api, '/state').then(state => {
|
|
162
166
|
if (cancelled) return;
|
|
163
167
|
setForm(formFromState(state));
|
|
164
|
-
setBusy(false);
|
|
165
168
|
void runCheck(api);
|
|
166
169
|
}).catch(e => {
|
|
167
170
|
if (cancelled) return;
|
|
168
171
|
setError(String(e && e.message ? e.message : e));
|
|
169
|
-
setBusy(false);
|
|
170
172
|
});
|
|
171
173
|
return () => { cancelled = true; };
|
|
172
174
|
}, []);
|
|
173
175
|
|
|
176
|
+
function validationError(current) {
|
|
177
|
+
const browserPort = current.browserPort === '' ? false : Number(current.browserPort);
|
|
178
|
+
if (browserPort !== false
|
|
179
|
+
&& (!Number.isInteger(browserPort) || browserPort < 1 || browserPort > 65535)) {
|
|
180
|
+
return '浏览器调试端口必须是 1-65535 的整数。';
|
|
181
|
+
}
|
|
182
|
+
const chatPort = Number(current.chatPort);
|
|
183
|
+
if (!Number.isInteger(chatPort) || chatPort < 1 || chatPort > 65535) {
|
|
184
|
+
return '聊天服务端口必须是 1-65535 的整数。';
|
|
185
|
+
}
|
|
186
|
+
return '';
|
|
187
|
+
}
|
|
188
|
+
|
|
174
189
|
async function save() {
|
|
175
|
-
|
|
190
|
+
const current = formRef.current;
|
|
191
|
+
if (!current) return;
|
|
192
|
+
if (saving.current) {
|
|
193
|
+
pending.current = true;
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
176
196
|
const api = apiConfig();
|
|
177
197
|
if (!api) {
|
|
178
198
|
setError('设置接口未注入,请重启 DSH。');
|
|
179
199
|
return;
|
|
180
200
|
}
|
|
181
|
-
|
|
201
|
+
const invalid = validationError(current);
|
|
202
|
+
if (invalid) {
|
|
203
|
+
setError(invalid);
|
|
204
|
+
setNotice('');
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
saving.current = true;
|
|
182
208
|
setError('');
|
|
183
209
|
setNotice('');
|
|
184
210
|
try {
|
|
185
211
|
const video = {
|
|
186
|
-
browserPort:
|
|
212
|
+
browserPort: current.browserPort === '' ? false : Number(current.browserPort),
|
|
187
213
|
};
|
|
188
|
-
const watch = { chatPort: Number(
|
|
189
|
-
const voice = { adapter:
|
|
214
|
+
const watch = { chatPort: Number(current.chatPort) };
|
|
215
|
+
const voice = { adapter: current.adapter };
|
|
190
216
|
await apiCall(api, '/save', { video: video, watch: watch, voice: voice });
|
|
191
|
-
setNotice('
|
|
217
|
+
setNotice('已自动保存。聊天端口改动在下次启动 DSH 后生效。');
|
|
192
218
|
} catch (e) {
|
|
193
219
|
setError(String(e && e.message ? e.message : e));
|
|
194
220
|
} finally {
|
|
195
|
-
|
|
221
|
+
saving.current = false;
|
|
222
|
+
if (pending.current) {
|
|
223
|
+
pending.current = false;
|
|
224
|
+
setTimeout(() => { void save(); }, 0);
|
|
225
|
+
}
|
|
196
226
|
}
|
|
197
227
|
}
|
|
198
228
|
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
if (!form) return undefined;
|
|
231
|
+
if (firstRender.current) {
|
|
232
|
+
firstRender.current = false;
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
const timer = setTimeout(() => { void save(); }, 550);
|
|
236
|
+
return () => clearTimeout(timer);
|
|
237
|
+
}, [form && form.browserPort, form && form.chatPort, form && form.adapter]);
|
|
238
|
+
|
|
199
239
|
if (!form) {
|
|
200
240
|
return h('div', { 'data-dsh-vs': 'watch', className: 'dsh-vs dsh-vs-loading' }, error || '正在加载设置…');
|
|
201
241
|
}
|
|
202
242
|
|
|
203
243
|
const visibleChecks = checks.filter(item => item.id !== 'browser' && item.id !== 'chat' && item.id !== 'voice');
|
|
244
|
+
const connectionChecks = checks.filter(item => item.id === 'browser' || item.id === 'chat' || item.id === 'voice');
|
|
204
245
|
const optionalIds = { python: true, extension: true, floating: true };
|
|
205
246
|
|
|
206
247
|
return h('div', { 'data-dsh-vs': 'watch', className: 'dsh-vs' },
|
|
@@ -241,6 +282,28 @@ window.__ModuleLoader__.load({
|
|
|
241
282
|
onChange: value => setForm(prev => ({ ...prev, adapter: value })),
|
|
242
283
|
}),
|
|
243
284
|
),
|
|
285
|
+
form.voiceEnvOverrides.length
|
|
286
|
+
? h('p', { className: 'dsh-vs-effective' },
|
|
287
|
+
'环境变量优先:' + form.voiceEnvOverrides.join('、') + ';这里的改动不会覆盖它们。')
|
|
288
|
+
: null,
|
|
289
|
+
),
|
|
290
|
+
h('section', { className: 'dsh-vs-section' },
|
|
291
|
+
h('div', { className: 'dsh-vs-section-head' },
|
|
292
|
+
h('h3', { className: 'dsh-vs-section-title' }, '连接状态'),
|
|
293
|
+
),
|
|
294
|
+
connectionChecks.length
|
|
295
|
+
? h('div', { className: 'dsh-vs-deps' }, connectionChecks.map(check =>
|
|
296
|
+
h('div', { className: 'dsh-vs-dep', key: check.id },
|
|
297
|
+
h('span', {
|
|
298
|
+
className: 'dsh-vs-dot'
|
|
299
|
+
+ (check.ok ? '' : optionalIds[check.id] ? ' is-warn' : ' is-bad'),
|
|
300
|
+
}),
|
|
301
|
+
h('div', { className: 'dsh-vs-dep-main' },
|
|
302
|
+
h('div', { className: 'dsh-vs-dep-name' }, check.label || check.id),
|
|
303
|
+
h('div', { className: 'dsh-vs-dep-detail', title: check.detail || '' }, check.detail || ''),
|
|
304
|
+
),
|
|
305
|
+
)))
|
|
306
|
+
: h('p', { className: 'dsh-vs-hint' }, checking ? '正在检查…' : '尚未检查。'),
|
|
244
307
|
),
|
|
245
308
|
h('section', { className: 'dsh-vs-section' },
|
|
246
309
|
h('div', { className: 'dsh-vs-section-head' },
|
|
@@ -270,12 +333,6 @@ window.__ModuleLoader__.load({
|
|
|
270
333
|
: h('p', { className: 'dsh-vs-hint' }, checking ? '正在检查…' : '尚未检查。'),
|
|
271
334
|
),
|
|
272
335
|
h('div', { className: 'dsh-vs-footer' },
|
|
273
|
-
h('button', {
|
|
274
|
-
type: 'button',
|
|
275
|
-
className: 'dsh-vs-btn dsh-vs-btn-primary',
|
|
276
|
-
disabled: busy,
|
|
277
|
-
onClick: save,
|
|
278
|
-
}, busy ? '保存中…' : '保存'),
|
|
279
336
|
h('span', { className: 'dsh-vs-status' + (error ? ' is-error' : ''), role: 'status' },
|
|
280
337
|
error || notice),
|
|
281
338
|
),
|
package/package.json
CHANGED
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "dsh-watch-together",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"dsh",
|
|
7
|
-
"dsh-plugin",
|
|
8
|
-
"deepseek-harness",
|
|
9
|
-
"video",
|
|
10
|
-
"watch-together",
|
|
11
|
-
"watch-party",
|
|
12
|
-
"companion",
|
|
13
|
-
"playback",
|
|
14
|
-
"subtitle",
|
|
15
|
-
"caption",
|
|
16
|
-
"tts"
|
|
17
|
-
],
|
|
18
|
-
"homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
|
|
21
|
-
},
|
|
22
|
-
"repository": {
|
|
23
|
-
"type": "git",
|
|
24
|
-
"url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
|
|
25
|
-
},
|
|
26
|
-
"author": "SAOS-3624",
|
|
27
|
-
"license": "Apache-2.0",
|
|
28
|
-
"type": "module",
|
|
29
|
-
"main": "./src/index.js",
|
|
30
|
-
"exports": {
|
|
31
|
-
".": "./src/index.js",
|
|
32
|
-
"./client": "./lib/client.js",
|
|
33
|
-
"./register": "./src/register.js",
|
|
34
|
-
"./tool-spec": "./src/tool-spec.js",
|
|
35
|
-
"./watch": "./src/watch.js",
|
|
36
|
-
"./batches": "./src/batches.js",
|
|
37
|
-
"./chat": "./src/chat.js",
|
|
38
|
-
"./voice": "./src/voice.js",
|
|
39
|
-
"./speech-bus": "./src/speech-bus.js",
|
|
40
|
-
"./voice-adapter": "./src/voice-adapter.js",
|
|
41
|
-
"./interfaces": "./src/interfaces.js",
|
|
42
|
-
"./public-api": "./src/public-api.js",
|
|
43
|
-
"./recognition-interface": "./src/recognition-interface.js",
|
|
44
|
-
"./tts-interface": "./src/tts-interface.js",
|
|
45
|
-
"./window-interface": "./src/window-interface.js",
|
|
46
|
-
"./window-protocol": "./src/window-protocol.js"
|
|
47
|
-
},
|
|
48
|
-
"bin": {
|
|
49
|
-
"dsh-watch": "./bin/watch.mjs",
|
|
50
|
-
"dsh-watch-lines": "./bin/lines.mjs"
|
|
51
|
-
},
|
|
52
|
-
"files": [
|
|
53
|
-
"src",
|
|
54
|
-
"lib",
|
|
55
|
-
"bin",
|
|
56
|
-
"extension",
|
|
57
|
-
"scripts",
|
|
58
|
-
"docs",
|
|
59
|
-
"cordis.patch.yml",
|
|
60
|
-
"dsh.plugin.json",
|
|
61
|
-
"README.md",
|
|
62
|
-
"CHANGELOG.md",
|
|
63
|
-
"LICENSE",
|
|
64
|
-
"NOTICE",
|
|
65
|
-
"examples/floating-chat/*.py",
|
|
66
|
-
"examples/floating-chat/*.cmd",
|
|
67
|
-
"examples/floating-chat/*.png",
|
|
68
|
-
"examples/floating-chat/*.txt",
|
|
69
|
-
"examples/voice-edge-tts/index.mjs"
|
|
70
|
-
],
|
|
71
|
-
"engines": {
|
|
72
|
-
"node": ">=20"
|
|
73
|
-
},
|
|
74
|
-
"scripts": {
|
|
75
|
-
"test": "node --test",
|
|
76
|
-
"pretest": "node scripts/sync-dep.mjs",
|
|
77
|
-
"sync:dep": "node scripts/sync-dep.mjs",
|
|
78
|
-
"prepublishOnly": "node scripts/check-syntax.mjs && node --test",
|
|
79
|
-
"check": "node scripts/check-syntax.mjs",
|
|
80
|
-
"doctor": "node bin/watch.mjs doctor",
|
|
81
|
-
"install:extension": "node bin/watch.mjs install-extension",
|
|
82
|
-
"sim": "node scripts/watch-sim.mjs",
|
|
83
|
-
"e2e": "node scripts/watch-e2e.mjs"
|
|
84
|
-
},
|
|
85
|
-
"dependencies": {
|
|
86
|
-
"dsh-video-storyboard": "^0.6.0"
|
|
87
|
-
},
|
|
88
|
-
"peerDependencies": {
|
|
89
|
-
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
|
|
90
|
-
},
|
|
91
|
-
"peerDependenciesMeta": {
|
|
92
|
-
"@deepseek-ai/dsh-tools": {
|
|
93
|
-
"optional": true
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
"dsh": {
|
|
97
|
-
"bundle": {
|
|
98
|
-
"patch": "./cordis.patch.yml"
|
|
99
|
-
},
|
|
100
|
-
"client": {
|
|
101
|
-
"platform": "web"
|
|
102
|
-
},
|
|
103
|
-
"catalog": {
|
|
104
|
-
"category": "tool",
|
|
105
|
-
"summary": {
|
|
106
|
-
"en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
|
|
107
|
-
"zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
|
|
108
|
-
},
|
|
109
|
-
"capabilities": [
|
|
110
|
-
"fs",
|
|
111
|
-
"shell"
|
|
112
|
-
]
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "dsh-watch-together",
|
|
3
|
+
"version": "0.2.7",
|
|
4
|
+
"description": "Watch a video together with a text-only agent: follow the user's real playback position, hand over one segment at a time just before it ends, and keep a single text stream of scripted lines, interjections and the user's replies.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"dsh",
|
|
7
|
+
"dsh-plugin",
|
|
8
|
+
"deepseek-harness",
|
|
9
|
+
"video",
|
|
10
|
+
"watch-together",
|
|
11
|
+
"watch-party",
|
|
12
|
+
"companion",
|
|
13
|
+
"playback",
|
|
14
|
+
"subtitle",
|
|
15
|
+
"caption",
|
|
16
|
+
"tts"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/SAOS-3624/dsh-watch-together#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/SAOS-3624/dsh-watch-together/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/SAOS-3624/dsh-watch-together.git"
|
|
25
|
+
},
|
|
26
|
+
"author": "SAOS-3624",
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"main": "./src/index.js",
|
|
30
|
+
"exports": {
|
|
31
|
+
".": "./src/index.js",
|
|
32
|
+
"./client": "./lib/client.js",
|
|
33
|
+
"./register": "./src/register.js",
|
|
34
|
+
"./tool-spec": "./src/tool-spec.js",
|
|
35
|
+
"./watch": "./src/watch.js",
|
|
36
|
+
"./batches": "./src/batches.js",
|
|
37
|
+
"./chat": "./src/chat.js",
|
|
38
|
+
"./voice": "./src/voice.js",
|
|
39
|
+
"./speech-bus": "./src/speech-bus.js",
|
|
40
|
+
"./voice-adapter": "./src/voice-adapter.js",
|
|
41
|
+
"./interfaces": "./src/interfaces.js",
|
|
42
|
+
"./public-api": "./src/public-api.js",
|
|
43
|
+
"./recognition-interface": "./src/recognition-interface.js",
|
|
44
|
+
"./tts-interface": "./src/tts-interface.js",
|
|
45
|
+
"./window-interface": "./src/window-interface.js",
|
|
46
|
+
"./window-protocol": "./src/window-protocol.js"
|
|
47
|
+
},
|
|
48
|
+
"bin": {
|
|
49
|
+
"dsh-watch": "./bin/watch.mjs",
|
|
50
|
+
"dsh-watch-lines": "./bin/lines.mjs"
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"src",
|
|
54
|
+
"lib",
|
|
55
|
+
"bin",
|
|
56
|
+
"extension",
|
|
57
|
+
"scripts",
|
|
58
|
+
"docs",
|
|
59
|
+
"cordis.patch.yml",
|
|
60
|
+
"dsh.plugin.json",
|
|
61
|
+
"README.md",
|
|
62
|
+
"CHANGELOG.md",
|
|
63
|
+
"LICENSE",
|
|
64
|
+
"NOTICE",
|
|
65
|
+
"examples/floating-chat/*.py",
|
|
66
|
+
"examples/floating-chat/*.cmd",
|
|
67
|
+
"examples/floating-chat/*.png",
|
|
68
|
+
"examples/floating-chat/*.txt",
|
|
69
|
+
"examples/voice-edge-tts/index.mjs"
|
|
70
|
+
],
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=20"
|
|
73
|
+
},
|
|
74
|
+
"scripts": {
|
|
75
|
+
"test": "node --test",
|
|
76
|
+
"pretest": "node scripts/sync-dep.mjs",
|
|
77
|
+
"sync:dep": "node scripts/sync-dep.mjs",
|
|
78
|
+
"prepublishOnly": "node scripts/check-syntax.mjs && node --test",
|
|
79
|
+
"check": "node scripts/check-syntax.mjs",
|
|
80
|
+
"doctor": "node bin/watch.mjs doctor",
|
|
81
|
+
"install:extension": "node bin/watch.mjs install-extension",
|
|
82
|
+
"sim": "node scripts/watch-sim.mjs",
|
|
83
|
+
"e2e": "node scripts/watch-e2e.mjs"
|
|
84
|
+
},
|
|
85
|
+
"dependencies": {
|
|
86
|
+
"dsh-video-storyboard": "^0.6.0"
|
|
87
|
+
},
|
|
88
|
+
"peerDependencies": {
|
|
89
|
+
"@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
|
|
90
|
+
},
|
|
91
|
+
"peerDependenciesMeta": {
|
|
92
|
+
"@deepseek-ai/dsh-tools": {
|
|
93
|
+
"optional": true
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
"dsh": {
|
|
97
|
+
"bundle": {
|
|
98
|
+
"patch": "./cordis.patch.yml"
|
|
99
|
+
},
|
|
100
|
+
"client": {
|
|
101
|
+
"platform": "web"
|
|
102
|
+
},
|
|
103
|
+
"catalog": {
|
|
104
|
+
"category": "tool",
|
|
105
|
+
"summary": {
|
|
106
|
+
"en": "Watch a video together with a text-only agent: it follows your real playback position and hands over one segment at a time, just before that segment ends.",
|
|
107
|
+
"zh": "和只有文字的智能体一起看视频:跟着你真实的播放位置,一段一段把画面和台词交到它手上,在每段结束前说完。"
|
|
108
|
+
},
|
|
109
|
+
"capabilities": [
|
|
110
|
+
"fs",
|
|
111
|
+
"shell"
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
package/src/chat-server.js
CHANGED
|
@@ -38,19 +38,49 @@ export async function startChatServer({
|
|
|
38
38
|
|
|
39
39
|
// 扩展从**网页的源**发请求,属于跨域;而且是从公网页面访问本地地址,
|
|
40
40
|
// Chrome 的 Private Network Access 还要求预检里看到 allow-private-network。
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
//
|
|
42
|
+
// **不能直接放开成 `*`**:否则用户随便打开一个网页,它就能向本机 9377 写假台词、
|
|
43
|
+
// 伪造播放位置。只放行扩展来源和同端口的本机页面;没有 Origin 的请求(CLI、Python
|
|
44
|
+
// 悬浮窗、curl)保持可用 —— 浏览器发起的跨域请求一定会带 Origin。
|
|
45
|
+
const EXTENSION_SCHEMES = new Set(['chrome-extension:', 'moz-extension:', 'safari-web-extension:']);
|
|
46
|
+
function isAllowedOrigin(origin, port) {
|
|
47
|
+
if (!origin) return true;
|
|
48
|
+
try {
|
|
49
|
+
const u = new URL(origin);
|
|
50
|
+
if (EXTENSION_SCHEMES.has(u.protocol)) return true;
|
|
51
|
+
if (u.protocol !== 'http:') return false;
|
|
52
|
+
const host = u.hostname;
|
|
53
|
+
if (host !== '127.0.0.1' && host !== 'localhost' && host !== '[::1]') return false;
|
|
54
|
+
const p = Number(u.port || 80);
|
|
55
|
+
return Number.isInteger(p) && p === Number(port);
|
|
56
|
+
} catch {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function corsFor(origin) {
|
|
61
|
+
return {
|
|
62
|
+
'access-control-allow-origin': origin || '*',
|
|
63
|
+
'access-control-allow-methods': 'GET, POST, OPTIONS',
|
|
64
|
+
'access-control-allow-headers': 'content-type',
|
|
65
|
+
'access-control-allow-private-network': 'true',
|
|
66
|
+
'cache-control': 'no-store',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
49
69
|
|
|
50
70
|
const server = createServer(async (req, res) => {
|
|
51
71
|
let u;
|
|
52
72
|
try { u = new URL(req.url, 'http://127.0.0.1'); } catch { res.writeHead(400); res.end(); return; }
|
|
53
73
|
|
|
74
|
+
const port = server.address()?.port ?? listenPort;
|
|
75
|
+
const origin = typeof req.headers.origin === 'string' && req.headers.origin
|
|
76
|
+
? req.headers.origin : null;
|
|
77
|
+
if (!isAllowedOrigin(origin, port)) {
|
|
78
|
+
res.writeHead(403, { 'content-type': 'text/plain; charset=utf-8' });
|
|
79
|
+
res.end('origin not allowed');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const cors = corsFor(origin);
|
|
83
|
+
|
|
54
84
|
// 扩展直接 fetch(不经过 service worker)时会有这一趟预检
|
|
55
85
|
if (req.method === 'OPTIONS') {
|
|
56
86
|
res.writeHead(204, cors);
|
|
@@ -107,8 +137,16 @@ export async function startChatServer({
|
|
|
107
137
|
if (u.pathname === '/api/messages') {
|
|
108
138
|
const since = Math.max(0, Number(u.searchParams.get('since')) || 0);
|
|
109
139
|
const all = readChat(env);
|
|
110
|
-
|
|
111
|
-
|
|
140
|
+
// 页面按"已读条数"轮询。chat.jsonl 被清空/重写后文件会比 since 短,
|
|
141
|
+
// 这时 slice(since) 永远是空的 —— 页面从此再也看不到新消息。让页面知道
|
|
142
|
+
// 该重置游标,而不是让它永远卡在旧条数上。
|
|
143
|
+
const reset = since > all.length;
|
|
144
|
+
res.writeHead(200, { ...cors, 'content-type': 'application/json; charset=utf-8', 'cache-control': 'no-store' });
|
|
145
|
+
res.end(JSON.stringify({
|
|
146
|
+
total: all.length,
|
|
147
|
+
msgs: reset ? all : all.slice(since),
|
|
148
|
+
...(reset ? { reset: true } : {}),
|
|
149
|
+
}));
|
|
112
150
|
return;
|
|
113
151
|
}
|
|
114
152
|
if (u.pathname === '/api/say' && req.method === 'POST') {
|
|
@@ -128,7 +166,7 @@ export async function startChatServer({
|
|
|
128
166
|
} catch { /* 坏请求就算了 */ }
|
|
129
167
|
// ok:false 让页面能把话回填进输入框 —— 之前一律 ok:true,
|
|
130
168
|
// 服务端没写进去用户也不知道,字就丢了
|
|
131
|
-
res.writeHead(200, { 'content-type': 'application/json' });
|
|
169
|
+
res.writeHead(200, { ...cors, 'content-type': 'application/json' });
|
|
132
170
|
res.end(JSON.stringify({ ok }));
|
|
133
171
|
});
|
|
134
172
|
return;
|
package/src/chat-view.js
CHANGED
|
@@ -56,6 +56,9 @@ input:focus{border-color:#4a7ab5}
|
|
|
56
56
|
var n=0;
|
|
57
57
|
function poll(){
|
|
58
58
|
fetch(BASE+"/api/messages?since="+n+"&t="+Date.now()).then(function(r){return r.json();}).then(function(j){
|
|
59
|
+
// chat.jsonl 被清空/重写过:游标比文件长,服务端会回 reset。清屏重放,
|
|
60
|
+
// 否则页面会一直用旧条数 slice,新消息永远不出现。
|
|
61
|
+
if(j.reset){log.innerHTML="";n=0;}
|
|
59
62
|
for(var k=0;k<j.msgs.length;k++)add(j.msgs[k]);
|
|
60
63
|
n=j.total;setTimeout(poll,600);
|
|
61
64
|
}).catch(function(){setTimeout(poll,1500);});
|
package/src/index.js
CHANGED
|
@@ -102,10 +102,18 @@ async function registerAll(ctx) {
|
|
|
102
102
|
// 声音适配器(可选):只通过 tts 接口挂,不 import voice.js。
|
|
103
103
|
// 这里也保留启动时挂载,这样第一次只调 `say`(还没开窗)也有声音。
|
|
104
104
|
try {
|
|
105
|
-
const
|
|
105
|
+
const tts = getTtsPort();
|
|
106
|
+
const v = await tts.attachConfigured?.({ log: (m) => ctx?.logger?.info?.(m) });
|
|
106
107
|
if (v && !v.ok && v.reason !== 'not-configured') {
|
|
107
108
|
ctx?.logger?.warn?.(`[dsh-watch-together] voice adapter not loaded: ${v.reason}`);
|
|
108
109
|
}
|
|
110
|
+
// 适配器订阅了 speech bus;插件卸载必须退订,否则 speechSubscribers()
|
|
111
|
+
// 会一直 > 0,重载后循环误以为"有人会念",模型就再也不会被叫醒。
|
|
112
|
+
if (v?.ok && typeof tts.detachConfigured === 'function') {
|
|
113
|
+
disposers.push(() => {
|
|
114
|
+
try { void tts.detachConfigured(); } catch { /* 卸载失败不能影响其他 disposer */ }
|
|
115
|
+
});
|
|
116
|
+
}
|
|
109
117
|
} catch (e) {
|
|
110
118
|
ctx?.logger?.warn?.(`[dsh-watch-together] voice adapter crashed: ${e?.message ?? e}`);
|
|
111
119
|
}
|
package/src/settings/config.js
CHANGED
|
@@ -118,6 +118,8 @@ export function readVoiceSettings(env = process.env) {
|
|
|
118
118
|
exists: raw.exists,
|
|
119
119
|
error: raw.error,
|
|
120
120
|
adapter: typeof raw.data.adapter === 'string' ? raw.data.adapter : '',
|
|
121
|
+
envOverrides: ['DSH_VOICE_ADAPTER']
|
|
122
|
+
.filter((k) => env[k] !== undefined && env[k] !== ''),
|
|
121
123
|
};
|
|
122
124
|
}
|
|
123
125
|
|
package/src/settings/deps.js
CHANGED
|
@@ -115,11 +115,12 @@ function floatingWindow() {
|
|
|
115
115
|
|
|
116
116
|
function voice(env) {
|
|
117
117
|
const cfg = readVoiceSettings(env);
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
118
|
+
const adapter = String(env.DSH_VOICE_ADAPTER || '').trim() || cfg.adapter;
|
|
119
|
+
if (!adapter) return { ok: false, detail: '未配置(可选;只影响念台词)' };
|
|
120
|
+
if (/^[a-zA-Z]:[\\/]|^\\\\|^\.{1,2}[\\/]|^\//.test(adapter)) {
|
|
121
|
+
return { ok: existsSync(adapter), detail: existsSync(adapter) ? adapter : '文件不存在:' + adapter };
|
|
121
122
|
}
|
|
122
|
-
return { ok: true, detail:
|
|
123
|
+
return { ok: true, detail: adapter + '(包名,挂载时才能校验)' };
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
/** @returns {Promise<Array<{id:string,label:string,ok:boolean,detail:string}>>} */
|
package/src/tts-interface.js
CHANGED
|
@@ -16,6 +16,7 @@ export const TTS_INTERFACE_VERSION = 1;
|
|
|
16
16
|
* speechSubscribers: Function,
|
|
17
17
|
* lastSpeech: Function,
|
|
18
18
|
* attachConfiguredVoice?: Function,
|
|
19
|
+
* detachAdapters?: Function,
|
|
19
20
|
* attachedAdapters?: Function,
|
|
20
21
|
* configuredVoiceAdapter?: Function,
|
|
21
22
|
* }} bus
|
|
@@ -23,7 +24,7 @@ export const TTS_INTERFACE_VERSION = 1;
|
|
|
23
24
|
export function createTtsInterface(bus = {}) {
|
|
24
25
|
const {
|
|
25
26
|
onSpeech, emitSpeech, emitSpoken, speechSubscribers, lastSpeech,
|
|
26
|
-
attachConfiguredVoice, attachedAdapters, configuredVoiceAdapter,
|
|
27
|
+
attachConfiguredVoice, detachAdapters, attachedAdapters, configuredVoiceAdapter,
|
|
27
28
|
} = bus;
|
|
28
29
|
for (const [name, fn] of Object.entries({ onSpeech, emitSpeech, speechSubscribers, lastSpeech })) {
|
|
29
30
|
if (typeof fn !== 'function') throw new TypeError(`tts: ${name}() is required`);
|
|
@@ -53,6 +54,7 @@ export function createTtsInterface(bus = {}) {
|
|
|
53
54
|
return lastSpeech();
|
|
54
55
|
},
|
|
55
56
|
attachConfigured: typeof attachConfiguredVoice === 'function' ? attachConfiguredVoice : null,
|
|
57
|
+
detachConfigured: typeof detachAdapters === 'function' ? detachAdapters : null,
|
|
56
58
|
attached: typeof attachedAdapters === 'function' ? attachedAdapters : () => [],
|
|
57
59
|
configured: typeof configuredVoiceAdapter === 'function' ? configuredVoiceAdapter : () => null,
|
|
58
60
|
});
|
package/src/watch-lines.js
CHANGED
|
@@ -166,9 +166,17 @@ export async function saveLines(input, lines, { env = process.env } = {}) {
|
|
|
166
166
|
// `at` 除了秒数,还可以直接传**字幕原文片段**,这里去转写里查它的 from。
|
|
167
167
|
// 为什么必须有这条路:模型凭印象写秒数会整段错 —— 实测把"1/4 螺口"挂在 189 秒,
|
|
168
168
|
// 而字幕里它在 247 秒,提前了 58 秒,用户当场发现"台词对不上视频"。
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
//
|
|
170
|
+
// **null 和"没写 at"同义**:显式传 `at: null` 是合法输入(校验允许),
|
|
171
|
+
// 但 `Number(null) === 0` 会把它存成"第 0 秒"——第 180 段的那句从此永远
|
|
172
|
+
// 是"迟到 180 秒"被 dueLine 丢掉,用户看到的是"写了台词却没念"。
|
|
173
|
+
// 这里只接受数字或非空字符串;其余(null / undefined / 空串)都当没写。
|
|
174
|
+
const rawAt = l?.at;
|
|
175
|
+
let at = NaN;
|
|
176
|
+
if (typeof rawAt === 'number') {
|
|
177
|
+
at = rawAt;
|
|
178
|
+
} else if (typeof rawAt === 'string' && rawAt.trim()) {
|
|
179
|
+
const q = rawAt.trim();
|
|
172
180
|
// **先查落盘的 `subs-<key>.json`,再查 locate 的进程内记忆**。
|
|
173
181
|
// 后者只有 4 条、重启就空,而台词恰恰经常在另一个进程/另一轮里写 ——
|
|
174
182
|
// 查不到就会被当成"没写 at",落到段首:用户看到的就是"台词比画面早一大截"。
|