@cloud411716/fancy-webnovel 4.8.1 → 4.9.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # fancy-webnovel
2
2
 
3
- DeepSeek Harness(DSH)网文创作插件组合包。它把工作区初始化、扫榜、选题、拆书、故事构建、素材库和抖音图文/视频素材采集注册成 `/fancy-*` 命令。
3
+ DeepSeek Harness(DSH)网文创作插件组合包。它把工作区初始化、扫榜、选题、拆书、故事构建、素材库和抖音图文/视频/文章素材采集注册成 `/fancy-*` 命令。
4
4
 
5
5
  ## 环境
6
6
 
@@ -1,13 +1,14 @@
1
1
  # fancy-douyin 抖音素材采集(图文 + 视频)
2
2
 
3
- 把记录在案的抖音账号主页下的图文作品和视频作品交给 LLM 提取素材,并写入
3
+ 把记录在案的抖音账号主页下的图文、视频和文章作品交给 LLM 提取素材,并写入
4
4
  工作区素材库(`source=other`,kind 不受内置列表限制)。
5
5
 
6
6
  运行前先让 LLM 自检图片识别和视频识别能力:
7
7
 
8
8
  - 有图片识别能力:分析 `/note/` 图文作品。
9
9
  - 有视频识别能力:分析 `/video/` 视频作品。
10
- - 两种能力都没有:直接退出并通知,不启动 Chrome。
10
+ - `/article/` 长文不需要视觉能力,直接读取正文分析。
11
+ - 图片和视频能力都没有时,只跳过图文/视频,仍然处理文章。
11
12
 
12
13
  ## 命令
13
14
 
@@ -32,8 +33,9 @@ https://www.douyin.com/user/MS4wLjABAAAA...
32
33
  ```text
33
34
  LLM 能力自检(图片 / 视频)
34
35
  → 两种能力都没有:退出并通知
35
- → 依次扫描账号主页,收集 /note/ 图文和 /video/ 视频
36
+ → 依次扫描账号主页,收集 /note/ 图文、/video/ 视频和 /article/ 文章
36
37
  → 跳过 crawled.json 中已成功入库、已确认无关或已标记失败跳过的作品
38
+ → 文章:提取标题、发布日期、阅读时长和正文
37
39
  → 图文:逐页判断类型
38
40
  → 图片页:下载轮播原图并转成 JPG(避免滚动时截到半张图)
39
41
  → 视频页:下载该页短视频,用 ffmpeg scene 检测 + 固定间隔兜底抽帧,拼成一张关键帧图
@@ -49,7 +51,7 @@ LLM 能力自检(图片 / 视频)
49
51
  → 继续下一篇
50
52
  ```
51
53
 
52
- 作品级失败(下载、抽帧、LLM 整理失败)会记录为 `failed + skip`,本次跳过且下次不再重试;账号扫描失败不会写入作品记录,下次运行仍会重试。
54
+ 作品级失败(下载、抽帧、文章正文提取失败、LLM 整理失败)会记录为 `failed + skip`,本次跳过且下次不再重试;账号扫描失败不会写入作品记录,下次运行仍会重试。
53
55
 
54
56
  ## 登录与验证
55
57
 
@@ -91,7 +93,7 @@ cookies 会额外镜像到:
91
93
  ├── login-state.json # cookies 镜像(0600)
92
94
  ├── chrome-profile/ # Chrome 登录态
93
95
  ├── chrome.json # CDP 端口、profile 与 headed/headless 模式
94
- └── output/<时间>/ # 截图/关键帧、note.json/video.json、materials.jsonl
96
+ └── output/<时间>/ # 截图/关键帧、note.json/video.json/article.json/article.md、materials.jsonl
95
97
  ```
96
98
 
97
99
  浏览器脚本部署在:
@@ -102,6 +104,7 @@ cookies 会额外镜像到:
102
104
  ├── scan-account.cjs
103
105
  ├── crawl-note.cjs
104
106
  ├── crawl-video.cjs
107
+ ├── crawl-article.cjs
105
108
  ├── video-frames.cjs
106
109
  ├── lib.cjs
107
110
  └── package.json
@@ -117,15 +117,17 @@ namespace: fancy
117
117
  /fancy-douyin add <主页地址> # 记录一个抖音账号主页
118
118
  /fancy-douyin list # 查看已记录账号
119
119
  /fancy-douyin remove <序号|地址> # 删除账号记录
120
- /fancy-douyin # 依次采集所有账号下未处理的图文和视频
120
+ /fancy-douyin # 依次采集所有账号下未处理的图文、视频和文章
121
121
  /fancy-douyin help
122
122
  ```
123
123
 
124
124
  先让 LLM 自检图片/视频识别能力:有图片能力才处理 `/note/` 图文,有视频能力才
