@cloud411716/fancy-webnovel 4.17.1 → 4.18.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 -2
- package/lib/material-db.js +31 -18
- package/package.json +1 -1
- package/plugins/fancy-douyin/index.js +1 -1
- package/plugins/fancy-douyin/scripts/crawl-article.cjs +1 -1
- package/plugins/fancy-douyin/scripts/crawl-note.cjs +1 -1
- package/plugins/fancy-douyin/scripts/crawl-video.cjs +1 -1
- package/plugins/fancy-douyin/scripts/scan-account.cjs +1 -1
- package/plugins/fancy-douyin/state.js +1 -0
- package/plugins/fancy-douyin/templates.js +21 -22
package/docs/douyin-plugin.md
CHANGED
|
@@ -92,11 +92,12 @@ cookies 会额外镜像到:
|
|
|
92
92
|
<工作区>/.fancy/douyin/
|
|
93
93
|
├── accounts.json # 旧版账号文件;首次运行会迁移到 douyin_account 表
|
|
94
94
|
├── crawled.json # 旧版本地记录,仅用于一次性迁移/备份
|
|
95
|
-
├── jobs/<账号>/<作品ID>/ #
|
|
95
|
+
├── jobs/<账号>/<作品ID>/ # 稳定作品目录,重启后复用;含截图/关键帧、note.json/video.json/article.json/article.md、materials.jsonl
|
|
96
|
+
├── jobs/_runs/<时间>/ # 每次运行的 LLM 能力自检、账号扫描 profile_cards.json、登录门禁截图
|
|
96
97
|
├── login-state.json # cookies 镜像(0600)
|
|
97
98
|
├── chrome-profile/ # Chrome 登录态
|
|
98
99
|
├── chrome.json # CDP 端口、profile 与 headed/headless 模式
|
|
99
|
-
└── output
|
|
100
|
+
└── output/ # 旧版本的运行目录,仅保留兼容,不再写入
|
|
100
101
|
```
|
|
101
102
|
|
|
102
103
|
浏览器脚本部署在:
|
package/lib/material-db.js
CHANGED
|
@@ -133,8 +133,9 @@ export async function ensureMaterialDatabase(root) {
|
|
|
133
133
|
/**
|
|
134
134
|
* Remove the workspace material database.
|
|
135
135
|
*
|
|
136
|
-
*
|
|
137
|
-
*
|
|
136
|
+
* Drop the known tables one by one first, then drop the database through the
|
|
137
|
+
* registry connection. This avoids a long-lived database-level DDL conflict
|
|
138
|
+
* on large material libraries.
|
|
138
139
|
*
|
|
139
140
|
* @param {string} root workspace directory
|
|
140
141
|
* @returns {Promise<{removed: boolean, database: string}>}
|
|
@@ -149,30 +150,42 @@ export async function removeMaterialDatabase(root) {
|
|
|
149
150
|
throw new Error('素材库数据库名不合法:' + database);
|
|
150
151
|
}
|
|
151
152
|
const registry = workspace.surreal?.registry_database || 'fancy_registry';
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
password: secrets.surreal?.password,
|
|
158
|
-
});
|
|
159
|
-
await db.use({ namespace, database: registry });
|
|
153
|
+
const retryable = (err) => {
|
|
154
|
+
const message = err && err.message ? err.message : String(err);
|
|
155
|
+
return /read or write conflict|transaction can be retried|failed to commit transaction|timed out/i.test(message);
|
|
156
|
+
};
|
|
157
|
+
const runWithRetry = async (label, fn) => {
|
|
160
158
|
let lastError = null;
|
|
161
|
-
const
|
|
162
|
-
for (const delay of delays) {
|
|
159
|
+
for (const delay of [0, 1000, 2500, 5000]) {
|
|
163
160
|
if (delay) await new Promise((resolve) => setTimeout(resolve, delay));
|
|
164
161
|
try {
|
|
165
|
-
await
|
|
166
|
-
return
|
|
162
|
+
await fn();
|
|
163
|
+
return;
|
|
167
164
|
} catch (err) {
|
|
168
|
-
|
|
169
|
-
const retryable = /read or write conflict|transaction can be retried|failed to commit transaction/i.test(message);
|
|
170
|
-
if (!retryable) throw err;
|
|
165
|
+
if (!retryable(err)) throw err;
|
|
171
166
|
lastError = err;
|
|
172
167
|
}
|
|
173
168
|
}
|
|
174
|
-
throw new Error('
|
|
169
|
+
throw new Error(label + '时数据库事务冲突,可能有其他素材/抖音任务正在读写。请等任务结束后重试。原始错误:'
|
|
175
170
|
+ (lastError && lastError.message ? lastError.message : String(lastError)));
|
|
171
|
+
};
|
|
172
|
+
const db = new Surreal({ engines: { ...createRemoteEngines() } });
|
|
173
|
+
try {
|
|
174
|
+
await db.connect(rpcUrl(workspace));
|
|
175
|
+
await db.signin({
|
|
176
|
+
username: secrets.surreal?.username || 'root',
|
|
177
|
+
password: secrets.surreal?.password,
|
|
178
|
+
});
|
|
179
|
+
// Drop the large material table first. Asking SurrealDB to drop the whole
|
|
180
|
+
// database in one DDL transaction can stay in a read/write conflict for a
|
|
181
|
+
// long time on a library with >100k records.
|
|
182
|
+
await db.use({ namespace, database });
|
|
183
|
+
for (const table of ['material', 'douyin_job', 'douyin_meta', 'douyin_account']) {
|
|
184
|
+
await runWithRetry('删除素材表 ' + table, () => db.query('REMOVE TABLE IF EXISTS ' + table + ';'));
|
|
185
|
+
}
|
|
186
|
+
await db.use({ namespace, database: registry });
|
|
187
|
+
await runWithRetry('删除素材库', () => db.query('REMOVE DATABASE IF EXISTS ' + database + ';'));
|
|
188
|
+
return { removed: true, database };
|
|
176
189
|
} finally {
|
|
177
190
|
try { await db.close(); } catch { /* ignore */ }
|
|
178
191
|
}
|
package/package.json
CHANGED
|
@@ -932,7 +932,7 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
932
932
|
return notify(session, 'error', '还没有记录抖音账号。先运行:/fancy-douyin add <主页地址>');
|
|
933
933
|
}
|
|
934
934
|
|
|
935
|
-
const runDir = path.join(paths.
|
|
935
|
+
const runDir = path.join(paths.runs, stampOfNow());
|
|
936
936
|
fs.mkdirSync(runDir, { recursive: true });
|
|
937
937
|
fs.mkdirSync(paths.jobs, { recursive: true });
|
|
938
938
|
|
|
@@ -67,7 +67,7 @@ async function main() {
|
|
|
67
67
|
const workspace = path.resolve(String(args.workspace || process.cwd()));
|
|
68
68
|
const articleUrl = String(args.article || '');
|
|
69
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', '
|
|
70
|
+
const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', 'jobs', '_runs', 'article')));
|
|
71
71
|
const loginState = path.resolve(String(args['login-state'] || path.join(workspace, '.fancy', 'douyin', 'login-state.json')));
|
|
72
72
|
if (!/\/article\//.test(articleUrl)) throw new Error('不是抖音文章作品地址:' + articleUrl);
|
|
73
73
|
ensureDir(outDir);
|
|
@@ -445,7 +445,7 @@ async function main() {
|
|
|
445
445
|
const workspace = path.resolve(String(args.workspace || process.cwd()));
|
|
446
446
|
const noteUrl = String(args.note || '');
|
|
447
447
|
const cdp = String(args.cdp || 'http://127.0.0.1:9222');
|
|
448
|
-
const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', '
|
|
448
|
+
const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', 'jobs', '_runs', 'note')));
|
|
449
449
|
const loginState = path.resolve(String(args['login-state'] || path.join(workspace, '.fancy', 'douyin', 'login-state.json')));
|
|
450
450
|
if (!/\/note\//.test(noteUrl)) throw new Error('不是抖音图文作品地址:' + noteUrl);
|
|
451
451
|
ensureDir(outDir);
|
|
@@ -176,7 +176,7 @@ async function main() {
|
|
|
176
176
|
const workspace = path.resolve(String(args.workspace || process.cwd()));
|
|
177
177
|
const videoUrl = String(args.video || '');
|
|
178
178
|
const cdp = String(args.cdp || 'http://127.0.0.1:9222');
|
|
179
|
-
const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', '
|
|
179
|
+
const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', 'jobs', '_runs', 'video')));
|
|
180
180
|
const loginState = path.resolve(String(args['login-state'] || path.join(workspace, '.fancy', 'douyin', 'login-state.json')));
|
|
181
181
|
const maxSeconds = Number(args['max-seconds'] || 60);
|
|
182
182
|
if (!/\/video\//.test(videoUrl)) throw new Error('不是抖音视频作品地址:' + videoUrl);
|
|
@@ -98,7 +98,7 @@ async function main() {
|
|
|
98
98
|
const workspace = path.resolve(String(args.workspace || process.cwd()));
|
|
99
99
|
const account = String(args.account || '');
|
|
100
100
|
const cdp = String(args.cdp || 'http://127.0.0.1:9222');
|
|
101
|
-
const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', '
|
|
101
|
+
const outDir = path.resolve(String(args.out || path.join(workspace, '.fancy', 'douyin', 'jobs', '_runs', 'scan')));
|
|
102
102
|
const loginState = path.resolve(String(args['login-state'] || path.join(workspace, '.fancy', 'douyin', 'login-state.json')));
|
|
103
103
|
if (!account) throw new Error('缺少 --account 主页地址');
|
|
104
104
|
ensureDir(outDir);
|
|
@@ -25,28 +25,27 @@ export function helpText() {
|
|
|
25
25
|
/fancy-douyin help 显示本帮助
|
|
26
26
|
|
|
27
27
|
说明:
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
- 浏览器脚本部署在 <工作区>/.fancy-tools/fancy-douyin/。`;
|
|
28
|
+
1. 运行前会检查当前模型是否支持图片和视频识别。
|
|
29
|
+
- 支持图片识别:分析 /note/ 图文作品。
|
|
30
|
+
- 支持视频识别:分析 /video/ 视频作品。
|
|
31
|
+
- 两种能力都没有:跳过图文/视频,只处理 /article/ 长文。
|
|
32
|
+
2. 图文作品会下载轮播原图并转成 JPG;如果轮播里混有视频页,会下载该页短视频,用场景变化检测 + 固定间隔抽取关键帧拼图。
|
|
33
|
+
3. 文章作品直接提取标题、发布日期、阅读时长和正文,按长文设定拆成原子素材。
|
|
34
|
+
4. 采集和分析可以并行:父进程继续扫描、采集下一个作品,分析子 Agent 同时处理已经入队的作品。
|
|
35
|
+
5. 父进程负责采集、校验、入库和任务状态;子 Agent 只写各作品的 materials.jsonl。
|
|
36
|
+
6. 作品任务状态记录在素材库的 douyin_job 表;中途重启会复用稳定任务目录,已导入/已跳过的作品不会重采。
|
|
37
|
+
7. 视觉能力自检和视频前 5 秒相关性筛选会自动完成;没有子 Agent 服务时回退到父 Agent 串行处理。
|
|
38
|
+
8. 子 Agent 并发数由 FANCY_DOUYIN_SUBAGENTS 控制(默认 5,范围 1–6,0 关闭)。
|
|
39
|
+
9. 视频作品先判断时长:超过 1 分钟直接跳过;不超过 1 分钟的先看前 5 秒,与网文创作无关就跳过,有关才继续分析关键帧。
|
|
40
|
+
10. 如果内容与网文创作无关,LLM 会写入 skip 标记,该作品记为已处理并跳过。
|
|
41
|
+
11. 素材按 material JSONL 格式写入数据库,source 固定为 other,kind 用中文作品主题。
|
|
42
|
+
12. 已成功入库、确认无关或作品级失败的作品记录在素材库 douyin_job 表,后续跳过;账号级失败仍会重试。
|
|
43
|
+
13. 登录态保存在 <工作区>/.fancy/douyin/chrome-profile/,并镜像到 login-state.json。
|
|
44
|
+
14. 首次需要登录时用有头 Chrome;登录态有效后后续运行自动使用无头 Chrome。
|
|
45
|
+
15. 每次运行结束会自动关闭 Chrome,释放资源。
|
|
46
|
+
16. 需要登录或安全验证时会弹窗,请在 Chrome 窗口手动完成,然后选择「已登陆」。
|
|
47
|
+
17. 浏览器脚本部署在 <工作区>/.fancy-tools/fancy-douyin/。
|
|
48
|
+
`;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
export function loginQuestion(paths) {
|