@cloud411716/fancy-webnovel 4.21.0 → 4.22.0
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,6 +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`,不能当作总页数。插件会逐页推进并等待当前页内容切换完成,确保 `note.json` 记录所有页。
|
|
204
205
|
- 独立视频作品会先尝试下载原片并用 ffmpeg 抽帧;下载失败时退化为播放器元素截图。
|
|
205
206
|
视频时长超过 1 分钟直接跳过;前 5 秒与网文创作无关也跳过。
|
|
206
207
|
- 场景切换点本身常是过渡虚影。插件会在密集采样后用 ffmpeg blurdetect 给每帧打分,在每个稳定画面段的清晰中段选一帧,避免把文字尚未完全出现的模糊帧交给 LLM。
|
package/package.json
CHANGED
|
@@ -63,7 +63,9 @@ async function activeSlideInfo(page) {
|
|
|
63
63
|
if (String(videoSrc).startsWith('//')) videoSrc = 'https:' + videoSrc;
|
|
64
64
|
duration = Number.isFinite(video.duration) && video.duration > 0 ? video.duration : null;
|
|
65
65
|
}
|
|
66
|
-
const img = el.querySelector('img[src*="tplv-dy-aweme-images"], img[src*="aweme-images"]')
|
|
66
|
+
const img = el.querySelector('img[src*="tplv-dy-aweme-images"], img[src*="aweme-images"]');
|
|
67
|
+
const anyImg = el.querySelector('img');
|
|
68
|
+
const fallbackImg = anyImg && anyImg.src && !/douyinDefault/i.test(anyImg.src) ? anyImg.src : '';
|
|
67
69
|
return {
|
|
68
70
|
domIndex: active.index,
|
|
69
71
|
x: Math.round(active.rect.x),
|
|
@@ -73,11 +75,33 @@ async function activeSlideInfo(page) {
|
|
|
73
75
|
hasVideo: Boolean(videoSrc && !videoSrc.startsWith('blob:')),
|
|
74
76
|
videoSrc,
|
|
75
77
|
duration,
|
|
76
|
-
|
|
78
|
+
// Never fall back to Douyin's placeholder image: if the real image has
|
|
79
|
+
// not loaded yet, the caller will wait or take an element screenshot.
|
|
80
|
+
imageSrc: img && img.src ? img.src : fallbackImg,
|
|
77
81
|
};
|
|
78
82
|
});
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
async function readSlidePosition(page) {
|
|
86
|
+
return await page.evaluate(() => {
|
|
87
|
+
const el = document.querySelector('.YoycnaPk');
|
|
88
|
+
if (el) {
|
|
89
|
+
const parts = [...el.querySelectorAll('span')].map((span) => String(span.textContent || '').trim());
|
|
90
|
+
const current = Number(parts[0]);
|
|
91
|
+
const total = Number(parts[parts.length - 1]);
|
|
92
|
+
if (Number.isFinite(current) && Number.isFinite(total) && total > 0) return { current, total };
|
|
93
|
+
}
|
|
94
|
+
const matches = [...String(document.body && document.body.innerText || '')
|
|
95
|
+
.matchAll(/(?:^|\s)(\d{1,3})\s*\/\s*(\d{1,3})(?=\s|$)/g)];
|
|
96
|
+
for (let index = matches.length - 1; index >= 0; index -= 1) {
|
|
97
|
+
const current = Number(matches[index][1]);
|
|
98
|
+
const total = Number(matches[index][2]);
|
|
99
|
+
if (current > 0 && total >= current && total <= 100) return { current, total };
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
81
105
|
async function freezeSlideVideos(page) {
|
|
82
106
|
await page.evaluate(() => {
|
|
83
107
|
const pause = () => {
|
|
@@ -138,12 +162,22 @@ async function clickNextSlide(page) {
|
|
|
138
162
|
return false;
|
|
139
163
|
}
|
|
140
164
|
|
|
141
|
-
|
|
165
|
+
function sameSlide(a, b) {
|
|
166
|
+
if (!a || !b) return false;
|
|
167
|
+
if (a.domIndex !== b.domIndex) return false;
|
|
168
|
+
if (a.videoSrc && b.videoSrc && a.videoSrc !== b.videoSrc) return false;
|
|
169
|
+
if (a.imageSrc && b.imageSrc && a.imageSrc !== b.imageSrc) return false;
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function waitActiveSlide(page, previous = null) {
|
|
142
174
|
let info = null;
|
|
143
|
-
for (let attempt = 0; attempt <
|
|
175
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
144
176
|
info = await activeSlideInfo(page);
|
|
145
|
-
|
|
146
|
-
|
|
177
|
+
const changed = previous ? !sameSlide(info, previous) : true;
|
|
178
|
+
if (info && changed && info.hasVideo && info.duration) return info;
|
|
179
|
+
if (info && changed && !info.hasVideo && info.imageSrc) return info;
|
|
180
|
+
await page.waitForTimeout(300);
|
|
147
181
|
}
|
|
148
182
|
return info;
|
|
149
183
|
}
|
|
@@ -281,21 +315,25 @@ async function captureSlides(page, context, outDir) {
|
|
|
281
315
|
try {
|
|
282
316
|
converter = await context.newPage();
|
|
283
317
|
await freezeSlideVideos(page);
|
|
284
|
-
|
|
318
|
+
const initialSlides = await page.evaluate(() => document.querySelectorAll('.dySwiperSlide').length);
|
|
285
319
|
if (initialSlides === 0) {
|
|
286
320
|
return await captureFallbackImages(page, context, converter, outDir);
|
|
287
321
|
}
|
|
288
322
|
|
|
289
323
|
let current = await waitActiveSlide(page);
|
|
324
|
+
const initialPosition = await readSlidePosition(page);
|
|
325
|
+
const expectedTotal = initialPosition && initialPosition.total > 0 ? initialPosition.total : null;
|
|
290
326
|
let guard = 0;
|
|
291
|
-
log('[note] carousel initial slides: ' + initialSlides
|
|
292
|
-
|
|
327
|
+
log('[note] carousel initial slides: ' + initialSlides
|
|
328
|
+
+ ', page: ' + (initialPosition ? initialPosition.current + '/' + initialPosition.total : 'unknown')
|
|
329
|
+
+ ', first domIndex: ' + (current && current.domIndex));
|
|
330
|
+
while (current && guard < 60) {
|
|
293
331
|
guard += 1;
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
log('[note] processing
|
|
297
|
-
if (!seen.has(
|
|
298
|
-
seen.add(
|
|
332
|
+
const position = await readSlidePosition(page);
|
|
333
|
+
const pageNo = position && position.current > 0 ? position.current : current.domIndex + 1;
|
|
334
|
+
log('[note] processing page ' + pageNo + ' (slide ' + (slides.length + 1) + ')');
|
|
335
|
+
if (!seen.has(pageNo)) {
|
|
336
|
+
seen.add(pageNo);
|
|
299
337
|
const slideNo = slides.length + 1;
|
|
300
338
|
if (current.hasVideo) {
|
|
301
339
|
const videoFile = path.join(outDir, 'slide_' + String(slideNo).padStart(2, '0') + '.mp4');
|
|
@@ -399,17 +437,24 @@ async function captureSlides(page, context, outDir) {
|
|
|
399
437
|
}
|
|
400
438
|
|
|
401
439
|
// 一次只前进一格。优先点轮播右侧箭头;视频播放时按钮偶尔会被
|
|
402
|
-
//
|
|
403
|
-
|
|
440
|
+
// 播放器层吃掉,先暂停再重试,仍失败才退回拖拽。页面计数器比
|
|
441
|
+
// DOM 节点数可靠:note.json 必须覆盖计数器的全部页数。
|
|
442
|
+
if (expectedTotal && seen.size >= expectedTotal) break;
|
|
443
|
+
const beforePage = pageNo;
|
|
404
444
|
let next = null;
|
|
405
445
|
for (let press = 0; press < 3 && !next; press += 1) {
|
|
406
446
|
const clicked = await clickNextSlide(page);
|
|
407
447
|
log('[note] next click ' + press + ': ' + clicked);
|
|
408
448
|
if (!clicked) await advanceSlide(page, current);
|
|
409
449
|
for (let wait = 0; wait < 8; wait += 1) {
|
|
410
|
-
await page.waitForTimeout(
|
|
450
|
+
await page.waitForTimeout(400);
|
|
411
451
|
const info = await activeSlideInfo(page);
|
|
412
|
-
|
|
452
|
+
const after = await readSlidePosition(page);
|
|
453
|
+
if (after && after.current !== beforePage) {
|
|
454
|
+
next = info || current;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
if (!after && info && info.domIndex !== current.domIndex) {
|
|
413
458
|
next = info;
|
|
414
459
|
break;
|
|
415
460
|
}
|
|
@@ -419,9 +464,15 @@ async function captureSlides(page, context, outDir) {
|
|
|
419
464
|
await page.waitForTimeout(500);
|
|
420
465
|
}
|
|
421
466
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
467
|
+
const afterPosition = await readSlidePosition(page);
|
|
468
|
+
log('[note] next page: ' + (afterPosition ? afterPosition.current + '/' + afterPosition.total : 'unknown')
|
|
469
|
+
+ ', seen: ' + [...seen].join(','));
|
|
470
|
+
if (!next) break;
|
|
471
|
+
if (afterPosition && beforePage && afterPosition.current <= beforePage) break;
|
|
472
|
+
current = await waitActiveSlide(page, current);
|
|
473
|
+
}
|
|
474
|
+
if (expectedTotal && seen.size < expectedTotal) {
|
|
475
|
+
log('[note] WARNING incomplete carousel: captured ' + seen.size + '/' + expectedTotal + ' pages');
|
|
425
476
|
}
|
|
426
477
|
} finally {
|
|
427
478
|
await unfreezeSlideVideos(page);
|