125
- 处理 `/video/` 视频;两种能力都没有时直接退出并通知。图文截图保存为 JPG;视频
126
- 超过 1 分钟直接跳过,不超过 1 分钟的先看前 5 秒,与网文创作无关也跳过。内容交给
127
- LLM 提取素材,按 material JSONL 写入数据库,`source` 固定为 `other`。已成功入库或
128
- 确认无关的作品记录在工作区 `/.fancy/douyin/crawled.json`,后续跳过。
125
+ 处理 `/video/` 视频;`/article/` 长文直接读取正文,不依赖视觉能力。图片和视频能力
126
+ 都没有时只跳过图文/视频,仍然处理文章。图文截图保存为 JPG;视频超过 1 分钟直接
127
+ 跳过,不超过 1 分钟的先看前 5 秒,与网文创作无关也跳过;文章按标题层级拆成原子
128
+ 设定。内容交给 LLM 提取素材,按 material JSONL 写入数据库,`source` 固定为
129
+ `other`。已成功入库、确认无关或作品级失败的作品记录在工作区
130
+ `/.fancy/douyin/crawled.json`,后续跳过。
129
131
 
130
132
  登录态保存在工作区 `/.fancy/douyin/chrome-profile/`,并镜像 cookies 到
131
133
  `login-state.json`。首次需要登录时使用有头 Chrome,登录态有效后后续运行自动
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "4.8.1",
3
+ "version": "4.9.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -315,7 +315,7 @@ export async function apply(ctx) {
315
315
  '2. /fancy-topic 选题',
316
316
  '3. /fancy-topic setup 创建项目(会分配 UUID、项目库和独立数据库用户)',
317
317
  '4. /fancy-material 生成素材库(可选,写作时查名字/金手指/冲突/场景)',
318
- '5. /fancy-douyin add <主页> 采集抖音图文/视频素材(可选)',
318
+ '5. /fancy-douyin add <主页> 采集抖音图文/视频/文章素材(可选)',
319
319
  '6. /fancy-build scale 开始写故事',
320
320
  ].join('\n'));
