dsh-watch-together 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/plugin.md ADDED
@@ -0,0 +1,9 @@
1
+ # Watch Together
2
+
3
+ Watch a video in sync with the user's real playback. Before each segment ends, the plugin delivers one storyboard image and its timed lines; the floating window carries speech, microphone input, and the chat history.
4
+
5
+ - `watch_together`: start watching, wait for the next segment, write lines
6
+ - Floating window: voice input/output, history, microphone
7
+ - Settings: browser debug port, chat port, window style
8
+
9
+ See the repository README for full usage and integration details.
@@ -0,0 +1,9 @@
1
+ # 一起看
2
+
3
+ 跟着用户真实播放位置一起看视频。每段结束前,插件把一张分镜图 + 带秒台词交过来;悬浮窗负责说话、收音和显示字幕。
4
+
5
+ - `watch_together`:进入陪看、等待下一段、写入台词
6
+ - 悬浮窗:语音输入/输出、历史消息、麦克风
7
+ - 设置页:浏览器调试端口、聊天端口、悬浮窗样式
8
+
9
+ 完整用法和接入方式见仓库 README。
package/dsh.plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-watch-together",
3
3
  "description": "Watch a video together, in sync with the user's real playback: each segment arrives as one storyboard image plus its subtitle lines just before it ends, and the floating window carries spoken replies and live room audio.",
