@cloud411716/fancy-webnovel 4.23.0 → 4.24.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.
@@ -201,11 +201,12 @@ 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`,不能当作总页数。插件会以第一个 slide 所在的播放器容器为锚点,按 `X/Y` 文本定位计数器,并从计数器相邻元素取得上一页/下一页按钮,不依赖抖音会变化的哈希类名;逐页推进并等待当前页内容切换完成,确保 `note.json` 记录所有页。
204
+ - 图文轮播必须以页面计数器 `当前页/总页数` 为准:页面刚打开时 DOM 里可能只挂载 1–2 个 `.dySwiperSlide`,不能当作总页数。插件会以第一个 slide 所在的播放器容器为锚点,按 `X/Y` 文本定位计数器,并从计数器相邻元素取得上一页/下一页按钮,不依赖抖音会变化的哈希类名;逐页推进并等待当前页内容切换完成,确保 `note.json` 记录所有页。如果某次翻页被播放器/浮层吞掉导致采集页数少于计数器,会重新加载作品并重试最多 2 次。
205
205
  - 独立视频作品会先尝试下载原片并用 ffmpeg 抽帧;下载失败时退化为播放器元素截图。
206
206
  视频时长超过 1 分钟直接跳过;前 5 秒与网文创作无关也跳过。
207
207
  - 场景切换点本身常是过渡虚影。插件会在密集采样后用 ffmpeg blurdetect 给每帧打分,在每个稳定画面段的清晰中段选一帧,避免把文字尚未完全出现的模糊帧交给 LLM。
208
- - 帧选择版本是 `frame_version: 3`;旧版本缓存的截图/关键帧会自动重新采集。
208
+ - 稳定画面段可能漏掉只出现 0.3–0.5 秒的短字幕。每个视频页会额外生成一张覆盖全片的密集预览图(15 秒内约每 0.4 秒一帧),LLM 必须同时读取关键帧拼图和密集预览,补齐短字幕后再去重。
209
+ - 帧选择版本是 `frame_version: 4`;旧版本缓存的截图/关键帧会自动重新采集。
209
210
  - 子 Agent 或 DSH 在分析途中中断时,作品任务保持 pending;下次运行会复用已采集文件重新分析。旧版本留下的 aborted/failed 任务会在启动采集时自动恢复为 pending。
210
211
  - 抖音 DOM/类名会变,`scan-account.cjs`、`crawl-note.cjs` 和 `crawl-video.cjs`
211
212
  的选择器可能需要维护。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "4.23.0",
3
+ "version": "4.24.1",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -45,7 +45,7 @@ import {
45
45
 
46
46
  export const inject = ['commands', 'userQuestions'];
47
47
 
48
- const FRAME_SELECTION_VERSION = 3;
48
+ const FRAME_SELECTION_VERSION = 4;
49
49
  const ANALYSIS_TIMEOUT_MS = 20 * 60 * 1000;
50
50
  const ANALYSIS_IDLE_GRACE_MS = 60 * 1000;
51
51
  const CAPABILITY_TIMEOUT_MS = 5 * 60 * 1000;
@@ -679,6 +679,7 @@ async function analyzeVideo(ctx, invocation, session, {
679
679
  accountUrl,
680
680
  video,
681
681
  frames: video.frames || [],
682
+ overview: video.overview_file ? { file: video.overview_file, interval: video.overview_interval } : null,
682
683
  targetFile: target,
683
684
  workspace: root,
684
685
  queryScript: materialTools.queryScript,
@@ -732,6 +733,7 @@ function analysisPromptForJob(job, root, materialTools) {
732
733
  accountUrl: job.accountUrl,
733
734
  video: job.video,
734
735
  frames: job.video.frames || [],
736
+ overview: job.video.overview_file ? { file: job.video.overview_file, interval: job.video.overview_interval } : null,
735
737
  targetFile: job.target,
736
738
  workspace: root,
737
739
  queryScript: materialTools.queryScript,
@@ -12,6 +12,7 @@
12
12
  {{SCREENSHOT_LIST}}
13
13
 
14
14
  截图可能来自图片页,也可能是同一页视频的关键帧拼图。带“第 X 页(视频……)”的图片属于同一页素材,请按从左到右读取拼图里的多个瞬间,合并提取,不要把同一页的多个瞬间当成多条素材。视频关键帧里的动态字幕、标语、口播文字也要提取到 `name`、`tags` 或 `note` 中;不要只看封面图。
15
+ 如果同一视频页同时提供关键帧拼图和密集预览图,必须逐格读取密集预览,补齐只出现很短时间的字幕或画面,再与关键帧去重。
15
16
 
16
17
  ## 图片专用补充
17
18
 
@@ -15,6 +15,12 @@
15
15
 
16
16
  {{FRAME_LIST}}
17
17
 
18
+ ## 密集预览图
19
+
20
+ {{OVERVIEW_LIST}}
21
+
22
+ 密集预览图用于兜底:关键帧可能漏掉只出现很短时间的字幕或画面。必须逐格读取密集预览,补齐短字幕/短画面,再与关键帧去重。
23
+
18
24
  ## 视频专用补充
19
25
 
20
26
  - 关键帧按时间顺序看,先看前 5 秒,再看后续。
@@ -16,6 +16,7 @@ const {
16
16
  } = require('./lib.cjs');
17
17
  const {
18
18
  probeDuration, detectSceneTimes, fixedShortTimes, extractDenseFramesAt,
19
+ createVideoOverviewSheet,
19
20
  } = require('./video-frames.cjs');
20
21
 
21
22
  const UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36';
@@ -364,6 +365,7 @@ async function captureSlides(page, context, outDir) {
364
365
  const screenshots = [];
365
366
  let converter = null;
366
367
  const seen = new Set();
368
+ let expectedTotal = null;
367
369
  try {
368
370
  converter = await context.newPage();
369
371
  await freezeSlideVideos(page);
@@ -374,7 +376,7 @@ async function captureSlides(page, context, outDir) {
374
376
 
375
377
  let current = await waitActiveSlide(page);
376
378
  const initialPosition = await readSlidePosition(page);
377
- const expectedTotal = initialPosition && initialPosition.total > 0 ? initialPosition.total : null;
379
+ expectedTotal = initialPosition && initialPosition.total > 0 ? initialPosition.total : null;
378
380
  let guard = 0;
379
381
  log('[note] carousel initial slides: ' + initialSlides
380
382
  + ', page: ' + (initialPosition ? initialPosition.current + '/' + initialPosition.total : 'unknown')
@@ -426,6 +428,11 @@ async function captureSlides(page, context, outDir) {
426
428
  slides.push(slide);
427
429
  const contact = createVideoContactSheet(frames, outDir, slideNo);
428
430
  slide.contact_file = contact;
431
+ const overview = fs.existsSync(videoFile)
432
+ ? createVideoOverviewSheet(videoFile, outDir, 'slide_' + String(slideNo).padStart(2, '0'), { duration: slide.duration })
433
+ : null;
434
+ slide.overview_file = overview ? overview.file : '';
435
+ slide.overview_interval = overview ? overview.interval : null;
429
436
  if (contact) {
430
437
  const times = frames.map((frame) => frame.time + ' 秒').join(' / ');
431
438
  screenshots.push({
@@ -450,6 +457,18 @@ async function captureSlides(page, context, outDir) {
450
457
  });
451
458
  }
452
459
  }
460
+ if (overview) {
461
+ screenshots.push({
462
+ index: screenshots.length + 1,
463
+ slide: slideNo,
464
+ type: 'video_overview',
465
+ duration: slide.duration,
466
+ interval: overview.interval,
467
+ file: overview.file,
468
+ label: '第 ' + slideNo + ' 页(视频 ' + (slide.duration ? slide.duration.toFixed(1) + ' 秒' : '')
469
+ + ',密集预览:每 ' + overview.interval + ' 秒一帧,按从左到右、从上到下读取)',
470
+ });
471
+ }
453
472
  } else {
454
473
  const file = path.join(outDir, 'slide_' + String(slideNo).padStart(2, '0') + '.jpg');
455
474
  let saved = false;
@@ -543,7 +562,12 @@ async function captureSlides(page, context, outDir) {
543
562
  throw new Error('没有找到可分析的图片或视频,且页面截图失败:' + (err && err.message ? err.message : String(err)));
544
563
  }
545
564
  }
546
- return { slides, screenshots };
565
+ return {
566
+ slides,
567
+ screenshots,
568
+ page_count: expectedTotal,
569
+ captured_pages: [...seen].sort((a, b) => a - b),
570
+ };
547
571
  }
548
572
 
549
573
  async function main() {
@@ -575,7 +599,25 @@ async function main() {
575
599
  }
576
600
 
577
601
  const meta = await readMetadata(page);
578
- const captured = await captureSlides(page, context, outDir);
602
+ let captured = await captureSlides(page, context, outDir);
603
+ for (let retry = 1; retry <= 2; retry += 1) {
604
+ if (!captured.page_count || captured.slides.length >= captured.page_count) break;
605
+ log('[note] incomplete carousel (' + captured.slides.length + '/' + captured.page_count
606
+ + '), reloading and retrying ' + retry);
607
+ await page.goto(noteUrl, { waitUntil: 'domcontentloaded', timeout: 60000 });
608
+ await page.waitForTimeout(4500);
609
+ const retryGate = await safeGateResult(page, outDir);
610
+ if (retryGate) {
611
+ keepPage = true;
612
+ await saveCookies(context, loginState, page.url());
613
+ printJson(retryGate);
614
+ return;
615
+ }
616
+ const retried = await captureSlides(page, context, outDir);
617
+ if (!retried.slides.length) break;
618
+ if (retried.slides.length < captured.slides.length) break;
619
+ captured = retried;
620
+ }
579
621
 
580
622
  const afterGate = await safeGateResult(page, outDir);
581
623
  if (afterGate) {
@@ -594,7 +636,9 @@ async function main() {
594
636
  description: meta.description,
595
637
  body: meta.body,
596
638
  slides: captured.slides,
597
- frame_version: 3,
639
+ page_count: captured.page_count || null,
640
+ captured_pages: captured.captured_pages || null,
641
+ frame_version: 4,
598
642
  screenshots: captured.screenshots,
599
643
  crawled_at: new Date().toISOString(),
600
644
  dir: outDir,
@@ -20,6 +20,7 @@ const {
20
20
  } = require('./lib.cjs');
21
21
  const {
22
22
  probeDuration, detectSceneTimes, fixedVideoTimes, extractDenseFramesAt,
23
+ createVideoOverviewSheet,
23
24
  } = require('./video-frames.cjs');
24
25
 
25
26
  const UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36';
@@ -228,7 +229,7 @@ async function main() {
228
229
  frames: [],
229
230
  first5s: [],
230
231
  video_file: '',
231
- frame_version: 3,
232
+ frame_version: 4,
232
233
  crawled_at: new Date().toISOString(),
233
234
  dir: outDir,
234
235
  };
@@ -277,7 +278,7 @@ async function main() {
277
278
  frames: [],
278
279
  first5s: [],
279
280
  video_file: videoFile,
280
- frame_version: 3,
281
+ frame_version: 4,
281
282
  crawled_at: new Date().toISOString(),
282
283
  dir: outDir,
283
284
  };
@@ -317,6 +318,9 @@ async function main() {
317
318
  const captured = await captureFramesFromPage(page, outDir, duration, times);
318
319
  frames = captured.frames;
319
320
  }
321
+ const overview = videoFile && fs.existsSync(videoFile)
322
+ ? createVideoOverviewSheet(videoFile, outDir, 'video', { duration })
323
+ : null;
320
324
  first5s = frames.filter((frame) => Number(frame.time) < FIRST_SECONDS);
321
325
  if (!first5s.length) first5s = frames.slice(0, 1);
322
326
  if (!frames.length) throw new Error('没有抽取到视频关键帧');
@@ -348,7 +352,9 @@ async function main() {
348
352
  fixed_times: fixedTimes,
349
353
  video_file: videoFile,
350
354
  download_error: downloadError,
351
- frame_version: 3,
355
+ overview_file: overview ? overview.file : '',
356
+ overview_interval: overview ? overview.interval : null,
357
+ frame_version: 4,
352
358
  crawled_at: new Date().toISOString(),
353
359
  dir: outDir,
354
360
  };
@@ -358,6 +358,47 @@ function selectDenseFrameTimes(samples, {
358
358
  return [...new Set(picked.map((item) => Math.round(item.sample.time * 100) / 100))].sort((a, b) => a - b);
359
359
  }
360
360
 
361
+ /**
362
+ * Build one compact contact sheet from evenly spaced frames across the whole
363
+ * clip. It is a coverage safety net: short captions can fall between stable
364
+ * keyframes, but they still appear in the dense preview.
365
+ */
366
+ function createVideoOverviewSheet(file, outDir, prefix, {
367
+ duration = null,
368
+ columns = 4,
369
+ rows = 5,
370
+ width = 480,
371
+ timeout = 120000,
372
+ } = {}) {
373
+ fs.mkdirSync(outDir, { recursive: true });
374
+ const total = Number.isFinite(Number(duration)) && Number(duration) > 0
375
+ ? Number(duration)
376
+ : probeDuration(file);
377
+ if (!total) return null;
378
+ const cells = Math.max(1, Number(columns) * Number(rows));
379
+ const base = total <= SHORT_VIDEO_SECONDS ? 0.4 : 1;
380
+ const interval = Math.round(Math.max(base, total / Math.max(1, cells - 1)) * 100) / 100;
381
+ const fps = Math.round((1 / interval) * 1000) / 1000;
382
+ const target = path.join(outDir, prefix + '_overview.jpg');
383
+ const scale = 'fps=' + fps + ',scale=' + width + ':-2';
384
+ const label = "drawtext=text='%{pts\\:hms}':x=8:y=8:fontsize=22:fontcolor=yellow:box=1:boxcolor=black@0.6";
385
+ const tile = ',tile=' + columns + 'x' + rows;
386
+ const args = (filter) => [
387
+ '-y', '-hide_banner', '-loglevel', 'error',
388
+ '-i', file, '-vf', filter, '-frames:v', '1', target,
389
+ ];
390
+ let result = spawnSync('ffmpeg', args(scale + ',' + label + tile), {
391
+ encoding: 'utf8', timeout,
392
+ });
393
+ if (result.status !== 0 || !fs.existsSync(target)) {
394
+ result = spawnSync('ffmpeg', args(scale + tile), {
395
+ encoding: 'utf8', timeout,
396
+ });
397
+ }
398
+ if (result.status !== 0 || !fs.existsSync(target)) return null;
399
+ return { file: target, interval, columns, rows };
400
+ }
401
+
361
402
  /**
362
403
  * Dense sample + stable-state selection + frame extraction. Returns the
363
404
  * selected frames along with the sampling metadata for note.json/video.json.
@@ -403,4 +444,5 @@ module.exports = {
403
444
  analyzeDenseFrames,
404
445
  selectDenseFrameTimes,
405
446
  extractDenseFramesAt,
447
+ createVideoOverviewSheet,
406
448
  };
@@ -121,6 +121,12 @@ function frameListText(frames) {
121
121
  .join('\n');
122
122
  }
123
123
 
124
+ function overviewListText(overview) {
125
+ if (!overview || !overview.file) return '(没有密集预览图)';
126
+ const interval = Number(overview.interval);
127
+ return `- \`${overview.file}\`(密集预览:每 ${Number.isFinite(interval) ? interval : '?'} 秒一帧,按从左到右、从上到下读取)`;
128
+ }
129
+
124
130
  export function capabilityPrompt({ capabilityFile }) {
125
131
  return renderTemplate(CAPABILITY_PROMPT_FILE, {
126
132
  CAPABILITY_FILE: capabilityFile,
@@ -205,6 +211,7 @@ export function videoAnalysisPrompt({
205
211
  accountUrl,
206
212
  video,
207
213
  frames,
214
+ overview,
208
215
  targetFile,
209
216
  workspace,
210
217
  queryScript,
@@ -216,6 +223,7 @@ export function videoAnalysisPrompt({
216
223
  VIDEO_TITLE: read(video.title, '(无标题)'),
217
224
  VIDEO_DURATION: Number.isFinite(Number(video.duration)) ? String(Number(video.duration)) : '未知',
218
225
  FRAME_LIST: frameListText(frames) || '(没有关键帧)',
226
+ OVERVIEW_LIST: overviewListText(overview),
219
227
  WORK_ID: read(video.id, ''),
220
228
  FACET_CANDIDATES: renderFacetCandidates(),
221
229
  TARGET_FILE: targetFile,