321
321
  } catch (err) {
@@ -16,7 +16,7 @@ const HERE = __dirname;
16
16
  const requireHere = createRequire(import.meta.url);
17
17
 
18
18
  export const DOUYIN_TOOL_DIR = path.join('.fancy-tools', 'fancy-douyin');
19
- export const TOOL_FILES = ['lib.cjs', 'video-frames.cjs', 'start-chrome.cjs', 'scan-account.cjs', 'crawl-note.cjs', 'crawl-video.cjs'];
19
+ export const TOOL_FILES = ['lib.cjs', 'video-frames.cjs', 'start-chrome.cjs', 'scan-account.cjs', 'crawl-note.cjs', 'crawl-video.cjs', 'crawl-article.cjs'];
20
20
 
21
21
  export function playwrightNodePath() {
22
22
  try {
@@ -77,7 +77,7 @@ function writeToolFile(file, content, problems) {
77
77
 
78
78
  /**
79
79
  * @param {string} root workspace directory
80
- * @returns {{ok: boolean, dir: string, nodePath: string, scripts: {start: string, scan: string, note: string, video: string}, problems: string[]}}
80
+ * @returns {{ok: boolean, dir: string, nodePath: string, scripts: {start: string, scan: string, note: string, video: string, article: string}, problems: string[]}}
81
81
  */
82
82
  export function deployDouyinTools(root) {
83
83
  const problems = [];
@@ -87,7 +87,7 @@ export function deployDouyinTools(root) {
87
87
 
88
88
  if (!ensureRealDir(fancyTools, '.fancy-tools', problems)
89
89
  || !ensureRealDir(target, '.fancy-tools/fancy-douyin', problems)) {
90
- return { ok: false, dir: target, nodePath: '', scripts: { start: '', scan: '', note: '', video: '' }, problems };
90
+ return { ok: false, dir: target, nodePath: '', scripts: { start: '', scan: '', note: '', video: '', article: '' }, problems };
91
91
  }
92
92
 
93
93
  for (const name of TOOL_FILES) {
@@ -114,7 +114,7 @@ export function deployDouyinTools(root) {
114
114
 
115
115
  writeToolFile(path.join(target, 'README.txt'), [
116
116
  '本目录由 fancy-douyin 自动部署。',
117
- '浏览器脚本:start-chrome.cjs / scan-account.cjs / crawl-note.cjs / crawl-video.cjs',
117
+ '浏览器脚本:start-chrome.cjs / scan-account.cjs / crawl-note.cjs / crawl-video.cjs / crawl-article.cjs',
118
118
  '视频抽帧:video-frames.cjs(ffmpeg scene 检测 + 固定间隔兜底)',
119
119
  '登录态与采集记录在 <工作区>/.fancy/douyin/ 下。',
120
120
  '不要手工修改本目录脚本;重新运行 /fancy-douyin 会刷新。',
@@ -130,6 +130,7 @@ export function deployDouyinTools(root) {
130
130
  scan: path.join(target, 'scan-account.cjs'),
131
131
  note: path.join(target, 'crawl-note.cjs'),
132
132
  video: path.join(target, 'crawl-video.cjs'),
133
+ article: path.join(target, 'crawl-article.cjs'),
133
134
  },
134
135
  problems,
135
136
  };
@@ -32,7 +32,7 @@ import {
32
32
  readCrawled,
33
33
  removeAccount,
34
34
  } from './state.js';
35
- import { analysisPrompt, capabilityPrompt, helpText, loginQuestion, summaryText, videoAnalysisPrompt, videoRelevancePrompt } from './templates.js';
35
+ import { analysisPrompt, articlePrompt, capabilityPrompt, helpText, loginQuestion, summaryText, videoAnalysisPrompt, videoRelevancePrompt } from './templates.js';
36
36
 
37
37
  export const inject = ['commands', 'userQuestions'];
38
38
 
@@ -631,6 +631,27 @@ async function analyzeVideo(ctx, invocation, session, {
631
631
  });
632
632
  }
633
633
 
634
+ async function analyzeArticle(ctx, invocation, session, {
635
+ root, accountUrl, article, target, materialTools, taskList,
636
+ }) {
637
+ const prompt = articlePrompt({
638
+ accountUrl,
639
+ article,
640
+ targetFile: target,
641
+ workspace: root,
642
+ queryScript: materialTools.queryScript,
643
+ validateScript: materialTools.validateScript,
644
+ });
645
+ return analyzeMaterials(ctx, invocation, session, {
646
+ root,
647
+ prompt,
648
+ target: target,
649
+ title: article.title,
650
+ materialTools,
651
+ taskList,
652
+ });
653
+ }
654
+
634
655
  async function runCrawl(ctx, invocation, session, taskList) {
635
656
  const root = workspaceOf(session);
636
657
  const paths = ensureDouyinDir(root);
@@ -651,11 +672,8 @@ async function runCrawl(ctx, invocation, session, taskList) {
651
672
  return notify(session, 'error', '❌ LLM 能力自检失败:' + capabilities.error);
652
673
  }
653
674
  if (!capabilities.image_supported && !capabilities.video_supported) {
654
- return notify(session, 'error', [
655
- '❌ 当前模型既没有图片识别能力,也没有视频识别能力,已退出。',
656
- capabilities.reason ? '模型说明:' + capabilities.reason : '',
657
- '请切换到支持视觉识别的模型后重试。',
658
- ].filter(Boolean).join('\n'));
675
+ // 文章是纯文本,不依赖视觉能力;无视觉时只跳过图文和视频。
676
+ taskList.progress('无视觉能力,将跳过图文/视频,只处理文章');
659
677
  }
660
678
 
661
679
  const tools = deployDouyinTools(root);
@@ -683,6 +701,8 @@ async function runCrawl(ctx, invocation, session, taskList) {
683
701
  let scannedAccounts = 0;
684
702
  let foundNotes = 0;
685
703
  let foundVideos = 0;
704
+ let foundArticles = 0;
705
+ let skippedArticles = 0;
686
706
  let skippedNotes = 0;
687
707
  let skippedNotesByCapability = 0;
688
708
  let skippedVideosByCapability = 0;
@@ -734,8 +754,10 @@ async function runCrawl(ctx, invocation, session, taskList) {
734
754
  scannedAccounts += 1;
735
755
  const notes = Array.isArray(scan.json.notes) ? scan.json.notes : [];
736
756
  const videos = Array.isArray(scan.json.videos) ? scan.json.videos : [];
757
+ const articles = Array.isArray(scan.json.articles) ? scan.json.articles : [];
737
758
  foundNotes += notes.length;
738
759
  foundVideos += videos.length;
760
+ foundArticles += articles.length;
739
761
  taskList.advance(3);
740
762
 
741
763
  for (const card of notes) {
@@ -971,6 +993,97 @@ async function runCrawl(ctx, invocation, session, taskList) {
971
993
  await sleep(delay);
972
994
  }
973
995
  }
996
+
997
+ for (const card of articles) {
998
+ if (abortRequested(invocation)) { aborted = true; break outer; }
999
+ const articleId = noteIdFromUrl(card.href);
1000
+ if (!articleId) continue;
1001
+ if (crawled[articleId]) {
1002
+ skippedArticles += 1;
1003
+ continue;
1004
+ }
1005
+ const articleDir = path.join(accountDir, articleId);
1006
+ const articleResult = await runWithLogin(
1007
+ ctx, invocation, session, root, tools.scripts.article,
1008
+ ['--workspace', root, '--article', card.href, '--cdp', browser.cdp,
1009
+ '--out', articleDir, '--login-state', paths.loginState],
1010
+ articleDir,
1011
+ paths,
1012
+ '采集文章',
1013
+ tools.nodePath,
1014
+ browser,
1015
+ tools,
1016
+ );
1017
+ if (!articleResult.ok) {
1018
+ failures.push({ id: articleId, url: card.href, reason: articleResult.error });
1019
+ if (articleResult.cancelled || authFailureText(articleResult.error)) { aborted = true; break outer; }
1020
+ markFailed(articleId, card, { type: 'article', dir: articleDir }, articleResult.error);
1021
+ continue;
1022
+ }
1023
+ const article = articleResult.json.article || {};
1024
+ if (!article || !article.body || String(article.body).trim().length < 50) {
1025
+ failures.push({ id: articleId, url: card.href, reason: '文章正文为空' });
1026
+ markFailed(articleId, card, { type: 'article', dir: articleDir, title: article.title }, '文章正文为空');
1027
+ continue;
1028
+ }
1029
+ processedWorks += 1;
1030
+ article.account_url = account.url;
1031
+ const target = path.join(articleDir, 'materials.jsonl');
1032
+ taskList.advance(4);
1033
+ taskList.progress(`LLM 整理文章素材(${article.title || articleId})`);
1034
+ const analyzed = await analyzeArticle(ctx, invocation, session, {
1035
+ root,
1036
+ accountUrl: account.url,
1037
+ article,
1038
+ target,
1039
+ materialTools,
1040
+ taskList,
1041
+ });
1042
+ if (!analyzed.ok) {
1043
+ failures.push({ id: articleId, url: card.href, reason: analyzed.error });
1044
+ if (analyzed.aborted) { aborted = true; break outer; }
1045
+ if (analyzed.fatal) break outer;
1046
+ markFailed(articleId, card, { type: 'article', dir: articleDir, title: article.title }, analyzed.error);
1047
+ continue;
1048
+ }
1049
+ if (analyzed.skipped) {
1050
+ skippedIrrelevant += 1;
1051
+ markCrawled(root, articleId, {
1052
+ account_url: account.url,
1053
+ url: article.url || card.href,
1054
+ title: article.title || card.text || '',
1055
+ type: 'article',
1056
+ body_file: article.body_file,
1057
+ reading_time: article.reading_time,
1058
+ body_length: article.body_length,
1059
+ dir: articleDir,
1060
+ inserted: 0,
1061
+ skipped: 0,
1062
+ skip: true,
1063
+ reason: analyzed.reason || '与网文创作无关',
1064
+ });
1065
+ } else {
1066
+ inserted += analyzed.inserted;
1067
+ skippedMaterials += analyzed.skipped;
1068
+ markCrawled(root, articleId, {
1069
+ account_url: account.url,
1070
+ url: article.url || card.href,
1071
+ title: article.title || card.text || '',
1072
+ type: 'article',
1073
+ body_file: article.body_file,
1074
+ reading_time: article.reading_time,
1075
+ body_length: article.body_length,
1076
+ dir: articleDir,
1077
+ inserted: analyzed.inserted,
1078
+ skipped: analyzed.skipped,
1079
+ });
1080
+ }
1081
+ crawled[articleId] = true;
1082
+ if (NOTE_DELAY_MIN_MS < NOTE_DELAY_MAX_MS) {
1083
+ const delay = NOTE_DELAY_MIN_MS + Math.floor(Math.random() * (NOTE_DELAY_MAX_MS - NOTE_DELAY_MIN_MS));
1084
+ await sleep(delay);
1085
+ }
1086
+ }
974
1087
  }
975
1088
 
976
1089
  taskList.advance(5);
@@ -979,9 +1092,11 @@ async function runCrawl(ctx, invocation, session, taskList) {
979
1092
  scannedAccounts,
980
1093
  foundNotes,
981
1094
  foundVideos,
1095
+ foundArticles,
982
1096
  skippedNotesByCapability,
983
1097
  skippedVideosByCapability,
984
1098
  skippedNotes,
1099
+ skippedArticles,
985
1100
  processedNotes: processedWorks,
986
1101
  skippedIrrelevant,
987
1102
  skippedLongVideos,
@@ -1041,7 +1156,7 @@ function douyinTaskTitles(invocation) {
1041
1156
  '检查账号与素材库',
1042
1157
  'LLM 能力自检(图片 / 视频)',
1043
1158
  '扫描账号主页',
1044
- '采集图文 / 视频作品',
1159
+ '采集图文 / 视频 / 文章作品',
1045
1160
  'LLM 整理素材',
1046
1161
  '写入素材库',
1047
1162
  ];
@@ -5,6 +5,8 @@
5
5
  - **图片识别**:你能用 `read` 工具打开图片文件,并真正看到画面内容吗?
6
6
  - **视频识别**:插件会把视频按时间抽成关键帧图片;你能读取这些关键帧,并据此还原视频里发生了什么吗?
7
7
 
8
+ 如果需要创建测试文件,放在当前项目的 `.tmp` 目录下,并且测试后不需要删除测试文件。
9
+
8
10
  把结果写入下面的绝对路径(覆盖写):
9
11
 
10
12
  ```text
@@ -0,0 +1,94 @@
1
+ 你正在分析一篇抖音长文/文章作品,把文章里的设定、素材、灵感和写作方法拆成可以直接进入网文素材库的小积木。
2
+
3
+ ## 作品信息
4
+
5
+ - 账号主页:{{ACCOUNT_URL}}
6
+ - 文章地址:{{ARTICLE_URL}}
7
+ - 文章标题:{{ARTICLE_TITLE}}
8
+ - 发布日期:{{ARTICLE_DATE}}
9
+ - 阅读时长:{{ARTICLE_READING_TIME}}
10
+ - 正文字数:约 {{ARTICLE_LENGTH}} 字
11
+ - 正文文件:`{{ARTICLE_FILE}}`
12
+
13
+ ## 文章正文
14
+
15
+ {{ARTICLE_BODY}}
16
+
17
+ ## 任务
18
+
19
+ 分析文章内容。如果文章与小说网文创作的设定、素材、写作方法等无关,写 skip 标记并结束。有关则把文章拆成原子素材,不要只写一篇摘要。
20
+
21
+ ### 提取规则(必须遵守)
22
+
23
+ 1. **先按文章结构拆小节**:一级标题、二级标题、编号列表都是天然的分类依据。小节标题要进入 `subkind` 和 `tags`。
24
+ 2. **世界观 / 设定大纲 / 图鉴 / 列表**:
25
+ - 每个独立条目单独成一条素材:世界层级、境界、灵根、宗门、资源、丹药、法器、规则、角色、地点等分别输出。
26
+ - `name` 原样保留文章里的名称或短语:例如“引气境”“筑基境”“凡界”“灵界”“极品灵根”“九转成丹”。
27
+ - 不要把多个条目合并成一条,不要改写成意象句,不要只挑一部分。文章里有多少个独立设定,就输出多少条。
28
+ - 分类标题进入 `subkind` 和 `tags`。例如【二、完整修炼体系】→ subkind 写“修炼体系”,tags 至少包含 `修炼体系`、`修仙`。
29
+ 3. **长段落 / 分析 / 写作技巧**:抽象成可以独立取用的素材,不要整段抄写。机制、代价、限制、反制、冲突、反转、写法分开成条。
30
+ 4. `kind` 必须写中文主题,例如 `修仙境界`、`世界层级`、`灵根`、`宗门`、`功法`、`丹药`、`法器`、`世界规则`、`写作技巧`。不要写 `world_rule`、`color_word` 这类英文内部标识。
31
+ 5. `subkind` 可选,是 `kind` 下的中文二级分类,最多 40 字;文章有二级标题就原样写。
32
+ 6. `tags` 3–8 个:包含文章主题、章节分类、用途、气质等维度。
33
+ 7. `genres` 1–5 个:根据内容判断,例如仙侠、玄幻、修真、西幻、悬疑、都市异能。
34
+ 8. `note` 只补充一句使用场景、限制或来源,最多 300 字;不要把 `name` 再改写一遍。
35
+ 9. **禁止**把长文只概括成少量创作句;文章里的独立设定必须逐条保留。
36
+
37
+ ### 命名风格提炼与同风格扩写(每篇必做)
38
+
39
+ 提取完全部原始条目后,先提炼这篇文章的命名方式、特色和吸睛原因,再据此扩写 10 条新素材:
40
+
41
+ 1. **先提炼,再动笔**:想清楚文章的命名方式(如“境界名 + 能力边界”“地名 + 地域气质”“宗门名 + 行事规则”)、语言气质和它为什么适合网文。
42
+ 2. **选一组 kind + subkind**:从本文已提取的条目里选最有代表性的一组,扩写的 10 条必须全部使用这同一个 `kind` 和同一个 `subkind`;如果文章没有二级分类,10 条保持同 `kind` 即可。
43
+ 3. **保持风格一致**:新素材要沿用文章的长度、词性、意象密度和命名节奏;读起来必须像同一篇设定大纲里会出现的条目。
44
+ 4. **必须是新条目**:不能与文章原始条目、也不能与数据库中已有素材同名或近义重复。
45
+ 5. **同样写全字段**:每条都要有 `tags`、`genres`、`note`;质量与原始条目一致。
46
+ 6. **写在同一个文件**:10 条新素材接在原始条目后面,`id` 序号继续递增,仍用 `dy_<文章ID>_<序号>`。
47
+ 7. **数量**:原始条目全部保留,另加 10 条新素材;如果文章有多个 subkind,只选其中一组扩写 10 条。
48
+
49
+ ## 输出文件
50
+
51
+ 把 JSONL 写到:
52
+
53
+ ```text
54
+ {{TARGET_FILE}}
55
+ ```
56
+
57
+ 一行一个 JSON 对象,不要 Markdown 代码围栏、标题、解释、前后缀。
58
+
59
+ 字段只能是:
60
+
61
+ ```text
62
+ id / kind / subkind / name / tags / genres / note / source
63
+ ```
64
+
65
+ - `source` 固定写 `other`。
66
+ - `name`:设定/图鉴/列表条目必须原样抄录;长段落才抽象。
67
+ - `kind` 必须写中文主题。
68
+ - `subkind` 可选,是 `kind` 下的中文二级分类,最多 40 字。
69
+ - `tags` 3–8 个短标签;必须包含文章主题和章节分类。
70
+ - `genres` 1–5 个题材;不要全部写 `["通用"]`。
71
+ - `note` 可写一句补充,没有就写空字符串,最多 300 字。
72
+ - `id` 用小写字母、数字、下划线,格式建议:`dy_<文章ID>_<序号>`,全局唯一。
73
+
74
+ 如果判断文章与网文创作无关:不要写任何素材行,只把下面的对象写进同一个文件,然后结束本轮:
75
+
76
+ ```json
77
+ {"skip": true, "reason": "与网文创作无关:<一句话原因>"}
78
+ ```
79
+
80
+ 生成前可以查询已有素材,避免同名:
81
+
82
+ ```bash
83
+ node '{{QUERY_SCRIPT}}' --workspace '{{WORKSPACE}}' --kind <kind> --name '<候选名>' --json
84
+ ```
85
+
86
+ 写完运行格式校验:
87
+
88
+ ```bash
89
+ node '{{VALIDATE_SCRIPT}}' '{{TARGET_FILE}}'
90
+ ```
91
+
92
+ 校验失败就按错误修正,直到通过。
93
+
94
+ 写完后只回复:`已写入 {{TARGET_FILE}}`。
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Open one Douyin /article/ long-form work, extract its title, metadata and
5
+ * body text, and write article.json + article.md. stdout is one JSON object;
6
+ * Chrome stays open.
7
+ */
8
+
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+ const {
12
+ log, parseArgs, connect, installExternalProtocolGuard, restoreCookies, saveCookies,
13
+ safeGateResult, printJson, fail, ensureDir,
14
+ } = require('./lib.cjs');
15
+
16
+ function articleId(url) {
17
+ const match = String(url).match(/\/article\/(\d+)/);
18
+ if (match) return match[1];
19
+ return String(url).replace(/[?#].*$/, '').split('/').filter(Boolean).pop() || '';
20
+ }
21
+
22
+ async function readArticle(page) {
23
+ return await page.evaluate(() => {
24
+ const text = (el) => (el && el.innerText ? el.innerText.trim() : '');
25
+ const titleEl = document.querySelector('.ZuAUZjxr');
26
+ const metaEls = [...document.querySelectorAll('.lXa17VN5 .uKJCzxhH')];
27
+ let bodyEl = document.querySelector('.vZyRhR3L');
28
+ if (!bodyEl || text(bodyEl).length < 50) {
29
+ const candidates = [...document.querySelectorAll('div, article, section')]
30
+ .map((el) => ({
31
+ el,
32
+ len: text(el).length,
33
+ paragraphs: el.querySelectorAll('p').length,
34
+ }))
35
+ .filter((item) => item.paragraphs >= 3 && item.len >= 100)
36
+ .sort((a, b) => b.len - a.len);
37
+ if (candidates.length) bodyEl = candidates[0].el;
38
+ }
39
+ const paragraphs = bodyEl ? [...bodyEl.querySelectorAll('p')].map((p) => text(p)).filter(Boolean) : [];
40
+ const rawBody = text(bodyEl);
41
+ const meta = metaEls.map((el) => text(el)).filter(Boolean);
42
+ const date = meta.find((value) => /^\d{4}-\d{2}-\d{2}$/.test(value)) || '';
43
+ const readingTime = meta.find((value) => /阅读需要/.test(value)) || '';
44
+ return {
45
+ title: text(titleEl) || document.title.replace(/\s*-\s*抖音$/, ''),
46
+ date,
47
+ reading_time: readingTime,
48
+ body: paragraphs.length ? paragraphs.join('\n\n') : rawBody,
49
+ paragraphs,
50
+ body_length: rawBody.length,
51
+ };
52
+ });
53
+ }
54
+
55
+ async function waitForArticle(page) {
56
+ let article = null;
57
+ for (let attempt = 0; attempt < 20; attempt += 1) {
58
+ article = await readArticle(page);
59
+ if (article && article.title && article.body && article.body.length >= 100) return article;
60
+ await page.waitForTimeout(700);
61
+ }
62
+ return article;
63
+ }
64
+
65
+ async function main() {
66
+ const args = parseArgs(process.argv.slice(2));
67
+ const workspace = path.resolve(String(args.workspace || process.cwd()));
68
+ const articleUrl = String(args.article || '');
69
+ const cdp = String(args.cdp || 'http://127.0.0.1:9222');
70
+ const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', 'output', 'article')));
71
+ const loginState = path.resolve(String(args['login-state'] || path.join(workspace, '.fancy', 'douyin', 'login-state.json')));
72
+ if (!/\/article\//.test(articleUrl)) throw new Error('不是抖音文章作品地址:' + articleUrl);
73
+ ensureDir(outDir);
74
+
75
+ const { context } = await connect(cdp);
76
+ let page = null;
77
+ let keepPage = false;
78
+ try {
79
+ await restoreCookies(context, loginState);
80
+ page = await context.newPage();
81
+ await installExternalProtocolGuard(page);
82
+ await page.goto(articleUrl, { waitUntil: 'domcontentloaded', timeout: 60000 });
83
+ await page.waitForTimeout(3500);
84
+
85
+ const firstGate = await safeGateResult(page, outDir);
86
+ if (firstGate) {
87
+ keepPage = true;
88
+ await saveCookies(context, loginState, page.url());
89
+ printJson(firstGate);
90
+ return;
91
+ }
92
+
93
+ const article = await waitForArticle(page);
94
+ if (!article || !article.title || !article.body || article.body.length < 50) {
95
+ throw new Error('文章正文没有加载出来');
96
+ }
97
+
98
+ const afterGate = await safeGateResult(page, outDir);
99
+ if (afterGate) {
100
+ keepPage = true;
101
+ await saveCookies(context, loginState, page.url());
102
+ printJson(afterGate);
103
+ return;
104
+ }
105
+
106
+ await saveCookies(context, loginState, page.url());
107
+ const bodyFile = path.join(outDir, 'article.md');
108
+ const lines = ['# ' + article.title, ''];
109
+ if (article.date) lines.push('- 发布日期:' + article.date);
110
+ if (article.reading_time) lines.push('- ' + article.reading_time);
111
+ if (article.date || article.reading_time) lines.push('');
112
+ lines.push(article.body, '');
113
+ fs.writeFileSync(bodyFile, lines.join('\n'), 'utf8');
114
+
115
+ const record = {
116
+ id: articleId(articleUrl),
117
+ url: articleUrl,
118
+ final_url: page.url(),
119
+ type: 'article',
120
+ title: article.title,
121
+ date: article.date,
122
+ reading_time: article.reading_time,
123
+ body: article.body,
124
+ body_length: article.body.length,
125
+ body_file: bodyFile,
126
+ crawled_at: new Date().toISOString(),
127
+ dir: outDir,
128
+ };
129
+ const articleFile = path.join(outDir, 'article.json');
130
+ fs.writeFileSync(articleFile, JSON.stringify(record, null, 2) + '\n', 'utf8');
131
+ printJson({
132
+ ok: true,
133
+ login_required: false,
134
+ article: record,
135
+ article_file: articleFile,
136
+ });
137
+ } finally {
138
+ if (page && !keepPage) {
139
+ try { await page.close(); } catch { /* ignore */ }
140
+ }
141
+ }
142
+ }
143
+
144
+ main()
145
+ .then(() => process.exit(0))
146
+ .catch((err) => { fail(err); process.exit(0); });
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
3
  /**
4
- * Scan one Douyin account homepage and return its /note/ image-text works
5
- * and /video/ video works.
4
+ * Scan one Douyin account homepage and return its /note/ image-text works,
5
+ * /video/ video works and /article/ long-form articles.
6
6
  *
7
7
  * stdout is one JSON object. Progress goes to stderr. The script never closes
8
8
  * Chrome; it closes only its own page, so login state stays in the profile.
@@ -26,7 +26,8 @@ async function collectCards(page) {
26
26
  for (let round = 1; round <= 30; round += 1) {
27
27
  const batch = await page.evaluate(() => {
28
28
  const rows = [];
29
- for (const a of document.querySelectorAll('a[href*="/note/"], a[href*="/video/"]')) {
29
+ const root = document.querySelector('[data-e2e="user-post-list"]') || document;
30
+ for (const a of root.querySelectorAll('a[href*="/note/"], a[href*="/video/"], a[href*="/article/"]')) {
30
31
  // 只收「作品列表」里的卡片:必须是 li > a,并且卡片里有封面图。
31
32
  // 账号页底部还有 footer 推荐/友情链接,它们也是 <a href="/note/...">,
32
33
  // 但没有 li/img —— 之前会把「这裸考成绩…」这种页脚推荐当成作品。
@@ -34,13 +35,14 @@ async function collectCards(page) {
34
35
  if (!li) continue;
35
36
  if (a.closest('footer, nav, [role="navigation"]')) continue;
36
37
  const img = li.querySelector('img');
37
- if (!img) continue;
38
+ const isArticle = a.href.includes('/article/');
39
+ if (!img && !isArticle) continue;
38
40
  rows.push({
39
41
  href: a.href,
40
- kind: a.href.includes('/note/') ? 'note' : 'video',
42
+ kind: isArticle ? 'article' : (a.href.includes('/note/') ? 'note' : 'video'),
41
43
  text: li.innerText ? li.innerText.trim().slice(0, 300) : '',
42
- alt: img.alt ? img.alt : '',
43
- cover: img.src ? img.src : '',
44
+ alt: img && img.alt ? img.alt : '',
45
+ cover: img && img.src ? img.src : '',
44
46
  });
45
47
  }
46
48
  return rows;
@@ -49,7 +51,8 @@ async function collectCards(page) {
49
51
  for (const card of batch) {
50
52
  const href = normalize(card.href);
51
53
  // 第二层保险:页脚/相关推荐的裸链没有封面或 alt,直接丢弃。
52
- if (!card.alt && !card.cover) continue;
54
+ // 文章卡片可能没有封面图,但必须有文本。
55
+ if (!card.alt && !card.cover && !(card.kind === 'article' && card.text)) continue;
53
56
  if (/[?&]source=Baiduspider/i.test(href)) continue;
54
57
  if (!cards.has(href)) cards.set(href, { ...card, href });
55
58
  }
@@ -158,6 +161,7 @@ async function main() {
158
161
 
159
162
  const notes = cards.filter((card) => card.kind === 'note');
160
163
  const videos = cards.filter((card) => card.kind === 'video');
164
+ const articles = cards.filter((card) => card.kind === 'article');
161
165
  printJson({
162
166
  ok: true,
163
167
  login_required: false,
@@ -165,6 +169,7 @@ async function main() {
165
169
  title: await page.title(),
166
170
  notes,
167
171
  videos,
172
+ articles,
168
173
  cards_file: cardsFile,
169
174
  });
170
175
  } finally {
@@ -9,6 +9,7 @@ import { fileURLToPath } from 'url';
9
9
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
10
  const PROMPT_FILE = path.join(__dirname, 'prompts', '01-analysis-prompt.md');
11
11
  const VIDEO_PROMPT_FILE = path.join(__dirname, 'prompts', '02-video-analysis-prompt.md');
12
+ const ARTICLE_PROMPT_FILE = path.join(__dirname, 'prompts', '03-article-prompt.md');
12
13
  const CAPABILITY_PROMPT_FILE = path.join(__dirname, 'prompts', '00-capability-prompt.md');
13
14
 
14
15
  export function helpText() {
@@ -17,15 +18,17 @@ export function helpText() {
17
18
  /fancy-douyin add <主页地址> 记录一个抖音账号主页
18
19
  /fancy-douyin list 查看已记录的账号
19
20
  /fancy-douyin remove <序号|地址> 删除已记录的账号
20
- /fancy-douyin 依次采集所有账号下未处理的图文和视频作品
21
+ /fancy-douyin 依次采集所有账号下未处理的图文、视频和文章作品
21
22
  /fancy-douyin help 显示本帮助
22
23
 
23
24
  说明:
24
25
  - 先让 LLM 自检图片识别和视频识别能力:
25
26
  - 有图片识别能力:分析 /note/ 图文作品。
26
27
  - 有视频识别能力:分析 /video/ 视频作品。
27
- - 两种能力都没有:直接退出并通知,不启动采集。
28
+ - /article/ 长文不需要视觉能力,始终直接读取正文分析。
29
+ - 图片和视频能力都没有时,跳过图文/视频,只处理文章。
28
30
  - 图文作品会下载轮播原图并转成 JPG;如果轮播里混有视频页,会下载该页短视频,用场景变化检测 + 固定间隔兜底抽取关键帧拼图。
31
+ - 文章作品直接提取标题、发布日期、阅读时长和正文,按长文设定拆成原子素材。
29
32
  - 视频作品先判断时长:超过 1 分钟直接跳过;不超过 1 分钟的先看前 5 秒,
30
33
  与网文创作无关就跳过,有关才继续分析关键帧。
31
34
  - 如果内容与网文创作无关,LLM 会写入 skip 标记,该作品记为已处理并跳过。
@@ -167,6 +170,31 @@ export function videoRelevancePrompt({
167
170
  return lines.join('\n') + '\n';
168
171
  }
169
172
 
173
+ export function articlePrompt({
174
+ accountUrl,
175
+ article,
176
+ targetFile,
177
+ workspace,
178
+ queryScript,
179
+ validateScript,
180
+ }) {
181
+ const body = String(article && article.body ? article.body : '').slice(0, 60000);
182
+ return renderTemplate(ARTICLE_PROMPT_FILE, {
183
+ ACCOUNT_URL: read(accountUrl),
184
+ ARTICLE_URL: read(article && article.url),
185
+ ARTICLE_TITLE: read(article && article.title, '(无标题)'),
186
+ ARTICLE_DATE: read(article && article.date, '未知'),
187
+ ARTICLE_READING_TIME: read(article && article.reading_time, '未知'),
188
+ ARTICLE_LENGTH: String((article && (article.body_length || article.body)) ? (article.body_length || article.body.length) : 0),
189
+ ARTICLE_FILE: read(article && article.body_file, ''),
190
+ ARTICLE_BODY: body || '(文章正文为空)',
191
+ TARGET_FILE: targetFile,
192
+ QUERY_SCRIPT: queryScript,
193
+ VALIDATE_SCRIPT: validateScript,
194
+ WORKSPACE: workspace,
195
+ });
196
+ }
197
+
170
198
  export function videoAnalysisPrompt({
171
199
  accountUrl,
172
200
  video,
@@ -194,9 +222,11 @@ export function summaryText({
194
222
  scannedAccounts,
195
223
  foundNotes,
196
224
  foundVideos = 0,
225
+ foundArticles = 0,
197
226
  skippedNotesByCapability = 0,
198
227
  skippedVideosByCapability = 0,
199
228
  skippedNotes,
229
+ skippedArticles = 0,
200
230
  processedNotes,
201
231
  skippedIrrelevant = 0,
202
232
  skippedLongVideos = 0,
@@ -214,7 +244,8 @@ export function summaryText({
214
244
  '浏览器:' + (mode === 'headless' ? '无头' : '有头'),
215
245
  '发现图文:' + foundNotes + ' 篇',
216
246
  '发现视频:' + foundVideos + ' 个',
217
- '已处理过并跳过:' + skippedNotes + ' 篇',
247
+ '发现文章:' + foundArticles + ' 篇',
248
+ '已处理过并跳过:' + (skippedNotes + skippedArticles) + ' 篇',
218
249
  '能力不支持跳过:图文 ' + skippedNotesByCapability + ' 篇 / 视频 ' + skippedVideosByCapability + ' 个',
219
250
  '本次处理:' + processedNotes + ' 篇',
220
251
  '无关跳过:' + skippedIrrelevant + ' 篇',