dsh-fish-soul 0.18.17 → 0.18.18

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  让一个 QQ 小号背后有"同一个人":固定人格、按人记记忆、有自己的生活节奏、会主动开口;同一个"她"同时出现在 QQ、B站、抖音。
4
4
 
5
- DSH 插件(单角色 `feiyu`)。版本 **0.18.17**。
5
+ DSH 插件(单角色 `feiyu`)。版本 **0.18.18**。
6
6
 
7
7
  QQ 交流群:**1125962189**
8
8
 
@@ -435,26 +435,35 @@ async function findApplyButton(br, timing, hoverAt) {
435
435
  if (!quad || quad.length < 8) continue;
436
436
  const x = Math.round((quad[0] + quad[2] + quad[4] + quad[6]) / 4);
437
437
  const y = Math.round((quad[1] + quad[3] + quad[5] + quad[7]) / 4);
438
- if (x > 0 && y > 0) candidates.push({ x, y });
438
+ if (x > 0 && y > 0) candidates.push({ x, y, backendNodeId: n.backendDOMNodeId });
439
439
  }
440
440
  return candidates.length ? { ok: true, candidates } : { ok: false, reason: 'not-found' };
441
441
  }
442
442
 
443
443
  /**
444
- * 这个坐标上的元素,是不是落在「某个含该歌名的歌卡」里面?
444
+ * 这个按钮节点(或坐标上的元素),是不是落在「某个含该歌名的歌卡」里面?
445
445
  *
446
446
  * 为什么要这一步:AX 查询的范围是**整棵树**,命中的是 DOM 顺序第一个可见的「使用」。
447
447
  * 页面别处只要有一个可见的「使用」按钮,就会点到它 —— 而且后续歌名确认会失败,
448
448
  * 报出来的却是「已点击使用,但编辑页未确认显示歌名」,把错误指向了别处。
449
449
  * 旧代码用「在目标卡的子树里找按钮」天然避开了这件事,换成语义定位后必须显式补回来。
450
450
  *
451
+ * 🔴 优先直接用 AX 节点的 `backendNodeId` 往上查祖先链:
452
+ * 不用 `DOM.getNodeForLocation(x, y)` 去反查 —— 真机上音乐抽屉是 fixed 浮层,
453
+ * 鼠标移开或 hover 抖动的一帧里按钮可能短暂变成 `visibility: hidden` / `pointer-events: none`,
454
+ * 或者被子层盖住,`getNodeForLocation` 就会打穿到抽屉底板或背景层,误报「不在选中的那首歌上」。
455
+ *
451
456
  * @returns {Promise<boolean>} 读失败也返回 false(宁可这次不发,也不点错)
452
457
  */