4
- "version": "0.3.0",
4
+ "version": "0.3.1",
5
5
  "entry": {
6
6
  "name": "dsh-watch-together",
7
7
  "inject": [
@@ -49,6 +49,30 @@ SHADOW = "#0a1018"
49
49
  FONT_FAMILY = "Microsoft YaHei UI"
50
50
  FONT_SIZE = 13
51
51
 
52
+ # 上面这些是**默认值**(2026-11 用户实报:13px 在 2560×1440 上偏小)。
53
+ # `window.py` 会把 `watch-window.json` 里的 danmakuFontSize / danmakuFont /
54
+ # danmakuFg / danmakuShadow 传进来覆盖,改配置即可,不必动代码。
55
+
56
+
57
+ def _color(value, fallback: str) -> str:
58
+ """只认 `#rrggbb`;写错的颜色退回默认色,别让弹幕因为一个笔误消失。"""
59
+ s = str(value or "").strip()
60
+ if len(s) == 7 and s[0] == "#":
61
+ try:
62
+ int(s[1:], 16)
63
+ return s
64
+ except ValueError:
65
+ pass
66
+ return fallback
67
+
68
+
69
+ def _clamp_size(value, fallback: int = FONT_SIZE) -> int:
70
+ try:
71
+ n = int(value)
72
+ except (TypeError, ValueError):
73
+ return fallback
74
+ return max(10, min(40, n))
75
+
52
76
 
53
77
  def _units(ch: str) -> float:
54
78
  """全角算 1,半角算 0.55 —— 按字符数截断会让英文短句显得很长。"""
@@ -73,7 +97,9 @@ class DanmakuLayer:
73
97
 
74
98
  def __init__(self, root: tk.Tk, *, screen_w: int, screen_h: int,
75
99
  edge: str = "top", lanes: int = 2, speed: float = SPEED,
76
- inset: int = 0):
100
+ inset: int = 0, font_family: str = FONT_FAMILY,
101
+ font_size: int = FONT_SIZE, fg: str = FG, shadow: str = SHADOW,
102
+ weight: str = "normal"):
77
103
  self.root = root
78
104
  self.screen_w = max(320, int(screen_w))
79
105
  self.screen_h = max(240, int(screen_h))
@@ -81,6 +107,18 @@ class DanmakuLayer:
81
107
  self.lanes = max(1, min(3, int(lanes)))
82
108
  self.speed = max(40.0, min(400.0, float(speed)))
83
109
  self.inset = max(0, int(inset))
110
+ self.font_family = str(font_family or "").strip() or FONT_FAMILY
111
+ self.font_size = _clamp_size(font_size)
112
+ self.weight = "bold" if str(weight).lower() == "bold" else "normal"
113
+ self.fg = _color(fg, FG)
114
+ self.shadow = _color(shadow, SHADOW)
115
+ # 轨道高度**必须按字体实际行高**算,不能拿字号估:Tk 的 size 是磅值,
116
+ # 30 磅在 96DPI 下约 40px 字、行高 58px,旧公式 max(26, 字号+13) 只给 43px,
117
+ # 第二轨的文字会被窗口底边裁成"上半截"(2026-11 用户实报)。
118
+ # 行高问字体自己(metrics),换字体/换 DPI 都不会再错。
119
+ self._font = tkfont.Font(root=root, family=self.font_family,
120
+ size=self.font_size, weight=self.weight)
121
+ self.lane_h = max(LANE_H, self._font.metrics("linespace") + 1)
84
122
 
85
123
  self._pending = []
86
124
  self._items = [] # [{main, shadow, x, w, lane}]
@@ -106,7 +144,6 @@ class DanmakuLayer:
106
144
  self.canvas.pack(fill="both", expand=True)
107
145
  # 自己量宽度而不是问 `canvas.bbox()`:刚 create_text 出来的 item 还没排过版,
108
146
  # bbox 可能给 None / 旧值,那样 GAP 会算小、同轨两条直接叠上。
109
- self._font = tkfont.Font(root=root, family=FONT_FAMILY, size=FONT_SIZE)
110
147
  self._resize()
111
148
  self._apply_ex_style()
112
149
 
@@ -114,7 +151,7 @@ class DanmakuLayer:
114
151
 
115
152
  @property
116
153
  def height(self) -> int:
117
- return self.lanes * LANE_H + 2 * PAD_Y
154
+ return self.lanes * self.lane_h + 2 * PAD_Y
118
155
 
119
156
  def _resize(self) -> None:
120
157
  y = (self.screen_h - self.height - self.inset) if self.edge == "bottom" else self.inset
@@ -138,8 +175,15 @@ class DanmakuLayer:
138
175
  except Exception as exc:
139
176
  print("danmaku exstyle failed", repr(exc), flush=True)
140
177
 
141
- def set_options(self, *, edge=None, lanes=None, speed=None, inset=None) -> None:
142
- """配置改了就地生效:不清屏、不重开窗口(用户的观感是"字变快了")。"""
178
+ def set_options(self, *, edge=None, lanes=None, speed=None, inset=None,
179
+ font_family=None, font_size=None, fg=None, shadow=None,
180
+ weight=None) -> None:
181
+ """配置改了就地生效:不清屏、不重开窗口(用户的观感是"字变快了")。
182
+
183
+ 颜色能原地 `itemconfigure`;字体/字号/字重不行 —— 已经飞出去的 item 用的是旧字体,
184
+ 量出来的宽度也是旧的,硬改会让同轨间距算错。所以这几种情况清掉在飞的几条
185
+ (下一次 push 用新样式),配置改动本来就是低频操作。
186
+ """
143
187
  if edge is not None:
144
188
  self.edge = "bottom" if str(edge).lower() == "bottom" else "top"
145
189
  if lanes is not None:
@@ -148,6 +192,25 @@ class DanmakuLayer:
148
192
  self.speed = max(40.0, min(400.0, float(speed)))
149
193
  if inset is not None:
150
194
  self.inset = max(0, int(inset))
195
+ if fg is not None:
196
+ self.fg = _color(fg, self.fg)
197
+ if shadow is not None:
198
+ self.shadow = _color(shadow, self.shadow)
199
+ family = (str(font_family).strip() or self.font_family) if font_family is not None else self.font_family
200
+ size = _clamp_size(font_size) if font_size is not None else self.font_size
201
+ want_weight = ("bold" if str(weight).lower() == "bold" else "normal") if weight is not None else self.weight
202
+ if (family, size, want_weight) != (self.font_family, self.font_size, self.weight):
203
+ self.font_family, self.font_size, self.weight = family, size, want_weight
204
+ self._font.configure(family=self.font_family, size=self.font_size, weight=self.weight)
205
+ # 行高跟着字体走(见 __init__ 的注释):换字号/字体/字重都要重算
206
+ self.lane_h = max(LANE_H, self._font.metrics("linespace") + 1)
207
+ for it in list(self._items):
208
+ self.canvas.delete(it["main"])
209
+ self.canvas.delete(it["shadow"])
210
+ self._items.clear()
211
+ for it in self._items:
212
+ self.canvas.itemconfigure(it["main"], fill=self.fg)
213
+ self.canvas.itemconfigure(it["shadow"], fill=self.shadow)
151
214
  self._resize()
152
215
 
153
216
  # ---- 输入 ----
@@ -187,10 +250,10 @@ class DanmakuLayer:
187
250
  if lane is None:
188
251
  return
189
252
  text = self._pending.pop(0)
190
- y = PAD_Y + lane * LANE_H
191
- kwargs = dict(text=text, anchor="nw", font=(FONT_FAMILY, FONT_SIZE))
192
- shadow = self.canvas.create_text(self.screen_w + 1, y + 1, fill=SHADOW, **kwargs)
193
- main = self.canvas.create_text(self.screen_w, y, fill=FG, **kwargs)
253
+ y = PAD_Y + lane * self.lane_h
254
+ kwargs = dict(text=text, anchor="nw", font=self._font)
255
+ shadow = self.canvas.create_text(self.screen_w + 1, y + 1, fill=self.shadow, **kwargs)
256
+ main = self.canvas.create_text(self.screen_w, y, fill=self.fg, **kwargs)
194
257
  width = self._font.measure(text)
195
258
  self._items.append({"main": main, "shadow": shadow, "x": float(self.screen_w),
196
259
  "w": width, "lane": lane})
@@ -344,8 +344,19 @@ class CaptureSource:
344
344
 
345
345
 
346
346
  def finish(geo: Geometry, panel: Image.Image) -> Image.Image:
347
- """贴二值圆角遮罩;缝隙/圆角外是 KEY,被 Tk 抠成透明。"""
348
- out = Image.new("RGB", (geo.width, geo.height), KEY)
347
+ """贴二值圆角遮罩。
348
+
349
+ Windows 上圆角/阴影边距填 KEY,由 Tk 的 ``-transparentcolor`` 抠成透明;
350
+ 其它平台没有这个属性(Tk 也不支持 per-pixel alpha,填真透明会变纯黑),
351
+ 所以边距直接填**面板自己的底色** —— 视觉上是一整块卡片,不再是黑框。
352
+ """
353
+ base = KEY
354
+ if os.name != "nt":
355
+ try:
356
+ base = panel.convert("RGB").resize((1, 1), Image.LANCZOS).getpixel((0, 0))
357
+ except Exception:
358
+ base = KEY
359
+ out = Image.new("RGB", (geo.width, geo.height), base)
349
360
  out.paste(panel.convert("RGB"), (0, 0), geo.mask_hard)
350
361
  return out
351
362
 
@@ -401,6 +401,11 @@ def danmaku_wanted(cfg=None) -> bool:
401
401
 
402
402
 
403
403
  def danmaku_options(cfg=None) -> dict:
404
+ """弹幕的几何 + 外观。六个键都能在 `watch-window.json` 里手改。
405
+
406
+ 外观三项(2026-11 加):13px 在 2560×1440 上偏小(用户实报),字号/字色/描边
407
+ 现在可配;非法值由 `danmaku.py` 那边退回默认,这里只做原样透传。
408
+ """
404
409
  if cfg is None:
405
410
  cfg = read_config()
406
411
  cfg = cfg or {}
@@ -413,9 +418,18 @@ def danmaku_options(cfg=None) -> dict:
413
418
  except (TypeError, ValueError):
414
419
  lanes = 2
415
420
  edge = str(cfg.get("danmakuEdge") or "top").strip().lower()
421
+ try:
422
+ font_size = int(cfg.get("danmakuFontSize"))
423
+ except (TypeError, ValueError):
424
+ font_size = None
416
425
  return {"edge": edge if edge in DANMAKU_EDGES else "top",
417
426
  "lanes": max(1, min(3, lanes)),
418
- "speed": max(40, min(400, speed))}
427
+ "speed": max(40, min(400, speed)),
428
+ "font_family": str(cfg.get("danmakuFont") or "").strip() or None,
429
+ "font_size": font_size,
430
+ "weight": str(cfg.get("danmakuFontWeight") or "").strip() or None,
431
+ "fg": str(cfg.get("danmakuFg") or "").strip() or None,
432
+ "shadow": str(cfg.get("danmakuShadow") or "").strip() or None}
419
433
 
