@cloud411716/fancy-webnovel 4.22.0 → 4.22.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/douyin-plugin.md
CHANGED
|
@@ -201,7 +201,7 @@ id / kind / subkind / name / tags / genres / note / source
|
|
|
201
201
|
滚动、懒加载或页面动画截到残缺图片。
|
|
202
202
|
- 图文作品的轮播可以混合图片页和视频页。视频页会下载该页短视频,15 秒以内每 0.2 秒采样、15–60 秒每 0.5 秒采样,
|
|
203
203
|
再按稳定画面段选帧并拼成一张关键帧图交给 LLM;这样快速切换的画面和动态字幕/标语不会被封面漏掉。
|
|
204
|
-
- 图文轮播必须以页面计数器 `当前页/总页数` 为准:页面刚打开时 DOM 里可能只挂载 1–2 个 `.dySwiperSlide
|
|
204
|
+
- 图文轮播必须以页面计数器 `当前页/总页数` 为准:页面刚打开时 DOM 里可能只挂载 1–2 个 `.dySwiperSlide`,不能当作总页数。插件会以第一个 slide 所在的播放器容器为锚点,按 `X/Y` 文本定位计数器,并从计数器相邻元素取得上一页/下一页按钮,不依赖抖音会变化的哈希类名;逐页推进并等待当前页内容切换完成,确保 `note.json` 记录所有页。
|
|
205
205
|
- 独立视频作品会先尝试下载原片并用 ffmpeg 抽帧;下载失败时退化为播放器元素截图。
|
|
206
206
|
视频时长超过 1 分钟直接跳过;前 5 秒与网文创作无关也跳过。
|
|
207
207
|
- 场景切换点本身常是过渡虚影。插件会在密集采样后用 ffmpeg blurdetect 给每帧打分,在每个稳定画面段的清晰中段选一帧,避免把文字尚未完全出现的模糊帧交给 LLM。
|
package/package.json
CHANGED
|
@@ -84,19 +84,63 @@ async function activeSlideInfo(page) {
|
|
|
84
84
|
|
|
85
85
|
async function readSlidePosition(page) {
|
|
86
86
|
return await page.evaluate(() => {
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
const center = (el) => {
|
|
88
|
+
if (!el) return null;
|
|
89
|
+
const rect = el.getBoundingClientRect();
|
|
90
|
+
if (rect.width <= 0 || rect.height <= 0) return null;
|
|
91
|
+
return {
|
|
92
|
+
x: Math.round(rect.x + rect.width / 2),
|
|
93
|
+
y: Math.round(rect.y + rect.height / 2),
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// Anchor on the first slide's container instead of a hashed CSS class.
|
|
98
|
+
// Douyin's module class names change between builds, while the player
|
|
99
|
+
// container / focusPanel structure and the X/Y text are stable.
|
|
100
|
+
const slide = document.querySelector('.dySwiperSlide');
|
|
101
|
+
const roots = [
|
|
102
|
+
slide && slide.closest('[data-e2e="player-container"]'),
|
|
103
|
+
slide && slide.closest('.focusPanel'),
|
|
104
|
+
document.querySelector('[data-e2e="player-container"]'),
|
|
105
|
+
document.querySelector('[data-e2e="note-detail"]'),
|
|
106
|
+
document,
|
|
107
|
+
].filter(Boolean);
|
|
108
|
+
|
|
109
|
+
const candidates = [];
|
|
110
|
+
for (const root of roots) {
|
|
111
|
+
for (const el of root.querySelectorAll('div,span')) {
|
|
112
|
+
const text = String(el.textContent || '').trim();
|
|
113
|
+
if (!/^\d{1,3}\s*\/\s*\d{1,3}$/.test(text)) continue;
|
|
114
|
+
const parts = text.split('/').map((part) => Number(part.trim()));
|
|
115
|
+
const current = parts[0];
|
|
116
|
+
const total = parts[1];
|
|
117
|
+
if (!Number.isFinite(current) || !Number.isFinite(total)) continue;
|
|
118
|
+
if (current <= 0 || total < current || total > 100) continue;
|
|
119
|
+
const spans = el.querySelectorAll('span');
|
|
120
|
+
if (spans.length < 2) continue;
|
|
121
|
+
candidates.push({ el, current, total, size: el.querySelectorAll('*').length });
|
|
122
|
+
}
|
|
123
|
+
if (candidates.length) break;
|
|
124
|
+
}
|
|
125
|
+
if (candidates.length) {
|
|
126
|
+
candidates.sort((a, b) => a.size - b.size);
|
|
127
|
+
const counter = candidates[0].el;
|
|
128
|
+
const next = counter.nextElementSibling || (counter.parentElement && counter.parentElement.lastElementChild);
|
|
129
|
+
const prev = counter.previousElementSibling || (counter.parentElement && counter.parentElement.firstElementChild);
|
|
130
|
+
return {
|
|
131
|
+
current: candidates[0].current,
|
|
132
|
+
total: candidates[0].total,
|
|
133
|
+
next: center(next && next !== counter ? next : null),
|
|
134
|
+
prev: center(prev && prev !== counter ? prev : null),
|
|
135
|
+
};
|
|
93
136
|
}
|
|
137
|
+
|
|
94
138
|
const matches = [...String(document.body && document.body.innerText || '')
|
|
95
139
|
.matchAll(/(?:^|\s)(\d{1,3})\s*\/\s*(\d{1,3})(?=\s|$)/g)];
|
|
96
140
|
for (let index = matches.length - 1; index >= 0; index -= 1) {
|
|
97
141
|
const current = Number(matches[index][1]);
|
|
98
142
|
const total = Number(matches[index][2]);
|
|
99
|
-
if (current > 0 && total >= current && total <= 100) return { current, total };
|
|
143
|
+
if (current > 0 && total >= current && total <= 100) return { current, total, next: null, prev: null };
|
|
100
144
|
}
|
|
101
145
|
return null;
|
|
102
146
|
});
|
|
@@ -142,7 +186,15 @@ async function advanceSlide(page, current) {
|
|
|
142
186
|
await page.mouse.up();
|
|
143
187
|
}
|
|
144
188
|
|
|
145
|
-
async function clickNextSlide(page) {
|
|
189
|
+
async function clickNextSlide(page, position = null) {
|
|
190
|
+
// Prefer the button next to the discovered X/Y counter. This survives
|
|
191
|
+
// hashed class-name changes.
|
|
192
|
+
if (position && position.next) {
|
|
193
|
+
try {
|
|
194
|
+
await page.mouse.click(position.next.x, position.next.y);
|
|
195
|
+
return true;
|
|
196
|
+
} catch { /* fall through */ }
|
|
197
|
+
}
|
|
146
198
|
const byClass = page.locator('.odSlyAjv');
|
|
147
199
|
const classCount = await byClass.count();
|
|
148
200
|
log('[note] next buttons: class=' + classCount);
|
|
@@ -443,7 +495,8 @@ async function captureSlides(page, context, outDir) {
|
|
|
443
495
|
const beforePage = pageNo;
|
|
444
496
|
let next = null;
|
|
445
497
|
for (let press = 0; press < 3 && !next; press += 1) {
|
|
446
|
-
const
|
|
498
|
+
const currentPosition = await readSlidePosition(page);
|
|
499
|
+
const clicked = await clickNextSlide(page, currentPosition);
|
|
447
500
|
log('[note] next click ' + press + ': ' + clicked);
|
|
448
501
|
if (!clicked) await advanceSlide(page, current);
|
|
449
502
|
for (let wait = 0; wait < 8; wait += 1) {
|