@cloud411716/fancy-webnovel 4.30.2 → 4.30.3
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
|
@@ -36,7 +36,7 @@ https://www.douyin.com/user/MS4wLjABAAAA...
|
|
|
36
36
|
LLM 能力自检(图片 / 视频)
|
|
37
37
|
→ 两种能力都没有:退出并通知
|
|
38
38
|
→ 依次扫描账号主页,收集 /note/ 图文、/video/ 视频和 /article/ 文章
|
|
39
|
-
→ 跳过 douyin_job
|
|
39
|
+
→ 跳过 douyin_job 表中已导入、已确认无关或内容级失败的作品;超时/中断的 pending 作品会重试
|
|
40
40
|
→ 文章:提取标题、发布日期、阅读时长和正文
|
|
41
41
|
→ 图文:逐页判断类型
|
|
42
42
|
→ 图片页:下载轮播原图并转成 JPG(避免滚动时截到半张图)
|
|
@@ -53,7 +53,7 @@ LLM 能力自检(图片 / 视频)
|
|
|
53
53
|
→ 继续下一篇
|
|
54
54
|
```
|
|
55
55
|
|
|
56
|
-
|
|
56
|
+
内容级失败(下载、抽帧、文章正文提取失败、LLM 整理失败)会记录为 `failed`,本次跳过且下次不再重试;超时/中断属于可重试失败,会保持 `pending` 并在下次运行继续。子 Agent 超时前已经写出 `materials.jsonl` 的,父进程会先校验导入,能救回多少算多少。账号扫描失败不会写入作品记录,下次运行仍会重试。
|
|
57
57
|
|
|
58
58
|
## 登录与验证
|
|
59
59
|
|
|
@@ -132,13 +132,15 @@ cookies 会额外镜像到:
|
|
|
132
132
|
<工作区>/.fancy/douyin/jobs/<账号>/<作品ID>/
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
中途重启 DSH
|
|
135
|
+
中途重启 DSH 后,已导入/已跳过/内容级失败的作品直接跳过;已有 `materials.jsonl` 的只重新校验导入;已有采集文件的复用文件,不重新下载;超时/中断的 pending 作品继续重试。
|
|
136
136
|
|
|
137
|
-
|
|
137
|
+
并发数和超时:
|
|
138
138
|
|
|
139
139
|
```bash
|
|
140
|
-
FANCY_DOUYIN_SUBAGENTS=5
|
|
141
|
-
FANCY_DOUYIN_SUBAGENTS=0
|
|
140
|
+
FANCY_DOUYIN_SUBAGENTS=5 # 默认 5,范围 1–6
|
|
141
|
+
FANCY_DOUYIN_SUBAGENTS=0 # 关闭子 Agent,回退单 Agent 串行
|
|
142
|
+
FANCY_DOUYIN_ANALYSIS_TIMEOUT_MS=2400000 # 单个作品分析预算,默认 40 分钟
|
|
143
|
+
FANCY_DOUYIN_NOTE_TIMEOUT_MS=600000 # 图文轮播采集预算,默认 10 分钟
|
|
142
144
|
```
|
|
143
145
|
|
|
144
146
|
要求 DSH 挂载了 subagent 服务和 `spawn` provider。没有子 Agent 服务、provider 不存在或并发数为 0 时,会自动回退到原来的单 Agent 流程。
|
package/lib/infra.js
CHANGED
|
@@ -505,7 +505,7 @@ export function spawnScript(cmd, args, { timeout = 30000, cwd, env, onSpawn } =
|
|
|
505
505
|
// detached:true —— 子进程成为独立进程组的组长,超时时可整组清理。
|
|
506
506
|
proc = spawn(cmd, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], detached: true });
|
|
507
507
|
} catch (spawnErr) {
|
|
508
|
-
resolve({ ok: false, output: '', error: spawnErr.message, stderr: '' });
|
|
508
|
+
resolve({ ok: false, output: '', error: spawnErr.message, stderr: '', timedOut: false });
|
|
509
509
|
return;
|
|
510
510
|
}
|
|
511
511
|
|
|
@@ -573,6 +573,7 @@ export function spawnScript(cmd, args, { timeout = 30000, cwd, env, onSpawn } =
|
|
|
573
573
|
: undefined),
|
|
574
574
|
stderr,
|
|
575
575
|
code,
|
|
576
|
+
timedOut,
|
|
576
577
|
});
|
|
577
578
|
return;
|
|
578
579
|
} catch (_) {
|
|
@@ -580,15 +581,18 @@ export function spawnScript(cmd, args, { timeout = 30000, cwd, env, onSpawn } =
|
|
|
580
581
|
resolve({
|
|
581
582
|
ok: false,
|
|
582
583
|
output: stdout,
|
|
583
|
-
|
|
584
|
+
// 非 JSON 输出也必须让超时优先于 stderr。否则脚本被 kill 时,
|
|
585
|
+
// 最后几行普通日志会被当成失败原因,真正的超时反而看不见。
|
|
586
|
+
error: timedOut ? `timeout after ${timeout}ms` : (stderr.trim() || `exit ${code}`),
|
|
584
587
|
stderr,
|
|
585
588
|
code,
|
|
589
|
+
timedOut,
|
|
586
590
|
});
|
|
587
591
|
}
|
|
588
592
|
});
|
|
589
593
|
proc.on('error', (err) => {
|
|
590
594
|
clearTimeout(timer);
|
|
591
|
-
resolve({ ok: false, output: '', error: err.message, stderr: errParts.join(''), code: -1 });
|
|
595
|
+
resolve({ ok: false, output: '', error: err.message, stderr: errParts.join(''), code: -1, timedOut: false });
|
|
592
596
|
});
|
|
593
597
|
});
|
|
594
598
|
}
|
package/package.json
CHANGED
|
@@ -47,8 +47,15 @@ import {
|
|
|
47
47
|
|
|
48
48
|
export const inject = ['commands', 'userQuestions'];
|
|
49
49
|
|
|
50
|
+
function envMs(name, fallback) {
|
|
51
|
+
const value = Number(process.env[name]);
|
|
52
|
+
return Number.isFinite(value) && value > 0 ? value : fallback;
|
|
53
|
+
}
|
|
54
|
+
|
|
50
55
|
const FRAME_SELECTION_VERSION = 4;
|
|
51
|
-
|
|
56
|
+
// 图片密集的清单作品会读几十张切图,20 分钟经常在“准备写 JSONL”时被截断。
|
|
57
|
+
// 40 分钟给长尾作品留出余量;仍可通过环境变量按机器速度调整。
|
|
58
|
+
const ANALYSIS_TIMEOUT_MS = envMs('FANCY_DOUYIN_ANALYSIS_TIMEOUT_MS', 40 * 60 * 1000);
|
|
52
59
|
const ANALYSIS_IDLE_GRACE_MS = 60 * 1000;
|
|
53
60
|
const CAPABILITY_TIMEOUT_MS = 5 * 60 * 1000;
|
|
54
61
|
const CAPABILITY_IDLE_GRACE_MS = 30 * 1000;
|
|
@@ -56,6 +63,8 @@ const RELEVANCE_TIMEOUT_MS = 5 * 60 * 1000;
|
|
|
56
63
|
const RELEVANCE_IDLE_GRACE_MS = 30 * 1000;
|
|
57
64
|
const SCRIPT_TIMEOUT_MS = 4 * 60 * 1000;
|
|
58
65
|
const VIDEO_SCRIPT_TIMEOUT_MS = 10 * 60 * 1000;
|
|
66
|
+
// 图文轮播可能包含几十页图片和视频切片,不能按普通图文的 4 分钟算。
|
|
67
|
+
const NOTE_SCRIPT_TIMEOUT_MS = envMs('FANCY_DOUYIN_NOTE_TIMEOUT_MS', 10 * 60 * 1000);
|
|
59
68
|
const MAX_VIDEO_SECONDS = 60;
|
|
60
69
|
const LOGIN_RETRIES = 5;
|
|
61
70
|
const NOTE_DELAY_MIN_MS = 6000;
|
|
@@ -74,6 +83,34 @@ function sleep(ms) {
|
|
|
74
83
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
75
84
|
}
|
|
76
85
|
|
|
86
|
+
/**
|
|
87
|
+
* 把 `timeout after 600000ms` 变成人能直接读的原因。
|
|
88
|
+
* 采集脚本被 kill 时 stderr 往往是一大段进度日志,不能拿它当失败原因。
|
|
89
|
+
*/
|
|
90
|
+
export function humanizeTimeoutMessage(text) {
|
|
91
|
+
const raw = String(text || '').trim();
|
|
92
|
+
const match = /timeout after (\d+)ms/i.exec(raw);
|
|
93
|
+
if (!match) return raw || '采集超时';
|
|
94
|
+
const seconds = Math.max(1, Math.round(Number(match[1]) / 1000));
|
|
95
|
+
if (seconds < 60) return `采集超时(超过 ${seconds} 秒未完成)`;
|
|
96
|
+
return `采集超时(超过 ${Math.max(1, Math.round(seconds / 60))} 分钟未完成)`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function conciseError(text, max = 1200) {
|
|
100
|
+
const value = String(text || '').trim();
|
|
101
|
+
if (value.length <= max) return value;
|
|
102
|
+
return value.slice(0, max) + '…(完整日志见同目录 error.log)';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function saveErrorLog(outDir, text) {
|
|
106
|
+
const value = String(text || '').trim();
|
|
107
|
+
if (!outDir || !value) return;
|
|
108
|
+
try {
|
|
109
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
110
|
+
fs.writeFileSync(path.join(outDir, 'error.log'), value + '\n', 'utf8');
|
|
111
|
+
} catch { /* 日志写失败不能反过来中断采集 */ }
|
|
112
|
+
}
|
|
113
|
+
|
|
77
114
|
function authFailureText(text) {
|
|
78
115
|
return /登录|验证|login_required/i.test(String(text || ''));
|
|
79
116
|
}
|
|
@@ -157,6 +194,16 @@ async function stopChrome(root, tools, paths) {
|
|
|
157
194
|
async function runWithLogin(ctx, invocation, session, root, toolPath, args, outDir, paths, label, nodePath, browser, tools, timeout = SCRIPT_TIMEOUT_MS) {
|
|
158
195
|
for (let attempt = 1; attempt <= LOGIN_RETRIES; attempt += 1) {
|
|
159
196
|
const { result, json } = await runTool(toolPath, args, { root, nodePath, timeout });
|
|
197
|
+
// 超时优先于脚本可能已经写出的半截 JSON;否则半截 login_required / ok:true
|
|
198
|
+
// 会把真正的超时带偏。
|
|
199
|
+
if (result.timedOut) {
|
|
200
|
+
saveErrorLog(outDir, result.stderr);
|
|
201
|
+
return {
|
|
202
|
+
ok: false,
|
|
203
|
+
timeout: true,
|
|
204
|
+
error: conciseError(humanizeTimeoutMessage(result.error)),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
160
207
|
if (json && json.login_required) {
|
|
161
208
|
if (browser.mode === 'headless') {
|
|
162
209
|
// Headless cannot show a login UI. Close it, start headed Chrome and
|
|
@@ -181,13 +228,26 @@ async function runWithLogin(ctx, invocation, session, root, toolPath, args, outD
|
|
|
181
228
|
continue;
|
|
182
229
|
}
|
|
183
230
|
if (!json) {
|
|
231
|
+
saveErrorLog(outDir, result.stderr);
|
|
232
|
+
const raw = result.timedOut
|
|
233
|
+
? humanizeTimeoutMessage(result.error)
|
|
234
|
+
: (result.error || result.stderr || '脚本没有返回 JSON');
|
|
184
235
|
return {
|
|
185
236
|
ok: false,
|
|
186
|
-
|
|
237
|
+
timeout: Boolean(result.timedOut),
|
|
238
|
+
error: conciseError(raw),
|
|
187
239
|
};
|
|
188
240
|
}
|
|
189
241
|
if (!result.ok || json.ok !== true) {
|
|
190
|
-
|
|
242
|
+
saveErrorLog(outDir, result.stderr);
|
|
243
|
+
const raw = result.timedOut
|
|
244
|
+
? humanizeTimeoutMessage(result.error)
|
|
245
|
+
: (json.error || result.error || (label + '失败'));
|
|
246
|
+
return {
|
|
247
|
+
ok: false,
|
|
248
|
+
timeout: Boolean(result.timedOut),
|
|
249
|
+
error: conciseError(raw),
|
|
250
|
+
};
|
|
191
251
|
}
|
|
192
252
|
return { ok: true, json };
|
|
193
253
|
}
|
|
@@ -762,8 +822,17 @@ export function subagentTaskPrompt(job, root, materialTools) {
|
|
|
762
822
|
return lines.join('\n');
|
|
763
823
|
}
|
|
764
824
|
|
|
765
|
-
|
|
825
|
+
function fileHasContent(file) {
|
|
826
|
+
try {
|
|
827
|
+
return fs.statSync(file).size > 0;
|
|
828
|
+
} catch {
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
export async function runSubagentAnalysisJob({
|
|
766
834
|
subagents, provider, invocation, job, root, materialTools, signal,
|
|
835
|
+
timeoutMs = ANALYSIS_TIMEOUT_MS,
|
|
767
836
|
}) {
|
|
768
837
|
const prompt = subagentTaskPrompt(job, root, materialTools);
|
|
769
838
|
let activation;
|
|
@@ -787,24 +856,40 @@ async function runSubagentAnalysisJob({
|
|
|
787
856
|
result = await Promise.race([
|
|
788
857
|
activation.result,
|
|
789
858
|
new Promise((_, reject) => {
|
|
790
|
-
timer = setTimeout(() => reject(new Error('子 Agent 分析超时')),
|
|
859
|
+
timer = setTimeout(() => reject(new Error('子 Agent 分析超时')), timeoutMs);
|
|
791
860
|
if (timer && typeof timer.unref === 'function') timer.unref();
|
|
792
861
|
}),
|
|
793
862
|
]);
|
|
794
863
|
} catch (err) {
|
|
795
864
|
const message = err && err.message ? err.message : String(err);
|
|
865
|
+
const timeout = /超时|timeout/i.test(message);
|
|
866
|
+
// 超时前已经写出目标文件时,不要让已完成的素材陪葬。
|
|
867
|
+
// 先交给父进程的串行锁做 validate/import;校验不过再按失败处理。
|
|
868
|
+
if (!(signal && signal.aborted) && fileHasContent(job.target)) {
|
|
869
|
+
return {
|
|
870
|
+
ok: true,
|
|
871
|
+
needsFinalize: true,
|
|
872
|
+
partial: true,
|
|
873
|
+
timeout,
|
|
874
|
+
reason: timeout
|
|
875
|
+
? '子 Agent 分析超时,已写入目标文件,按已有内容继续校验'
|
|
876
|
+
: '子 Agent 异常结束,已写入目标文件,按已有内容继续校验',
|
|
877
|
+
};
|
|
878
|
+
}
|
|
796
879
|
return {
|
|
797
880
|
ok: false,
|
|
798
|
-
retryable: Boolean((signal && signal.aborted) ||
|
|
881
|
+
retryable: Boolean((signal && signal.aborted) || timeout
|
|
882
|
+
|| /abort|cancel|interrupt|terminated/i.test(message)),
|
|
883
|
+
timeout,
|
|
799
884
|
error: '子 Agent 执行失败:' + message,
|
|
800
885
|
};
|
|
801
886
|
} finally {
|
|
802
887
|
if (timer) clearTimeout(timer);
|
|
803
888
|
try { await activation.dispose(); } catch { /* best effort */ }
|
|
804
889
|
}
|
|
805
|
-
if (!
|
|
890
|
+
if (!fileHasContent(job.target)) {
|
|
806
891
|
const stop = result && result.stopReason ? String(result.stopReason) : '';
|
|
807
|
-
const retryable = /abort|cancel|interrupt|terminated
|
|
892
|
+
const retryable = /abort|cancel|interrupt|terminated|timeout|超时/i.test(stop)
|
|
808
893
|
|| Boolean(signal && signal.aborted);
|
|
809
894
|
return {
|
|
810
895
|
ok: false,
|
|
@@ -1068,9 +1153,28 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1068
1153
|
() => markJobSkippedLocked(job, reason, options),
|
|
1069
1154
|
);
|
|
1070
1155
|
|
|
1156
|
+
// 超时/中断不是内容级失败:保留 pending,下次运行继续。
|
|
1157
|
+
const markJobRetryableLocked = async (job, reason, { crawl = false } = {}) => {
|
|
1158
|
+
if (!job || !job.id) return;
|
|
1159
|
+
crawled[job.id] = true;
|
|
1160
|
+
if (job.jobKey) {
|
|
1161
|
+
await updateJob(jobStore.db, job.jobKey, {
|
|
1162
|
+
...(crawl ? { crawl_status: 'pending' } : {}),
|
|
1163
|
+
analysis_status: 'pending',
|
|
1164
|
+
import_status: 'pending',
|
|
1165
|
+
reason,
|
|
1166
|
+
error: '',
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
};
|
|
1170
|
+
const markJobRetryable = async (job, reason, options) => withStateLock(
|
|
1171
|
+
() => markJobRetryableLocked(job, reason, options),
|
|
1172
|
+
);
|
|
1173
|
+
|
|
1071
1174
|
queue = useSubagents ? createJobQueue() : null;
|
|
1072
1175
|
const queueStats = { queued: 0, finished: 0 };
|
|
1073
1176
|
const styleAccounts = new Map();
|
|
1177
|
+
const retryableJobs = [];
|
|
1074
1178
|
let styleResults = [];
|
|
1075
1179
|
let scannedAccounts = 0;
|
|
1076
1180
|
let foundNotes = 0;
|
|
@@ -1085,6 +1189,7 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1085
1189
|
let skippedLongVideos = 0;
|
|
1086
1190
|
let inserted = 0;
|
|
1087
1191
|
let skippedMaterials = 0;
|
|
1192
|
+
let salvaged = 0;
|
|
1088
1193
|
let aborted = false;
|
|
1089
1194
|
let writeActive = false;
|
|
1090
1195
|
|
|
@@ -1108,27 +1213,43 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1108
1213
|
writeActive = true;
|
|
1109
1214
|
taskList.activate(5);
|
|
1110
1215
|
}
|
|
1216
|
+
const wasPartial = Boolean(analyzed && analyzed.partial);
|
|
1111
1217
|
if (analyzed && analyzed.needsFinalize) {
|
|
1112
1218
|
analyzed = await finalizeMaterialFile({
|
|
1113
1219
|
root,
|
|
1114
1220
|
target: job.target,
|
|
1115
1221
|
materialTools,
|
|
1116
1222
|
});
|
|
1223
|
+
if (wasPartial && analyzed && analyzed.ok) analyzed.partial = true;
|
|
1117
1224
|
}
|
|
1118
1225
|
if (analyzed && (analyzed.aborted || analyzed.retryable)) {
|
|
1119
1226
|
if (job.jobKey) {
|
|
1120
1227
|
await updateJob(jobStore.db, job.jobKey, {
|
|
1121
1228
|
analysis_status: 'pending',
|
|
1122
1229
|
import_status: 'pending',
|
|
1123
|
-
reason: '上次分析被中断,等待重试',
|
|
1230
|
+
reason: analyzed.error || '上次分析被中断,等待重试',
|
|
1124
1231
|
error: '',
|
|
1125
1232
|
});
|
|
1126
1233
|
}
|
|
1127
|
-
if (jobSignal.aborted)
|
|
1234
|
+
if (jobSignal.aborted) {
|
|
1235
|
+
aborted = true;
|
|
1236
|
+
} else {
|
|
1237
|
+
retryableJobs.push({
|
|
1238
|
+
id: job.id,
|
|
1239
|
+
url: job.url,
|
|
1240
|
+
reason: analyzed.error || analyzed.reason || '等待重试',
|
|
1241
|
+
});
|
|
1242
|
+
crawled[job.id] = true;
|
|
1243
|
+
}
|
|
1244
|
+
queueStats.finished += 1;
|
|
1245
|
+
refreshProgress();
|
|
1128
1246
|
return;
|
|
1129
1247
|
}
|
|
1130
1248
|
if (!analyzed || !analyzed.ok) {
|
|
1131
|
-
const
|
|
1249
|
+
const detail = (analyzed && (analyzed.error || analyzed.detail)) || '素材没有通过校验';
|
|
1250
|
+
const reason = wasPartial
|
|
1251
|
+
? '子 Agent 分析超时,已有文件未通过校验:' + detail
|
|
1252
|
+
: detail;
|
|
1132
1253
|
failures.push({ id: job.id, url: job.url, reason });
|
|
1133
1254
|
await markJobFailedLocked(job, reason);
|
|
1134
1255
|
queueStats.finished += 1;
|
|
@@ -1150,13 +1271,14 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1150
1271
|
} else {
|
|
1151
1272
|
inserted += analyzed.inserted || 0;
|
|
1152
1273
|
skippedMaterials += analyzed.skipped || 0;
|
|
1274
|
+
if (wasPartial) salvaged += 1;
|
|
1153
1275
|
if (job.accountUrl) styleAccounts.set(job.accountUrl, (styleAccounts.get(job.accountUrl) || 0) + Math.max(1, analyzed.inserted || 0));
|
|
1154
1276
|
if (job.jobKey) {
|
|
1155
1277
|
await updateJob(jobStore.db, job.jobKey, {
|
|
1156
1278
|
analysis_status: 'analyzed',
|
|
1157
1279
|
import_status: 'imported',
|
|
1158
1280
|
material_count: analyzed.inserted || 0,
|
|
1159
|
-
reason: '',
|
|
1281
|
+
reason: wasPartial ? '超时后按已有素材导入' : '',
|
|
1160
1282
|
error: '',
|
|
1161
1283
|
imported_at: new Date(),
|
|
1162
1284
|
});
|
|
@@ -1228,20 +1350,25 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1228
1350
|
for (const account of accounts) {
|
|
1229
1351
|
if (abortRequested(invocation)) { aborted = true; break; }
|
|
1230
1352
|
const accountDir = path.join(runDir, accountSlug(account.url));
|
|
1353
|
+
const jobFor = (id, card, data) => ({
|
|
1354
|
+
id,
|
|
1355
|
+
jobKey: jobKeyFor(account.url, id),
|
|
1356
|
+
accountUrl: account.url,
|
|
1357
|
+
url: data.url || card.href,
|
|
1358
|
+
title: data.title || card.text || '',
|
|
1359
|
+
type: data.type,
|
|
1360
|
+
duration: data.duration,
|
|
1361
|
+
dir: data.dir,
|
|
1362
|
+
card,
|
|
1363
|
+
});
|
|
1231
1364
|
const markFailed = async (id, card, data, reason) => {
|
|
1232
1365
|
if (!id) return;
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
type: data.type,
|
|
1240
|
-
duration: data.duration,
|
|
1241
|
-
dir: data.dir,
|
|
1242
|
-
card,
|
|
1243
|
-
};
|
|
1244
|
-
await markJobFailed(job, reason, { crawl: true });
|
|
1366
|
+
await markJobFailed(jobFor(id, card, data), reason, { crawl: true });
|
|
1367
|
+
};
|
|
1368
|
+
const markRetryable = async (id, card, data, reason) => {
|
|
1369
|
+
if (!id) return;
|
|
1370
|
+
retryableJobs.push({ id, url: data.url || card.href, reason });
|
|
1371
|
+
await markJobRetryable(jobFor(id, card, data), reason, { crawl: true });
|
|
1245
1372
|
};
|
|
1246
1373
|
const scan = await runWithLogin(
|
|
1247
1374
|
ctx, invocation, session, root, tools.scripts.scan,
|
|
@@ -1383,10 +1510,15 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1383
1510
|
tools.nodePath,
|
|
1384
1511
|
browser,
|
|
1385
1512
|
tools,
|
|
1513
|
+
NOTE_SCRIPT_TIMEOUT_MS,
|
|
1386
1514
|
);
|
|
1387
1515
|
if (!noteResult.ok) {
|
|
1388
|
-
failures.push({ id: noteId, url: card.href, reason: noteResult.error });
|
|
1389
1516
|
if (noteResult.cancelled || authFailureText(noteResult.error)) { aborted = true; break outer; }
|
|
1517
|
+
if (noteResult.timeout) {
|
|
1518
|
+
await markRetryable(noteId, card, { type: 'note', dir: noteDir }, noteResult.error);
|
|
1519
|
+
continue;
|
|
1520
|
+
}
|
|
1521
|
+
failures.push({ id: noteId, url: card.href, reason: noteResult.error });
|
|
1390
1522
|
await markFailed(noteId, card, { type: 'note', dir: noteDir }, noteResult.error);
|
|
1391
1523
|
continue;
|
|
1392
1524
|
}
|
|
@@ -1500,8 +1632,12 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1500
1632
|
VIDEO_SCRIPT_TIMEOUT_MS,
|
|
1501
1633
|
);
|
|
1502
1634
|
if (!videoResult.ok) {
|
|
1503
|
-
failures.push({ id: videoId, url: card.href, reason: videoResult.error });
|
|
1504
1635
|
if (videoResult.cancelled || authFailureText(videoResult.error)) { aborted = true; break outer; }
|
|
1636
|
+
if (videoResult.timeout) {
|
|
1637
|
+
await markRetryable(videoId, card, { type: 'video', dir: videoDir }, videoResult.error);
|
|
1638
|
+
continue;
|
|
1639
|
+
}
|
|
1640
|
+
failures.push({ id: videoId, url: card.href, reason: videoResult.error });
|
|
1505
1641
|
await markFailed(videoId, card, { type: 'video', dir: videoDir }, videoResult.error);
|
|
1506
1642
|
continue;
|
|
1507
1643
|
}
|
|
@@ -1671,8 +1807,12 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1671
1807
|
tools,
|
|
1672
1808
|
);
|
|
1673
1809
|
if (!articleResult.ok) {
|
|
1674
|
-
failures.push({ id: articleId, url: card.href, reason: articleResult.error });
|
|
1675
1810
|
if (articleResult.cancelled || authFailureText(articleResult.error)) { aborted = true; break outer; }
|
|
1811
|
+
if (articleResult.timeout) {
|
|
1812
|
+
await markRetryable(articleId, card, { type: 'article', dir: articleDir }, articleResult.error);
|
|
1813
|
+
continue;
|
|
1814
|
+
}
|
|
1815
|
+
failures.push({ id: articleId, url: card.href, reason: articleResult.error });
|
|
1676
1816
|
await markFailed(articleId, card, { type: 'article', dir: articleDir }, articleResult.error);
|
|
1677
1817
|
continue;
|
|
1678
1818
|
}
|
|
@@ -1759,7 +1899,7 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1759
1899
|
}
|
|
1760
1900
|
|
|
1761
1901
|
taskList.advance(5);
|
|
1762
|
-
return notify(session, (aborted || failures.length) ? 'error' : 'success', summaryText({
|
|
1902
|
+
return notify(session, (aborted || failures.length || retryableJobs.length) ? 'error' : 'success', summaryText({
|
|
1763
1903
|
accounts: accounts.length,
|
|
1764
1904
|
scannedAccounts,
|
|
1765
1905
|
foundNotes,
|
|
@@ -1774,7 +1914,9 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1774
1914
|
skippedLongVideos,
|
|
1775
1915
|
inserted,
|
|
1776
1916
|
skippedMaterials,
|
|
1917
|
+
salvaged,
|
|
1777
1918
|
failures,
|
|
1919
|
+
retryableFailures: retryableJobs,
|
|
1778
1920
|
outputDir: runDir,
|
|
1779
1921
|
aborted,
|
|
1780
1922
|
mode: browser.mode,
|
|
@@ -179,7 +179,7 @@ export async function recoverInterruptedJobs(db) {
|
|
|
179
179
|
let recovered = 0;
|
|
180
180
|
for (const row of rows) {
|
|
181
181
|
const text = String(row.error || '') + ' ' + String(row.reason || '');
|
|
182
|
-
if (!/abort|cancel|interrupt|terminated
|
|
182
|
+
if (!/abort|cancel|interrupt|terminated|timeout|中断|超时|没有写入目标文件/i.test(text)) continue;
|
|
183
183
|
await updateJob(db, row.job_key, {
|
|
184
184
|
analysis_status: 'pending',
|
|
185
185
|
import_status: 'pending',
|
|
@@ -39,7 +39,7 @@ export function helpText() {
|
|
|
39
39
|
9. 视频作品先判断时长:超过 1 分钟直接跳过;不超过 1 分钟的先看前 5 秒,与网文创作无关就跳过,有关才继续分析关键帧。
|
|
40
40
|
10. 如果内容与网文创作无关,LLM 会写入 skip 标记,该作品记为已处理并跳过。
|
|
41
41
|
11. 素材按 material JSONL 格式写入数据库,source 固定为 other,kind 用中文作品主题。
|
|
42
|
-
12.
|
|
42
|
+
12. 已成功入库、确认无关或内容级失败的作品记录在素材库 douyin_job 表,后续跳过;超时/中断类待重试项会在下次运行继续;账号级失败仍会重试。
|
|
43
43
|
13. 登录态保存在 <工作区>/.fancy/douyin/chrome-profile/,并镜像到 login-state.json。
|
|
44
44
|
14. 首次需要登录时用有头 Chrome;登录态有效后后续运行自动使用无头 Chrome。
|
|
45
45
|
15. 每次运行结束会自动关闭 Chrome,释放资源。
|
|
@@ -250,7 +250,9 @@ export function summaryText({
|
|
|
250
250
|
skippedLongVideos = 0,
|
|
251
251
|
inserted,
|
|
252
252
|
skippedMaterials,
|
|
253
|
-
|
|
253
|
+
salvaged = 0,
|
|
254
|
+
failures = [],
|
|
255
|
+
retryableFailures = [],
|
|
254
256
|
outputDir,
|
|
255
257
|
aborted,
|
|
256
258
|
mode,
|
|
@@ -258,8 +260,11 @@ export function summaryText({
|
|
|
258
260
|
subagentWorkers = 0,
|
|
259
261
|
stylesUpdated = [],
|
|
260
262
|
}) {
|
|
263
|
+
const hasIssues = failures.length > 0 || retryableFailures.length > 0;
|
|
261
264
|
const lines = [
|
|
262
|
-
aborted
|
|
265
|
+
aborted
|
|
266
|
+
? '⚠️ 抖音采集已中断'
|
|
267
|
+
: (hasIssues ? '⚠️ 抖音采集部分完成' : '✅ 抖音采集完成'),
|
|
263
268
|
'账号:' + accounts + ' 个(本次扫描 ' + scannedAccounts + ' 个)',
|
|
264
269
|
'浏览器:' + (mode === 'headless' ? '无头' : '有头'),
|
|
265
270
|
'分析模式:' + (analysisMode === 'subagent' ? '子 Agent 并行(' + subagentWorkers + ' 个)' : '单 Agent 串行'),
|
|
@@ -273,14 +278,23 @@ export function summaryText({
|
|
|
273
278
|
'长视频跳过:' + skippedLongVideos + ' 个',
|
|
274
279
|
'新增素材:' + inserted + ' 条(重复跳过 ' + skippedMaterials + ' 条)',
|
|
275
280
|
];
|
|
281
|
+
if (salvaged > 0) lines.push('超时后完成:' + salvaged + ' 篇(按已写入素材导入)');
|
|
282
|
+
if (retryableFailures.length) {
|
|
283
|
+
lines.push('待重试:' + retryableFailures.length + ' 篇');
|
|
284
|
+
for (const item of retryableFailures.slice(0, 10)) {
|
|
285
|
+
lines.push(' - ' + (item.id || item.url || '未知') + ':' + item.reason);
|
|
286
|
+
}
|
|
287
|
+
if (retryableFailures.length > 10) lines.push(' - 其余 ' + (retryableFailures.length - 10) + ' 篇省略');
|
|
288
|
+
lines.push('这些作品是超时或中断,不是内容失败;下次运行会自动重试。');
|
|
289
|
+
}
|
|
276
290
|
if (failures.length) {
|
|
277
291
|
lines.push('失败:' + failures.length + ' 篇');
|
|
278
292
|
for (const item of failures.slice(0, 10)) {
|
|
279
293
|
lines.push(' - ' + (item.id || item.url || '未知') + ':' + item.reason);
|
|
280
294
|
}
|
|
281
295
|
if (failures.length > 10) lines.push(' - 其余 ' + (failures.length - 10) + ' 篇省略');
|
|
282
|
-
lines.push('
|
|
283
|
-
lines.push('
|
|
296
|
+
lines.push('失败项已记录,不会中断其他作品。');
|
|
297
|
+
lines.push('内容级失败后续跳过;超时/中断类待重试项会在下次运行继续。');
|
|
284
298
|
}
|
|
285
299
|
if (Array.isArray(stylesUpdated) && stylesUpdated.length) {
|
|
286
300
|
lines.push('风格更新:' + stylesUpdated.join('、'));
|