@cloud411716/fancy-webnovel 4.20.0 → 4.21.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 +3 -3
- package/docs/workspace-mcp.md +1 -1
- package/package.json +1 -1
- package/plugins/fancy-douyin/deploy.js +2 -2
- package/plugins/fancy-douyin/index.js +2 -61
- package/plugins/fancy-douyin/jobs.js +2 -2
- package/plugins/fancy-douyin/state.js +9 -20
- package/plugins/fancy-douyin/subagents.js +2 -2
- package/plugins/fancy-douyin/templates.js +1 -2
package/docs/douyin-plugin.md
CHANGED
|
@@ -91,7 +91,7 @@ cookies 会额外镜像到:
|
|
|
91
91
|
```text
|
|
92
92
|
<工作区>/.fancy/douyin/
|
|
93
93
|
├── accounts.json # 旧版账号文件;首次运行会迁移到 douyin_account 表
|
|
94
|
-
├── crawled.json #
|
|
94
|
+
├── crawled.json # 旧版本地记录;仅检测到旧文件时读取迁移,不再生成
|
|
95
95
|
├── jobs/<账号>/<作品ID>/ # 稳定作品目录,重启后复用;含截图/关键帧、note.json/video.json/article.json/article.md、materials.jsonl
|
|
96
96
|
├── jobs/_runs/<时间>/ # 每次运行的 LLM 能力自检、账号扫描 profile_cards.json、登录门禁截图
|
|
97
97
|
├── login-state.json # cookies 镜像(0600)
|
|
@@ -143,7 +143,7 @@ FANCY_DOUYIN_SUBAGENTS=0 # 关闭子 Agent,回退单 Agent 串行
|
|
|
143
143
|
|
|
144
144
|
要求 DSH 挂载了 subagent 服务和 `spawn` provider。没有子 Agent 服务、provider 不存在或并发数为 0 时,会自动回退到原来的单 Agent 流程。
|
|
145
145
|
|
|
146
|
-
子 Agent 不操作 Chrome
|
|
146
|
+
子 Agent 不操作 Chrome,不写本地状态文件,不运行 `import.js`,也不直接写素材数据库;数据库导入和采集状态只由父进程串行处理,避免并发覆盖。
|
|
147
147
|
|
|
148
148
|
采集、分析和入库重叠时,任务列表会同时把“采集作品”“分析素材”“写入素材库”标为进行中:采集行显示已扫描账号数和已入队作品数,分析行显示已分析/已入队和当前并发数,写入行显示已写入/已入队作品数。所有账号采集完成后,“采集作品”才标记完成;“分析素材”和“写入素材库”继续转圈,直到所有作品分析、校验和入库完成。
|
|
149
149
|
|
|
@@ -192,7 +192,7 @@ id / kind / subkind / name / tags / genres / note / source
|
|
|
192
192
|
- `analysis_status`:pending / analyzing / analyzed / failed
|
|
193
193
|
- `import_status`:pending / imported / skipped / failed
|
|
194
194
|
|
|
195
|
-
|
|
195
|
+
数据库里的 `douyin_job` 是唯一运行时状态源,新版本不再生成 `crawled.json`。如果旧工作区里已经存在这个文件,首次运行仍会把它一次性迁移到 `douyin_job`(已迁移过的由 `douyin_meta` 标记阻止重复导入)。
|
|
196
196
|
|
|
197
197
|
## 注意
|
|
198
198
|
|
package/docs/workspace-mcp.md
CHANGED
|
@@ -129,7 +129,7 @@ namespace: fancy
|
|
|
129
129
|
跳过,不超过 1 分钟的先看前 5 秒,与网文创作无关也跳过;文章按标题层级拆成原子
|
|
130
130
|
设定。内容交给 LLM 提取素材,按 material JSONL 写入数据库,`source` 固定为
|
|
131
131
|
`other`。作品任务状态记录在素材库的 `douyin_job` 表中,旧版工作区的
|
|
132
|
-
`/.fancy/douyin/crawled.json`
|
|
132
|
+
旧版 `/.fancy/douyin/crawled.json` 如果存在,会一次性迁移;新版本不再生成该文件。采集完成后可由 DSH 子 Agent 并行分析,`FANCY_DOUYIN_SUBAGENTS` 控制并发数(默认 5,0 关闭);没有 subagent 服务时自动回退单 Agent。
|
|
133
133
|
|
|
134
134
|
登录态保存在工作区 `/.fancy/douyin/chrome-profile/`,并镜像 cookies 到
|
|
135
135
|
`login-state.json`。首次需要登录时使用有头 Chrome,登录态有效后后续运行自动
|
package/package.json
CHANGED
|
@@ -115,8 +115,8 @@ export function deployDouyinTools(root) {
|
|
|
115
115
|
writeToolFile(path.join(target, 'README.txt'), [
|
|
116
116
|
'本目录由 fancy-douyin 自动部署。',
|
|
117
117
|
'浏览器脚本:start-chrome.cjs / scan-account.cjs / crawl-note.cjs / crawl-video.cjs / crawl-article.cjs',
|
|
118
|
-
'视频抽帧:video-frames.cjs
|
|
119
|
-
'
|
|
118
|
+
'视频抽帧:video-frames.cjs(密集采样 + 稳定画面段 + 清晰度评分)',
|
|
119
|
+
'登录态在 <工作区>/.fancy/douyin/ 下;采集任务状态在素材库 douyin_job 表。',
|
|
120
120
|
'不要手工修改本目录脚本;重新运行 /fancy-douyin 会刷新。',
|
|
121
121
|
'',
|
|
122
122
|
].join('\n'), problems);
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
accountSlug,
|
|
27
27
|
douyinPaths,
|
|
28
28
|
ensureDouyinDir,
|
|
29
|
-
markCrawled,
|
|
30
29
|
noteIdFromUrl,
|
|
31
30
|
readCrawled,
|
|
32
31
|
} from './state.js';
|
|
@@ -765,7 +764,7 @@ function first5sFrameText(video) {
|
|
|
765
764
|
export function subagentTaskPrompt(job, root, materialTools) {
|
|
766
765
|
const lines = [
|
|
767
766
|
'你是 fancy-douyin 的分析子 Agent,只处理下面这一篇作品。',
|
|
768
|
-
'不要扫描账号,不要启动或操作 Chrome
|
|
767
|
+
'不要扫描账号,不要启动或操作 Chrome,不要写本地状态文件,不要运行 import.js 或直接写素材数据库。',
|
|
769
768
|
'只读取给定文件,按提示词提取素材,写入目标 JSONL,运行 validate.js 后结束。',
|
|
770
769
|
'如果需要创建测试文件,放在当前项目的 `.tmp` 目录下(绝对路径:`' + path.join(root, '.tmp') + '`),并且测试后不需要删除测试文件。',
|
|
771
770
|
'禁止执行 rm、rmdir、find -delete、git clean 等删除命令,也不要删除已有文件。',
|
|
@@ -843,7 +842,7 @@ async function runSubagentAnalysisJob({
|
|
|
843
842
|
error: '子 Agent 没有写入目标文件' + (stop ? '(' + stop + ')' : ''),
|
|
844
843
|
};
|
|
845
844
|
}
|
|
846
|
-
//
|
|
845
|
+
// 文件已经写出,由父进程在串行锁内统一校验、导入和更新 douyin_job。
|
|
847
846
|
return { ok: true, needsFinalize: true };
|
|
848
847
|
}
|
|
849
848
|
|
|
@@ -1015,25 +1014,6 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1015
1014
|
const withStateLock = createSerialLock();
|
|
1016
1015
|
const markJobFailedLocked = async (job, reason, { crawl = false } = {}) => {
|
|
1017
1016
|
if (!job || !job.id) return;
|
|
1018
|
-
markCrawled(root, job.id, {
|
|
1019
|
-
account_url: job.accountUrl,
|
|
1020
|
-
url: job.url || (job.card && job.card.href) || '',
|
|
1021
|
-
title: job.title || (job.card && job.card.text) || '',
|
|
1022
|
-
type: job.type,
|
|
1023
|
-
duration: job.duration,
|
|
1024
|
-
screenshots: job.type === 'note' && Array.isArray(job.screenshots)
|
|
1025
|
-
? job.screenshots.map((shot) => shot.file)
|
|
1026
|
-
: undefined,
|
|
1027
|
-
body_file: job.article && job.article.body_file,
|
|
1028
|
-
reading_time: job.article && job.article.reading_time,
|
|
1029
|
-
body_length: job.article && job.article.body_length,
|
|
1030
|
-
dir: job.dir,
|
|
1031
|
-
inserted: 0,
|
|
1032
|
-
skipped: 0,
|
|
1033
|
-
skip: true,
|
|
1034
|
-
failed: true,
|
|
1035
|
-
reason,
|
|
1036
|
-
});
|
|
1037
1017
|
crawled[job.id] = true;
|
|
1038
1018
|
if (job.jobKey) {
|
|
1039
1019
|
await updateJob(jobStore.db, job.jobKey, {
|
|
@@ -1050,18 +1030,6 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1050
1030
|
|
|
1051
1031
|
const markJobSkippedLocked = async (job, reason, { crawl = false } = {}) => {
|
|
1052
1032
|
if (!job || !job.id) return;
|
|
1053
|
-
markCrawled(root, job.id, {
|
|
1054
|
-
account_url: job.accountUrl,
|
|
1055
|
-
url: job.url || (job.card && job.card.href) || '',
|
|
1056
|
-
title: job.title || (job.card && job.card.text) || '',
|
|
1057
|
-
type: job.type,
|
|
1058
|
-
duration: job.duration,
|
|
1059
|
-
dir: job.dir,
|
|
1060
|
-
inserted: 0,
|
|
1061
|
-
skipped: 0,
|
|
1062
|
-
skip: true,
|
|
1063
|
-
reason,
|
|
1064
|
-
});
|
|
1065
1033
|
crawled[job.id] = true;
|
|
1066
1034
|
if (job.jobKey) {
|
|
1067
1035
|
await updateJob(jobStore.db, job.jobKey, {
|
|
@@ -1110,22 +1078,6 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1110
1078
|
if (writeActive) taskList.progressAt(5, writeText());
|
|
1111
1079
|
};
|
|
1112
1080
|
|
|
1113
|
-
const jobRecord = (job, extra = {}) => ({
|
|
1114
|
-
account_url: job.accountUrl,
|
|
1115
|
-
url: job.url,
|
|
1116
|
-
title: job.title || (job.card && job.card.text) || '',
|
|
1117
|
-
type: job.type,
|
|
1118
|
-
duration: job.duration,
|
|
1119
|
-
screenshots: job.type === 'note' && Array.isArray(job.screenshots)
|
|
1120
|
-
? job.screenshots.map((shot) => shot.file)
|
|
1121
|
-
: undefined,
|
|
1122
|
-
body_file: job.article && job.article.body_file,
|
|
1123
|
-
reading_time: job.article && job.article.reading_time,
|
|
1124
|
-
body_length: job.article && job.article.body_length,
|
|
1125
|
-
dir: job.dir,
|
|
1126
|
-
...extra,
|
|
1127
|
-
});
|
|
1128
|
-
|
|
1129
1081
|
const finalizeJob = async (job, analyzed) => {
|
|
1130
1082
|
await withStateLock(async () => {
|
|
1131
1083
|
if (!writeActive) {
|
|
@@ -1162,12 +1114,6 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1162
1114
|
}
|
|
1163
1115
|
if (analyzed.skipped) {
|
|
1164
1116
|
skippedIrrelevant += 1;
|
|
1165
|
-
markCrawled(root, job.id, jobRecord(job, {
|
|
1166
|
-
inserted: 0,
|
|
1167
|
-
skipped: 0,
|
|
1168
|
-
skip: true,
|
|
1169
|
-
reason: analyzed.reason || '与网文创作无关',
|
|
1170
|
-
}));
|
|
1171
1117
|
if (job.jobKey) {
|
|
1172
1118
|
await updateJob(jobStore.db, job.jobKey, {
|
|
1173
1119
|
analysis_status: 'analyzed',
|
|
@@ -1181,10 +1127,6 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1181
1127
|
} else {
|
|
1182
1128
|
inserted += analyzed.inserted || 0;
|
|
1183
1129
|
skippedMaterials += analyzed.skipped || 0;
|
|
1184
|
-
markCrawled(root, job.id, jobRecord(job, {
|
|
1185
|
-
inserted: analyzed.inserted || 0,
|
|
1186
|
-
skipped: analyzed.skipped || 0,
|
|
1187
|
-
}));
|
|
1188
1130
|
if (job.jobKey) {
|
|
1189
1131
|
await updateJob(jobStore.db, job.jobKey, {
|
|
1190
1132
|
analysis_status: 'analyzed',
|
|
@@ -1800,7 +1742,6 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1800
1742
|
skippedMaterials,
|
|
1801
1743
|
failures,
|
|
1802
1744
|
outputDir: runDir,
|
|
1803
|
-
stateFile: paths.crawled,
|
|
1804
1745
|
aborted,
|
|
1805
1746
|
mode: browser.mode,
|
|
1806
1747
|
analysisMode: useSubagents ? 'subagent' : 'single',
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Douyin job state stored in the material database.
|
|
3
3
|
*
|
|
4
4
|
* Keeping this next to `material` means a database backup/restore carries both
|
|
5
|
-
* the imported materials and the knowledge of which works produced them.
|
|
6
|
-
* workspace `crawled.json`
|
|
5
|
+
* the imported materials and the knowledge of which works produced them. A
|
|
6
|
+
* legacy workspace `crawled.json` is only read for one-time migration.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import fs from 'fs';
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Workspace state for fancy-douyin.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Account and work state live in the material database (`douyin_account` and
|
|
5
|
+
* `douyin_job`). The Chrome profile, login cookies and downloaded screenshots
|
|
5
6
|
* live under <workspace>/.fancy/douyin. The deployed crawler scripts live under
|
|
6
7
|
* <workspace>/.fancy-tools/fancy-douyin.
|
|
7
8
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* the material library, or after it was confirmed irrelevant/long and skipped,
|
|
11
|
-
* so failed works are retried on the next run.
|
|
9
|
+
* A legacy `crawled.json` is only read when an old workspace still has one, so
|
|
10
|
+
* it can be migrated once into `douyin_job`; new runs never write it.
|
|
12
11
|
*/
|
|
13
12
|
|
|
14
13
|
import fs from 'fs';
|
|
@@ -187,26 +186,16 @@ export function removeAccount(root, selector) {
|
|
|
187
186
|
return { removed: true, url: removed.url, accounts };
|
|
188
187
|
}
|
|
189
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Legacy workspace crawl history. Runtime state lives in `douyin_job`; this
|
|
191
|
+
* reader exists only so old workspaces can still skip/migrate entries that
|
|
192
|
+
* predate the database. New runs never write this file.
|
|
193
|
+
*/
|
|
190
194
|
export function readCrawled(root) {
|
|
191
195
|
const value = readJsonFile(douyinPaths(root).crawled);
|
|
192
196
|
return value && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
193
197
|
}
|
|
194
198
|
|
|
195
|
-
export function writeCrawled(root, state) {
|
|
196
|
-
const paths = ensureDouyinDir(root);
|
|
197
|
-
atomicWriteJson(paths.crawled, state, { mode: 0o600 });
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export function markCrawled(root, noteId, data) {
|
|
201
|
-
const state = readCrawled(root);
|
|
202
|
-
state[noteId] = {
|
|
203
|
-
...data,
|
|
204
|
-
crawled_at: new Date().toISOString(),
|
|
205
|
-
};
|
|
206
|
-
writeCrawled(root, state);
|
|
207
|
-
return state[noteId];
|
|
208
|
-
}
|
|
209
|
-
|
|
210
199
|
export function accountListText(accountsOrRoot, countsOverride = null) {
|
|
211
200
|
const accounts = Array.isArray(accountsOrRoot) ? accountsOrRoot : readAccounts(accountsOrRoot);
|
|
212
201
|
if (!accounts.length) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The Douyin crawler still runs in the parent process. Only the LLM analysis
|
|
5
5
|
* of already-prepared works is delegated to child agents. That keeps Chrome,
|
|
6
|
-
*
|
|
6
|
+
* the job database, and material imports single-writer while allowing several
|
|
7
7
|
* image/video/article analyses to run at once.
|
|
8
8
|
*/
|
|
9
9
|
|
|
@@ -57,7 +57,7 @@ export async function runJobPool(items, concurrency, worker) {
|
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* A small async mutex. Finalization is deliberately serialized because it
|
|
60
|
-
*
|
|
60
|
+
* updates douyin_job and opens the material database; the LLM work itself is
|
|
61
61
|
* already parallel.
|
|
62
62
|
*/
|
|
63
63
|
export function createSerialLock() {
|
|
@@ -242,7 +242,6 @@ export function summaryText({
|
|
|
242
242
|
skippedMaterials,
|
|
243
243
|
failures,
|
|
244
244
|
outputDir,
|
|
245
|
-
stateFile,
|
|
246
245
|
aborted,
|
|
247
246
|
mode,
|
|
248
247
|
analysisMode = 'single',
|
|
@@ -273,6 +272,6 @@ export function summaryText({
|
|
|
273
272
|
lines.push('作品级失败已记录为跳过,下次不再重试;账号级失败仍会在下次重试。');
|
|
274
273
|
}
|
|
275
274
|
lines.push('输出目录:' + outputDir);
|
|
276
|
-
lines.push('
|
|
275
|
+
lines.push('任务状态:素材库 douyin_job 表');
|
|
277
276
|
return lines.join('\n');
|
|
278
277
|
}
|