420
434
 
421
435
  def append_user(text: str) -> None:
package/locale/en.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "Watch Together",
4
+ "description": "Watch a video in sync with the user's real playback: each segment delivers a storyboard image and timed lines, while the floating window speaks and listens.",
5
+ "detail": "docs/plugin.md"
6
+ }
7
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "meta": {
3
+ "title": "一起看",
4
+ "description": "跟着用户真实播放位置一起看视频:每段结束前交一张分镜图和带秒台词,悬浮窗负责说话和收音。",
5
+ "detail": "docs/plugin.zh.md"
6
+ }
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-watch-together",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Watch a video together, in sync with the user's real playback: every segment arrives as one storyboard image plus its subtitle lines just before it ends, while the floating window carries spoken replies and live room audio — picture and voice, not a transcript.",
5
5
  "keywords": [
6
6
  "dsh",
@@ -57,7 +57,9 @@
57
57
  "./recognition-interface": "./src/recognition-interface.js",
58
58
  "./tts-interface": "./src/tts-interface.js",
59
59
  "./window-interface": "./src/window-interface.js",
60
- "./window-protocol": "./src/window-protocol.js"
60
+ "./window-protocol": "./src/window-protocol.js",
61
+ "./package.json": "./package.json",
62
+ "./locale/*.json": "./locale/*.json"
61
63
  },
