dsh-fish-soul 0.18.17 → 0.18.19
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 +1 -1
- package/lib/douyin-social.js +106 -21
- package/package.json +2 -2
package/README.md
CHANGED
package/lib/douyin-social.js
CHANGED
|
@@ -299,13 +299,17 @@ export const COMMENT_STATE_JS = `(() => {
|
|
|
299
299
|
};
|
|
300
300
|
})()`;
|
|
301
301
|
|
|
302
|
-
/**
|
|
302
|
+
/** 编辑页上的「选择音乐 / 添加音乐」入口(页面有多个同名节点,取最后一个——真正可点的那颗;优先取其按钮容器并避免在视口内时不必要的滚动)。 */
|
|
303
303
|
const MUSIC_ENTRY_JS = String.raw`(() => {
|
|
304
|
-
const els = [...document.querySelectorAll('div, span, button')].filter((x) => x.children.length === 0 &&
|
|
304
|
+
const els = [...document.querySelectorAll('div, span, button')].filter((x) => x.children.length === 0 && /^(选择音乐|添加音乐)$/.test((x.innerText || '').trim()));
|
|
305
305
|
const el = els[els.length - 1];
|
|
306
306
|
if (!el) return null;
|
|
307
|
-
el.
|
|
308
|
-
|
|
307
|
+
const target = el.closest('[class*="preview-button"], button') || el;
|
|
308
|
+
let r = target.getBoundingClientRect();
|
|
309
|
+
if (r.top < 0 || r.bottom > window.innerHeight || r.left < 0 || r.right > window.innerWidth) {
|
|
310
|
+
target.scrollIntoView({ block: 'center', behavior: 'instant' });
|
|
311
|
+
r = target.getBoundingClientRect();
|
|
312
|
+
}
|
|
309
313
|
return r.width && r.height ? { x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) } : null;
|
|
310
314
|
})()`;
|
|
311
315
|
|
|
@@ -435,26 +439,35 @@ async function findApplyButton(br, timing, hoverAt) {
|
|
|
435
439
|
if (!quad || quad.length < 8) continue;
|
|
436
440
|
const x = Math.round((quad[0] + quad[2] + quad[4] + quad[6]) / 4);
|
|
437
441
|
const y = Math.round((quad[1] + quad[3] + quad[5] + quad[7]) / 4);
|
|
438
|
-
if (x > 0 && y > 0) candidates.push({ x, y });
|
|
442
|
+
if (x > 0 && y > 0) candidates.push({ x, y, backendNodeId: n.backendDOMNodeId });
|
|
439
443
|
}
|
|
440
444
|
return candidates.length ? { ok: true, candidates } : { ok: false, reason: 'not-found' };
|
|
441
445
|
}
|
|
442
446
|
|
|
443
447
|
/**
|
|
444
|
-
*
|
|
448
|
+
* 这个按钮节点(或坐标上的元素),是不是落在「某个含该歌名的歌卡」里面?
|
|
445
449
|
*
|
|
446
450
|
* 为什么要这一步:AX 查询的范围是**整棵树**,命中的是 DOM 顺序第一个可见的「使用」。
|
|
447
451
|
* 页面别处只要有一个可见的「使用」按钮,就会点到它 —— 而且后续歌名确认会失败,
|
|
448
452
|
* 报出来的却是「已点击使用,但编辑页未确认显示歌名」,把错误指向了别处。
|
|
449
453
|
* 旧代码用「在目标卡的子树里找按钮」天然避开了这件事,换成语义定位后必须显式补回来。
|
|
450
454
|
*
|
|
455
|
+
* 🔴 优先直接用 AX 节点的 `backendNodeId` 往上查祖先链:
|
|
456
|
+
* 不用 `DOM.getNodeForLocation(x, y)` 去反查 —— 真机上音乐抽屉是 fixed 浮层,
|
|
457
|
+
* 鼠标移开或 hover 抖动的一帧里按钮可能短暂变成 `visibility: hidden` / `pointer-events: none`,
|
|
458
|
+
* 或者被子层盖住,`getNodeForLocation` 就会打穿到抽屉底板或背景层,误报「不在选中的那首歌上」。
|
|
459
|
+
*
|
|
451
460
|
* @returns {Promise<boolean>} 读失败也返回 false(宁可这次不发,也不点错)
|
|
452
461
|
*/
|
|
453
|
-
async function pointBelongsToCard(br,
|
|
454
|
-
|
|
455
|
-
if (!
|
|
462
|
+
async function pointBelongsToCard(br, cand, music, timing) {
|
|
463
|
+
let backendNodeId = cand?.backendNodeId;
|
|
464
|
+
if (!backendNodeId && Number.isFinite(cand?.x) && Number.isFinite(cand?.y)) {
|
|
465
|
+
const hit = await br.send('DOM.getNodeForLocation', { x: cand.x, y: cand.y, includeUserAgentShadowDOM: false }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
|
|
466
|
+
backendNodeId = hit?.backendNodeId;
|
|
467
|
+
}
|
|
468
|
+
if (!backendNodeId) return false;
|
|
456
469
|
// describeNode 拿不到父链,改用 Runtime 从该节点往上走。
|
|
457
|
-
const resolved = await br.send('DOM.resolveNode', { backendNodeId
|
|
470
|
+
const resolved = await br.send('DOM.resolveNode', { backendNodeId }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
|
|
458
471
|
const objectId = resolved?.object?.objectId;
|
|
459
472
|
if (!objectId) return false;
|
|
460
473
|
try {
|
|
@@ -466,9 +479,11 @@ async function pointBelongsToCard(br, x, y, music, timing) {
|
|
|
466
479
|
const songSel = '[class*="song-name"]';
|
|
467
480
|
for (let p = this; p && p !== document.body; p = p.parentElement) {
|
|
468
481
|
if (!p.querySelectorAll) continue;
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
482
|
+
const names = p.querySelectorAll(songSel);
|
|
483
|
+
if (names.length === 1) {
|
|
484
|
+
const sn = names[0];
|
|
485
|
+
const text = norm(sn.innerText || sn.textContent || '');
|
|
486
|
+
if (text === target || (target.length >= 2 && text.includes(target))) return true;
|
|
472
487
|
}
|
|
473
488
|
}
|
|
474
489
|
return false;
|
|
@@ -544,6 +559,8 @@ export async function ensurePageAlive(br, { timeoutMs = 3000, reload = true } =
|
|
|
544
559
|
async function clickMusicEntry(br, timing) {
|
|
545
560
|
const sel = await br.eval(MUSIC_ENTRY_JS, { timeoutMs: timing.evalTimeoutMs }).catch(() => null);
|
|
546
561
|
if (!sel) return false;
|
|
562
|
+
await br.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: sel.x, y: sel.y }, br.sessionId).catch(() => {});
|
|
563
|
+
await sleep(150);
|
|
547
564
|
await realClick(br, sel.x, sel.y);
|
|
548
565
|
await sleep(1200);
|
|
549
566
|
return true;
|
|
@@ -617,19 +634,52 @@ async function pickNoteMusic(br, music, { allowDuplicate = false, timing = PAGE_
|
|
|
617
634
|
if (r.reason === 'read-failed') throw new Error(r.error); // 读失败要透出来,不能当「没找到」
|
|
618
635
|
return r.ok ? r : null;
|
|
619
636
|
}, { tries: 8, gapMs: 500, budgetMs: timing.waitBudgetMs });
|
|
620
|
-
if (!found?.ok) return { ok: false, error: '歌曲卡片悬停后没有出现使用按钮' };
|
|
621
|
-
// 逐个候选做归属校验:AX 命中的是整棵树,页面别处也可能有可见的「使用」。
|
|
622
637
|
let btn = null;
|
|
623
|
-
|
|
624
|
-
|
|
638
|
+
if (found?.ok) {
|
|
639
|
+
// 逐个候选做归属校验:AX 命中的是整棵树,页面别处也可能有可见的「使用」。
|
|
640
|
+
for (const c of found.candidates) {
|
|
641
|
+
if (await pointBelongsToCard(br, c, music, timing)) { btn = c; break; }
|
|
642
|
+
}
|
|
625
643
|
}
|
|
626
|
-
if (!btn)
|
|
644
|
+
if (!btn) {
|
|
645
|
+
// 兜底:直接在该歌卡 DOM 子树里找文本为「使用」的按钮或行内节点(防 AX 树漏掉或虚拟列表重排)
|
|
646
|
+
const domBtn = await br.eval(`(() => { ${MUSIC_DOM_JS}
|
|
647
|
+
const matches = rows.filter(row => nameOf(row) === ${JSON.stringify(music)});
|
|
648
|
+
const target = matches.length === 1 || ${allowDuplicate ? 'true' : 'false'} ? matches[0] : null;
|
|
649
|
+
if (!target) return null;
|
|
650
|
+
const el = [...target.querySelectorAll('button, [role="button"], span, div')]
|
|
651
|
+
.find(x => (x.innerText || x.textContent || '').trim() === '使用' && x.children.length <= 1);
|
|
652
|
+
if (!el) return null;
|
|
653
|
+
const r = el.getBoundingClientRect();
|
|
654
|
+
return r.width > 0 && r.height > 0 ? { x: Math.round(r.left + r.width / 2), y: Math.round(r.top + r.height / 2) } : { x: card.x, y: card.y };
|
|
655
|
+
})()`, { timeoutMs: timing.evalTimeoutMs }).catch(() => null);
|
|
656
|
+
if (domBtn) btn = domBtn;
|
|
657
|
+
}
|
|
658
|
+
if (!btn) return { ok: false, error: found?.ok ? '找到的「使用」按钮不在选中的那首歌上(页面结构变了?)' : '歌曲卡片悬停后没有出现使用按钮' };
|
|
627
659
|
// 点击前再 hover 到按钮上:查询与点击之间可能已过几轮重试,按钮可能重新 hidden。
|
|
628
660
|
// ⚠️ hover 与按下之间必须隔一帧:按钮靠 CSS :hover 从 visibility:hidden 变可见,
|
|
629
661
|
// 紧接着按下会落在「刚变可见」的瞬间、事件不派发(实测:点了没反应且不报错)。
|
|
630
662
|
await br.send('Input.dispatchMouseEvent', { type: 'mouseMoved', x: btn.x, y: btn.y }, br.sessionId).catch(() => {});
|
|
631
663
|
await sleep(250);
|
|
632
664
|
await realClick(br, btn.x, btn.y);
|
|
665
|
+
if (btn.backendNodeId) {
|
|
666
|
+
// 真机容错:getBoxModel 偶尔返回的是内层 span 偏移坐标(甚至超出了 400px 卡片右边界),
|
|
667
|
+
// 或者窗口在后台时 mousePressed 没触发 React 合成 onClick —— 仅在抽屉仍开着时用该节点的 DOM click 补一道。
|
|
668
|
+
await sleep(250);
|
|
669
|
+
const stillOpen = await br.eval(MUSIC_OPEN_JS, { timeoutMs: timing.evalTimeoutMs }).catch(() => false);
|
|
670
|
+
if (stillOpen) {
|
|
671
|
+
const resolved = await br.send('DOM.resolveNode', { backendNodeId: btn.backendNodeId }, br.sessionId, timing.evalTimeoutMs).catch(() => null);
|
|
672
|
+
const objectId = resolved?.object?.objectId;
|
|
673
|
+
if (objectId) {
|
|
674
|
+
await br.send('Runtime.callFunctionOn', {
|
|
675
|
+
objectId,
|
|
676
|
+
functionDeclaration: `function () { if (typeof this.click === 'function') this.click(); }`,
|
|
677
|
+
returnByValue: true
|
|
678
|
+
}, br.sessionId, timing.evalTimeoutMs).catch(() => {});
|
|
679
|
+
await br.send('Runtime.releaseObject', { objectId }, br.sessionId, timing.evalTimeoutMs).catch(() => {});
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
}
|
|
633
683
|
const verified = await waitFor(() => br.eval(`(() => {
|
|
634
684
|
const want = ${JSON.stringify(music)}.replace(/\\s+/g, '');
|
|
635
685
|
const visible = el => { const r = el.getBoundingClientRect(); const s = getComputedStyle(el); return r.width > 0 && r.height > 0 && s.visibility !== 'hidden' && s.display !== 'none'; };
|
|
@@ -646,6 +696,12 @@ async function pickNoteMusic(br, music, { allowDuplicate = false, timing = PAGE_
|
|
|
646
696
|
if (text.length <= 250 && text.replace(/\\s+/g, '').includes(want)) return true;
|
|
647
697
|
}
|
|
648
698
|
}
|
|
699
|
+
const binders = [...document.querySelectorAll('[class*="music-binder"], [class*="music-text"]')].filter(visible);
|
|
700
|
+
for (const b of binders) {
|
|
701
|
+
if (b.closest('.semi-sidesheet, [class*="music-collection-container"]')) continue;
|
|
702
|
+
const text = (b.innerText || '').trim();
|
|
703
|
+
if (text.length <= 250 && text.replace(/\\s+/g, '').includes(want)) return true;
|
|
704
|
+
}
|
|
649
705
|
return false;
|
|
650
706
|
})()`, { timeoutMs: timing.evalTimeoutMs }).catch(() => false), { tries: 10, gapMs: 500, budgetMs: timing.waitBudgetMs });
|
|
651
707
|
return verified ? { ok: true } : { ok: false, error: '已点击使用,但编辑页未确认显示歌名' };
|
|
@@ -809,11 +865,18 @@ export function douyinSocialDriver(host, timing = {}) {
|
|
|
809
865
|
/**
|
|
810
866
|
* 点「发布」并等它落地。
|
|
811
867
|
*
|
|
868
|
+
* music(可选):有些视频(如 OpenMotion 渲染或无声视频)要在创作者中心配 BGM;
|
|
869
|
+
* 传入歌名时先在当前编辑页调用 pickNoteMusic 选歌确认。
|
|
870
|
+
*
|
|
812
871
|
* 成功判据要**两个都**满足:地址跳到 content/manage,且页面上出现「已发布 / 发布成功」。
|
|
813
872
|
* 只看地址会把「跳到作品管理页、其实没发出去」当成成功。
|
|
814
873
|
*/
|
|
815
|
-
async publishVideo({ beforeSubmit } = {}) {
|
|
874
|
+
async publishVideo({ music, allowDuplicate = false, beforeSubmit } = {}) {
|
|
816
875
|
const br = b();
|
|
876
|
+
if (music) {
|
|
877
|
+
const picked = await pickNoteMusic(br, String(music), { allowDuplicate, timing: tm });
|
|
878
|
+
if (!picked.ok) return { ok: false, code: 'MUSIC_FAILED', error: `配乐失败,未发布:${picked.error}` };
|
|
879
|
+
}
|
|
817
880
|
const preVerify = await verifyKind();
|
|
818
881
|
if (preVerify) return { ok: false, code: 'NEEDS_VERIFY', error: '抖音要验证(短信 / 滑块)才能发' };
|
|
819
882
|
const hasBtn = await br.eval(String.raw`(() => [...document.querySelectorAll('button')].some((x) => (x.innerText || '').trim() === '发布' && !x.disabled))()`, { timeoutMs: tm.evalTimeoutMs }).catch(() => false);
|
|
@@ -1273,6 +1336,7 @@ export class DouyinSocial extends SocialBase {
|
|
|
1273
1336
|
// 文件已经生成 → 先记到任务上(崩了也知道视频在哪,别再花一次钱)
|
|
1274
1337
|
this.postJobs.prepared(jobId, out.file, '');
|
|
1275
1338
|
let r = null;
|
|
1339
|
+
let song = '';
|
|
1276
1340
|
try {
|
|
1277
1341
|
// 浏览器锁的时长从转码预算**推导**,不写死常量:
|
|
1278
1342
|
// exclusive 超时只把错误给调用方、锁要等 fn 真 settle 才放(见 lib/channels/douyin.js),
|
|
@@ -1281,7 +1345,28 @@ export class DouyinSocial extends SocialBase {
|
|
|
1281
1345
|
r = await this.host.exclusive('发抖音视频', async () => {
|
|
1282
1346
|
const pre = await this.driver.prepareVideo({ title: noteTitle(text), text, file: out.file });
|
|
1283
1347
|
if (!pre?.ok) return pre;
|
|
1284
|
-
|
|
1348
|
+
try {
|
|
1349
|
+
// OpenMotion 本地渲染或无声视频:如果创作者中心编辑页有「选择音乐」,顺手从推荐里配一首 BGM;
|
|
1350
|
+
// 视频已花钱/耗时生成,页面没给选音乐入口或没挑出来时退回原声发布,不让整条视频作废。
|
|
1351
|
+
let allowDuplicate = false;
|
|
1352
|
+
if (cfg.provider === 'openmotion' && typeof this.driver.listRecommendedMusic === 'function') {
|
|
1353
|
+
const list = await this.driver.listRecommendedMusic().catch(() => null);
|
|
1354
|
+
if (list?.ok && Array.isArray(list.songs) && list.songs.length) {
|
|
1355
|
+
const choice = await this.chooseMusic(text, list.songs, list.counts).catch(() => ({ song: '', duplicate: false }));
|
|
1356
|
+
if (choice.song) {
|
|
1357
|
+
song = choice.song;
|
|
1358
|
+
allowDuplicate = choice.duplicate;
|
|
1359
|
+
this.postJobs.prepared(jobId, out.file, song);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
return await this.driver.publishVideo({
|
|
1364
|
+
...(song ? { music: song, allowDuplicate } : {}),
|
|
1365
|
+
beforeSubmit: () => this.postJobs.submitting(jobId)
|
|
1366
|
+
});
|
|
1367
|
+
} finally {
|
|
1368
|
+
try { await this.driver.closeMusicPanel?.(); } catch { /* 关不掉就算了 */ }
|
|
1369
|
+
}
|
|
1285
1370
|
}, { maxMs: PAGE_TIMING.transcodeBudgetMs + VIDEO_LOCK_MARGIN_MS });
|
|
1286
1371
|
} finally {
|
|
1287
1372
|
// 发完或发布失败都清一下旧的 mp4 / 过期 .part:视频单条百 MB,失败路径也不能在盘上无限堆。
|
|
@@ -1292,7 +1377,7 @@ export class DouyinSocial extends SocialBase {
|
|
|
1292
1377
|
if (r?.code === 'NOT_LOGGED_IN') this.notify('douyin.creator', '想在抖音发视频,但创作者中心没登录:在抖音浏览器里打开 creator.douyin.com 登录一次就好');
|
|
1293
1378
|
if (!r?.ok) throw new Error(r?.error ?? '没发出去');
|
|
1294
1379
|
this.verifyCleared(); // 这次没被拦:验证计数清零
|
|
1295
|
-
this.note('post', { title: this.label, reason: '发了一条视频' });
|
|
1380
|
+
this.note('post', { title: this.label, reason: song ? `发了一条视频(已配乐《${song}》)` : '发了一条视频' });
|
|
1296
1381
|
this.notify('douyin.creator', null);
|
|
1297
1382
|
return '';
|
|
1298
1383
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-fish-soul",
|
|
3
|
-
"version": "0.18.
|
|
4
|
-
"description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu ,v0.18.
|
|
3
|
+
"version": "0.18.19",
|
|
4
|
+
"description": "鱼 · 人格、按人记忆(可纠正、有印象、能导入旧聊天记录)、日程自走与主动开口,直连 SnowLuma 收发 QQ(群里会自己插话),B站 / 抖音小号私信与自己刷视频;按功能选模型并统计用量花费,能听会说 QQ 语音、收藏表情包、学群里的梗,可选上网查;心情影响说话、去 AI 味、每个群的设定、按聊天选模型、每晚写日记、每周记忆存档与可选周记(DSH 插件,单角色 feiyu ,v0.18.19)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
7
7
|
"files": [
|