453
- async function pointBelongsToCard(br, x, y, music, timing) {
454
- const hit = await br.send('DOM.getNodeForLocation', { x, y, includeUserAgentShadowDOM: false }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
455
- if (!hit?.backendNodeId) return false;
458
+ async function pointBelongsToCard(br, cand, music, timing) {
459
+ let backendNodeId = cand?.backendNodeId;
460
+ if (!backendNodeId && Number.isFinite(cand?.x) && Number.isFinite(cand?.y)) {
461
+ const hit = await br.send('DOM.getNodeForLocation', { x: cand.x, y: cand.y, includeUserAgentShadowDOM: false }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
462
+ backendNodeId = hit?.backendNodeId;
463
+ }
464
+ if (!backendNodeId) return false;
456
465
  // describeNode 拿不到父链,改用 Runtime 从该节点往上走。
457
- const resolved = await br.send('DOM.resolveNode', { backendNodeId: hit.backendNodeId }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
466
+ const resolved = await br.send('DOM.resolveNode', { backendNodeId }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
458
467
  const objectId = resolved?.object?.objectId;
459
468
  if (!objectId) return false;
460
469
  try {
@@ -466,9 +475,11 @@ async function pointBelongsToCard(br, x, y, music, timing) {
466
475
  const songSel = '[class*="song-name"]';
467
476
  for (let p = this; p && p !== document.body; p = p.parentElement) {
468
477
  if (!p.querySelectorAll) continue;
469
- if (p.querySelectorAll(songSel).length === 1) {
470
- const sn = p.querySelector(songSel);
471
- if (sn && norm(sn.innerText) === target) return true;
478
+ const names = p.querySelectorAll(songSel);
479
+ if (names.length === 1) {
480
+ const sn = names[0];
481
+ const text = norm(sn.innerText || sn.textContent || '');
482
+ if (text === target || (target.length >= 2 && text.includes(target))) return true;
472
483
  }
473
484
  }
474
485
  return false;
@@ -617,13 +628,28 @@ async function pickNoteMusic(br, music, { allowDuplicate = false, timing = PAGE_
617
628
  if (r.reason === 'read-failed') throw new Error(r.error); // 读失败要透出来,不能当「没找到」
618
629
  return r.ok ? r : null;
619
630
  }, { tries: 8, gapMs: 500, budgetMs: timing.waitBudgetMs });
620
- if (!found?.ok) return { ok: false, error: '歌曲卡片悬停后没有出现使用按钮' };
621
- // 逐个候选做归属校验:AX 命中的是整棵树,页面别处也可能有可见的「使用」。
622
631
  let btn = null;
623
- for (const c of found.candidates) {
624
- if (await pointBelongsToCard(br, c.x, c.y, music, timing)) { btn = c; break; }
632
+ if (found?.ok) {
633
+ // 逐个候选做归属校验:AX 命中的是整棵树,页面别处也可能有可见的「使用」。
634
+ for (const c of found.candidates) {
635
+ if (await pointBelongsToCard(br, c, music, timing)) { btn = c; break; }
636
+ }
637
+ }
638
+ if (!btn) {
639
+ // 兜底:直接在该歌卡 DOM 子树里找文本为「使用」的按钮或行内节点(防 AX 树漏掉或虚拟列表重排)
640
+ const domBtn = await br.eval(`(() => { ${MUSIC_DOM_JS}
641
+ const matches = rows.filter(row => nameOf(row) === ${JSON.stringify(music)});
642
+ const target = matches.length === 1 || ${allowDuplicate ? 'true' : 'false'} ? matches[0] : null;
643
+ if (!target) return null;
644
+ const el = [...target.querySelectorAll('button, [role="button"], span, div')]
645
+ .find(x => (x.innerText || x.textContent || '').trim() === '使用' && x.children.length <= 1);
646
+ if (!el) return null;
647
+ const r = el.getBoundingClientRect();
648
+ return r.width > 0 && r.height > 0 ? { x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) } : null;
649
+ })()`, { timeoutMs: timing.evalTimeoutMs }).catch(() => null);
650
+ if (domBtn) btn = domBtn;
625
651
  }
626
- if (!btn) return { ok: false, error: '找到的「使用」按钮不在选中的那首歌上(页面结构变了?)' };
652
+ if (!btn) return { ok: false, error: found?.ok ? '找到的「使用」按钮不在选中的那首歌上(页面结构变了?)' : '歌曲卡片悬停后没有出现使用按钮' };
627
653
  // 点击前再 hover 到按钮上:查询与点击之间可能已过几轮重试,按钮可能重新 hidden。
628
654
  // ⚠️ hover 与按下之间必须隔一帧:按钮靠 CSS :hover 从 visibility:hidden 变可见,
629
655
  // 紧接着按下会落在「刚变可见」的瞬间、事件不派发(实测:点了没反应且不报错)。
@@ -809,11 +835,18 @@ export function douyinSocialDriver(host, timing = {}) {
809
835
  /**
810
836
  * 点「发布」并等它落地。
811
837
  *
838
+ * music(可选):有些视频(如 OpenMotion 渲染或无声视频)要在创作者中心配 BGM;
839
+ * 传入歌名时先在当前编辑页调用 pickNoteMusic 选歌确认。
840
+ *
812
841
  * 成功判据要**两个都**满足:地址跳到 content/manage,且页面上出现「已发布 / 发布成功」。
813
842
  * 只看地址会把「跳到作品管理页、其实没发出去」当成成功。
814
843
  */
815
- async publishVideo({ beforeSubmit } = {}) {
844
+ async publishVideo({ music, allowDuplicate = false, beforeSubmit } = {}) {
816
845
  const br = b();
846
+ if (music) {
847
+ const picked = await pickNoteMusic(br, String(music), { allowDuplicate, timing: tm });
848
+ if (!picked.ok) return { ok: false, code: 'MUSIC_FAILED', error: `配乐失败,未发布:${picked.error}` };
849
+ }
817
850
  const preVerify = await verifyKind();
818
851
  if (preVerify) return { ok: false, code: 'NEEDS_VERIFY', error: '抖音要验证(短信 / 滑块)才能发' };
819
852
  const hasBtn = await br.eval(String.raw`(() => [...document.querySelectorAll('button')].some((x) => (x.innerText || '').trim() === '发布' && !x.disabled))()`, { timeoutMs: tm.evalTimeoutMs }).catch(() => false);
@@ -1273,6 +1306,7 @@ export class DouyinSocial extends SocialBase {
1273
1306
  // 文件已经生成 → 先记到任务上(崩了也知道视频在哪,别再花一次钱)
1274
1307
  this.postJobs.prepared(jobId, out.file, '');
1275
1308
  let r = null;
1309
+ let song = '';
1276
1310
  try {
1277
1311
  // 浏览器锁的时长从转码预算**推导**,不写死常量:
1278
1312
  // exclusive 超时只把错误给调用方、锁要等 fn 真 settle 才放(见 lib/channels/douyin.js),
@@ -1281,7 +1315,28 @@ export class DouyinSocial extends SocialBase {
1281
1315
  r = await this.host.exclusive('发抖音视频', async () => {
1282
1316
  const pre = await this.driver.prepareVideo({ title: noteTitle(text), text, file: out.file });
1283
1317
  if (!pre?.ok) return pre;
1284
- return await this.driver.publishVideo({ beforeSubmit: () => this.postJobs.submitting(jobId) });
1318
+ try {
1319
+ // OpenMotion 本地渲染或无声视频:如果创作者中心编辑页有「选择音乐」,顺手从推荐里配一首 BGM;
1320
+ // 视频已花钱/耗时生成,页面没给选音乐入口或没挑出来时退回原声发布,不让整条视频作废。
1321
+ let allowDuplicate = false;
1322
+ if (cfg.provider === 'openmotion' && typeof this.driver.listRecommendedMusic === 'function') {
1323
+ const list = await this.driver.listRecommendedMusic().catch(() => null);
1324
+ if (list?.ok && Array.isArray(list.songs) && list.songs.length) {
1325
+ const choice = await this.chooseMusic(text, list.songs, list.counts).catch(() => ({ song: '', duplicate: false }));
1326
+ if (choice.song) {
1327
+ song = choice.song;
1328
+ allowDuplicate = choice.duplicate;
1329
+ this.postJobs.prepared(jobId, out.file, song);
1330
+ }
1331
+ }
1332
+ }
1333
+ return await this.driver.publishVideo({
1334
+ ...(song ? { music: song, allowDuplicate } : {}),
1335
+ beforeSubmit: () => this.postJobs.submitting(jobId)
1336
+ });
1337
+ } finally {
1338
+ try { await this.driver.closeMusicPanel?.(); } catch { /* 关不掉就算了 */ }
1339
+ }
1285
1340
  }, { maxMs: PAGE_TIMING.transcodeBudgetMs + VIDEO_LOCK_MARGIN_MS });
1286
1341
  } finally {
1287
1342
  // 发完或发布失败都清一下旧的 mp4 / 过期 .part:视频单条百 MB,失败路径也不能在盘上无限堆。
@@ -1292,7 +1347,7 @@ export class DouyinSocial extends SocialBase {
1292
1347
  if (r?.code === 'NOT_LOGGED_IN') this.notify('douyin.creator', '想在抖音发视频,但创作者中心没登录:在抖音浏览器里打开 creator.douyin.com 登录一次就好');
1293
1348
  if (!r?.ok) throw new Error(r?.error ?? '没发出去');
1294
1349
  this.verifyCleared(); // 这次没被拦:验证计数清零
1295
- this.note('post', { title: this.label, reason: '发了一条视频' });
1350
+ this.note('post', { title: this.label, reason: song ? `发了一条视频(已配乐《${song}》)` : '发了一条视频' });
1296
1351
  this.notify('douyin.creator', null);
1297
1352
  return '';
1298
1353
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-fish-soul",
3
- "version": "0.18.17",
4
- "description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu ,v0.18.17)",
3
+ "version": "0.18.18",
4
+ "description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu ,v0.18.18)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
7
7
  "files": [