62
64
  "bin": {
63
65
  "dsh-watch": "./bin/watch.mjs",
@@ -70,6 +72,7 @@
70
72
  "extension",
71
73
  "scripts",
72
74
  "docs",
75
+ "locale",
73
76
  "cordis.patch.yml",
74
77
  "dsh.plugin.json",
75
78
  "README.md",
@@ -101,7 +104,7 @@
101
104
  "e2e": "node scripts/watch-e2e.mjs"
102
105
  },
103
106
  "dependencies": {
104
- "dsh-video-storyboard": "^0.6.0"
107
+ "dsh-video-storyboard": "^0.7.0"
105
108
  },
106
109
  "peerDependencies": {
107
110
  "@deepseek-ai/dsh-tools": ">=0.1.0-rc.7"
@@ -5,8 +5,6 @@
5
5
  * 原生 React 表单渲染,直接调用同一套 API,不再套 iframe。工具也仍返回同一地址。
6
6
  */
7
7
 
8
- import { randomBytes } from 'node:crypto';
9
-
10
8
  import { checkEnvironment } from './deps.js';
11
9
  import {
12
10
  configPaths, readVideoSettings, readVoiceSettings, readWatchSettings,
@@ -14,6 +12,7 @@ import {
14
12
  writeWindowSettings,
15
13
  } from './config.js';
16
14
  import { settingsPage } from './page.js';
15
+ import { settingsToken } from './token.js';
17
16
 
18
17
  const PAGE_PATH = '/dsh-watch-together/settings';
19
18
  const API_PREFIX = PAGE_PATH + '/api';
@@ -76,7 +75,7 @@ function statePayload(env) {
76
75
  export function createSettingsPage({ ctx, env = process.env, log = () => {} } = {}) {
77
76
  const webServer = ctx?.get?.('webServer');
78
77
  if (!webServer || typeof webServer.register !== 'function') return null;
79
- const token = randomBytes(32).toString('hex');
78
+ const token = settingsToken(env);
80
79
  let disposed = false;
81
80
 
82
81
  const handle = async (req, res) => {
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 设置页 token:**跨进程重启保持稳定**。
3
+ *
4
+ * 旧实现每次 createSettingsPage() 都 randomBytes(32)。宿主重启后 token 变了,
5
+ * 而浏览器里已经打开的那一页仍拿着旧的注入 token,设置表单就会显示“token 无效”。
6
+ * 把 token 落到 $DSH_HOME 下一次启动继续用,旧页面不用刷新也能继续保存。
7
+ */
8
+
9
+ import { randomBytes } from 'node:crypto';
10
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
11
+ import { homedir } from 'node:os';
12
+ import { dirname, join } from 'node:path';
13
+
14
+ const TOKEN_NAME = 'watch-settings-token';
15
+
16
+ export function settingsTokenPath(env = process.env) {
17
+ const home = env.DSH_HOME || join(env.USERPROFILE || env.HOME || homedir(), '.dsh');
18
+ return join(home, TOKEN_NAME);
19
+ }
20
+
21
+ export function settingsToken(env = process.env) {
22
+ const path = settingsTokenPath(env);
23
+ try {
24
+ const raw = readFileSync(path, 'utf8').trim();
25
+ if (/^[a-f0-9]{64}$/i.test(raw)) return raw;
26
+ } catch { /* 没建过或读不了,下面生成 */ }
27
+ const token = randomBytes(32).toString('hex');
28
+ try {
29
+ mkdirSync(dirname(path), { recursive: true });
30
+ writeFileSync(path, token + '\n', { mode: 0o600 });
31
+ } catch { /* 写不进去就用这次进程内的 token */ }
32
+ return token;
33
+ }