@cloud411716/fancy-webnovel 4.18.1 → 4.19.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 +2 -0
- package/package.json +1 -1
- package/plugins/fancy-douyin/index.js +29 -10
- package/plugins/fancy-douyin/jobs.js +23 -0
- package/plugins/fancy-douyin/scripts/crawl-note.cjs +3 -1
- package/plugins/fancy-douyin/scripts/crawl-video.cjs +5 -1
- package/plugins/fancy-douyin/scripts/video-frames.cjs +104 -9
package/docs/douyin-plugin.md
CHANGED
|
@@ -203,6 +203,8 @@ id / kind / subkind / name / tags / genres / note / source
|
|
|
203
203
|
拼成一张关键帧图交给 LLM;这样快速切换的画面和动态字幕/标语不会被封面漏掉。
|
|
204
204
|
- 独立视频作品会先尝试下载原片并用 ffmpeg 抽帧;下载失败时退化为播放器元素截图。
|
|
205
205
|
视频时长超过 1 分钟直接跳过;前 5 秒与网文创作无关也跳过。
|
|
206
|
+
- 场景切换点本身常是过渡虚影;插件会在切换后取多个候选帧,用 ffmpeg blurdetect 选择最清晰的一帧,避免把文字尚未完全出现的模糊帧交给 LLM。
|
|
207
|
+
- 子 Agent 或 DSH 在分析途中中断时,作品任务保持 pending;下次运行会复用已采集文件重新分析。旧版本留下的 aborted/failed 任务会在启动采集时自动恢复为 pending。
|
|
206
208
|
- 抖音 DOM/类名会变,`scan-account.cjs`、`crawl-note.cjs` 和 `crawl-video.cjs`
|
|
207
209
|
的选择器可能需要维护。
|
|
208
210
|
- 每次运行结束会自动关闭 Chrome;登录态保存在 profile 和 login-state.json 中,下次运行自动复用。
|
package/package.json
CHANGED
|
@@ -41,11 +41,12 @@ import { analysisPrompt, articlePrompt, capabilityPrompt, helpText, loginQuestio
|
|
|
41
41
|
import { createJobQueue, createSerialLock, getSubagentRuntime, subagentWorkerCount } from './subagents.js';
|
|
42
42
|
import {
|
|
43
43
|
countJobsByAccount, createJob, jobKeyFor, jobRelDir,
|
|
44
|
-
listJobsForAccount, migrateCrawledJobs, openJobStore, updateJob,
|
|
44
|
+
listJobsForAccount, migrateCrawledJobs, openJobStore, recoverInterruptedJobs, updateJob,
|
|
45
45
|
} from './jobs.js';
|
|
46
46
|
|
|
47
47
|
export const inject = ['commands', 'userQuestions'];
|
|
48
48
|
|
|
49
|
+
const FRAME_SELECTION_VERSION = 2;
|
|
49
50
|
const ANALYSIS_TIMEOUT_MS = 20 * 60 * 1000;
|
|
50
51
|
const ANALYSIS_IDLE_GRACE_MS = 60 * 1000;
|
|
51
52
|
const CAPABILITY_TIMEOUT_MS = 5 * 60 * 1000;
|
|
@@ -807,7 +808,8 @@ async function runSubagentAnalysisJob({
|
|
|
807
808
|
delivery: 'caller',
|
|
808
809
|
});
|
|
809
810
|
} catch (err) {
|
|
810
|
-
|
|
811
|
+
const message = '子 Agent 启动失败:' + (err && err.message ? err.message : String(err));
|
|
812
|
+
return { ok: false, retryable: Boolean(signal && signal.aborted), error: message };
|
|
811
813
|
}
|
|
812
814
|
|
|
813
815
|
let result;
|
|
@@ -821,14 +823,25 @@ async function runSubagentAnalysisJob({
|
|
|
821
823
|
}),
|
|
822
824
|
]);
|
|
823
825
|
} catch (err) {
|
|
824
|
-
|
|
826
|
+
const message = err && err.message ? err.message : String(err);
|
|
827
|
+
return {
|
|
828
|
+
ok: false,
|
|
829
|
+
retryable: Boolean((signal && signal.aborted) || /abort|cancel|interrupt|terminated/i.test(message)),
|
|
830
|
+
error: '子 Agent 执行失败:' + message,
|
|
831
|
+
};
|
|
825
832
|
} finally {
|
|
826
833
|
if (timer) clearTimeout(timer);
|
|
827
834
|
try { await activation.dispose(); } catch { /* best effort */ }
|
|
828
835
|
}
|
|
829
836
|
if (!fs.existsSync(job.target)) {
|
|
830
|
-
const stop = result && result.stopReason ?
|
|
831
|
-
|
|
837
|
+
const stop = result && result.stopReason ? String(result.stopReason) : '';
|
|
838
|
+
const retryable = /abort|cancel|interrupt|terminated/i.test(stop)
|
|
839
|
+
|| Boolean(signal && signal.aborted);
|
|
840
|
+
return {
|
|
841
|
+
ok: false,
|
|
842
|
+
retryable,
|
|
843
|
+
error: '子 Agent 没有写入目标文件' + (stop ? '(' + stop + ')' : ''),
|
|
844
|
+
};
|
|
832
845
|
}
|
|
833
846
|
// 文件已经写出,由父进程在串行锁内统一校验、导入和写 crawled.json。
|
|
834
847
|
return { ok: true, needsFinalize: true };
|
|
@@ -878,14 +891,14 @@ function readJsonArtifact(dir, name) {
|
|
|
878
891
|
|
|
879
892
|
function reusableNote(dir) {
|
|
880
893
|
const note = readJsonArtifact(dir, 'note.json');
|
|
881
|
-
if (!note || !Array.isArray(note.screenshots) || !note.screenshots.length) return null;
|
|
894
|
+
if (!note || note.frame_version !== FRAME_SELECTION_VERSION || !Array.isArray(note.screenshots) || !note.screenshots.length) return null;
|
|
882
895
|
if (!note.screenshots.every((shot) => shot && shot.file && fs.existsSync(shot.file))) return null;
|
|
883
896
|
return note;
|
|
884
897
|
}
|
|
885
898
|
|
|
886
899
|
function reusableVideo(dir) {
|
|
887
900
|
const video = readJsonArtifact(dir, 'video.json');
|
|
888
|
-
if (!video || !Array.isArray(video.frames) || !video.frames.length) return null;
|
|
901
|
+
if (!video || video.frame_version !== FRAME_SELECTION_VERSION || !Array.isArray(video.frames) || !video.frames.length) return null;
|
|
889
902
|
if (!video.frames.every((frame) => frame && frame.file && fs.existsSync(frame.file))) return null;
|
|
890
903
|
return video;
|
|
891
904
|
}
|
|
@@ -978,6 +991,7 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
978
991
|
let workerPromises = [];
|
|
979
992
|
try {
|
|
980
993
|
await migrateCrawledJobs(jobStore.db, root, accounts);
|
|
994
|
+
await recoverInterruptedJobs(jobStore.db);
|
|
981
995
|
} catch (err) {
|
|
982
996
|
await jobStore.close();
|
|
983
997
|
return notify(session, 'error', '❌ 初始化抖音任务状态表失败:' + (err && err.message ? err.message : String(err)));
|
|
@@ -1126,11 +1140,16 @@ async function runCrawl(ctx, invocation, session, taskList) {
|
|
|
1126
1140
|
materialTools,
|
|
1127
1141
|
});
|
|
1128
1142
|
}
|
|
1129
|
-
if (analyzed && analyzed.aborted) {
|
|
1130
|
-
aborted = true;
|
|
1143
|
+
if (analyzed && (analyzed.aborted || analyzed.retryable)) {
|
|
1131
1144
|
if (job.jobKey) {
|
|
1132
|
-
await updateJob(jobStore.db, job.jobKey, {
|
|
1145
|
+
await updateJob(jobStore.db, job.jobKey, {
|
|
1146
|
+
analysis_status: 'pending',
|
|
1147
|
+
import_status: 'pending',
|
|
1148
|
+
reason: '上次分析被中断,等待重试',
|
|
1149
|
+
error: '',
|
|
1150
|
+
});
|
|
1133
1151
|
}
|
|
1152
|
+
if (jobSignal.aborted) aborted = true;
|
|
1134
1153
|
return;
|
|
1135
1154
|
}
|
|
1136
1155
|
if (!analyzed || !analyzed.ok) {
|
|
@@ -168,6 +168,29 @@ export async function migrateCrawledJobs(db, root, accountList = null) {
|
|
|
168
168
|
return { migrated };
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Reset jobs whose only failure was an interrupted child (for example a DSH
|
|
173
|
+
* restart or an aborted subagent). A real analysis failure stays failed.
|
|
174
|
+
*/
|
|
175
|
+
export async function recoverInterruptedJobs(db) {
|
|
176
|
+
const rows = firstRows(await db.query(
|
|
177
|
+
"SELECT job_key, error, reason FROM douyin_job WHERE import_status = 'failed';",
|
|
178
|
+
));
|
|
179
|
+
let recovered = 0;
|
|
180
|
+
for (const row of rows) {
|
|
181
|
+
const text = String(row.error || '') + ' ' + String(row.reason || '');
|
|
182
|
+
if (!/abort|cancel|interrupt|terminated|中断|没有写入目标文件/i.test(text)) continue;
|
|
183
|
+
await updateJob(db, row.job_key, {
|
|
184
|
+
analysis_status: 'pending',
|
|
185
|
+
import_status: 'pending',
|
|
186
|
+
reason: '上次分析被中断,等待重试',
|
|
187
|
+
error: '',
|
|
188
|
+
});
|
|
189
|
+
recovered += 1;
|
|
190
|
+
}
|
|
191
|
+
return { recovered };
|
|
192
|
+
}
|
|
193
|
+
|
|
171
194
|
export function legacyCrawledPath(root) {
|
|
172
195
|
return douyinPaths(root).crawled;
|
|
173
196
|
}
|
|
@@ -16,6 +16,7 @@ const {
|
|
|
16
16
|
} = require('./lib.cjs');
|
|
17
17
|
const {
|
|
18
18
|
probeDuration, detectSceneTimes, fixedShortTimes, mergeFrameTimes, extractFramesAt,
|
|
19
|
+
extractSharpFramesAt,
|
|
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';
|
|
@@ -313,7 +314,7 @@ async function captureSlides(page, context, outDir) {
|
|
|
313
314
|
minGap: 0.25,
|
|
314
315
|
maxFrames: 10,
|
|
315
316
|
});
|
|
316
|
-
frames =
|
|
317
|
+
frames = extractSharpFramesAt(videoFile, outDir, 'slide_' + String(slideNo).padStart(2, '0') + '_frame', times, { duration });
|
|
317
318
|
} catch (err) {
|
|
318
319
|
log('[note] video slide ' + slideNo + ' download/frames failed: ' + (err && err.message ? err.message : String(err)));
|
|
319
320
|
}
|
|
@@ -488,6 +489,7 @@ async function main() {
|
|
|
488
489
|
description: meta.description,
|
|
489
490
|
body: meta.body,
|
|
490
491
|
slides: captured.slides,
|
|
492
|
+
frame_version: 2,
|
|
491
493
|
screenshots: captured.screenshots,
|
|
492
494
|
crawled_at: new Date().toISOString(),
|
|
493
495
|
dir: outDir,
|
|
@@ -20,6 +20,7 @@ const {
|
|
|
20
20
|
} = require('./lib.cjs');
|
|
21
21
|
const {
|
|
22
22
|
probeDuration, detectSceneTimes, fixedVideoTimes, mergeFrameTimes, extractFramesAt,
|
|
23
|
+
extractSharpFramesAt,
|
|
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,6 +229,7 @@ async function main() {
|
|
|
228
229
|
frames: [],
|
|
229
230
|
first5s: [],
|
|
230
231
|
video_file: '',
|
|
232
|
+
frame_version: 2,
|
|
231
233
|
crawled_at: new Date().toISOString(),
|
|
232
234
|
dir: outDir,
|
|
233
235
|
};
|
|
@@ -276,6 +278,7 @@ async function main() {
|
|
|
276
278
|
frames: [],
|
|
277
279
|
first5s: [],
|
|
278
280
|
video_file: videoFile,
|
|
281
|
+
frame_version: 2,
|
|
279
282
|
crawled_at: new Date().toISOString(),
|
|
280
283
|
dir: outDir,
|
|
281
284
|
};
|
|
@@ -301,7 +304,7 @@ async function main() {
|
|
|
301
304
|
try {
|
|
302
305
|
sceneTimes = detectSceneTimes(videoFile, { threshold: 0.15, maxFrames: 16 });
|
|
303
306
|
times = mergeFrameTimes(fixedTimes, sceneTimes, { minGap: 0.4, maxFrames: 24 });
|
|
304
|
-
frames =
|
|
307
|
+
frames = extractSharpFramesAt(videoFile, outDir, 'video_frame', times, { duration });
|
|
305
308
|
} catch (err) {
|
|
306
309
|
log('[video] ffmpeg frame extraction failed: ' + (err && err.message ? err.message : String(err)));
|
|
307
310
|
}
|
|
@@ -341,6 +344,7 @@ async function main() {
|
|
|
341
344
|
fixed_times: fixedTimes,
|
|
342
345
|
video_file: videoFile,
|
|
343
346
|
download_error: downloadError,
|
|
347
|
+
frame_version: 2,
|
|
344
348
|
crawled_at: new Date().toISOString(),
|
|
345
349
|
dir: outDir,
|
|
346
350
|
};
|
|
@@ -96,6 +96,18 @@ function mergeFrameTimes(fixed, scene, { minGap = 0.25, maxFrames = 12 } = {}) {
|
|
|
96
96
|
return [...new Set(picked)].sort((a, b) => a - b);
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
function extractFrameAt(file, target, time, timeout = 60000) {
|
|
100
|
+
const result = spawnSync('ffmpeg', [
|
|
101
|
+
'-y', '-hide_banner', '-loglevel', 'error',
|
|
102
|
+
'-ss', String(time),
|
|
103
|
+
'-i', file,
|
|
104
|
+
'-frames:v', '1',
|
|
105
|
+
'-q:v', '2',
|
|
106
|
+
target,
|
|
107
|
+
], { encoding: 'utf8', timeout });
|
|
108
|
+
return result.status === 0 && fs.existsSync(target);
|
|
109
|
+
}
|
|
110
|
+
|
|
99
111
|
function extractFramesAt(file, outDir, prefix, times, { timeout = 60000 } = {}) {
|
|
100
112
|
fs.mkdirSync(outDir, { recursive: true });
|
|
101
113
|
for (const name of fs.readdirSync(outDir)) {
|
|
@@ -108,21 +120,102 @@ function extractFramesAt(file, outDir, prefix, times, { timeout = 60000 } = {})
|
|
|
108
120
|
const time = Number(times[index]);
|
|
109
121
|
if (!Number.isFinite(time) || time < 0) continue;
|
|
110
122
|
const target = path.join(outDir, prefix + '_' + String(frames.length + 1).padStart(3, '0') + '.jpg');
|
|
111
|
-
|
|
112
|
-
'-y', '-hide_banner', '-loglevel', 'error',
|
|
113
|
-
'-ss', String(time),
|
|
114
|
-
'-i', file,
|
|
115
|
-
'-frames:v', '1',
|
|
116
|
-
'-q:v', '2',
|
|
117
|
-
target,
|
|
118
|
-
], { encoding: 'utf8', timeout });
|
|
119
|
-
if (result.status === 0 && fs.existsSync(target)) {
|
|
123
|
+
if (extractFrameAt(file, target, time, timeout)) {
|
|
120
124
|
frames.push({ index: frames.length + 1, time: Math.round(time * 10) / 10, file: target });
|
|
121
125
|
}
|
|
122
126
|
}
|
|
123
127
|
return frames;
|
|
124
128
|
}
|
|
125
129
|
|
|
130
|
+
/** Lower is sharper. Uses ffmpeg's blurdetect filter; null when unavailable. */
|
|
131
|
+
function frameBlurScore(file) {
|
|
132
|
+
const result = spawnSync('ffmpeg', [
|
|
133
|
+
'-hide_banner', '-i', file,
|
|
134
|
+
'-vf', 'blurdetect,metadata=print',
|
|
135
|
+
'-an', '-f', 'null', '-',
|
|
136
|
+
], { encoding: 'utf8', timeout: 30000 });
|
|
137
|
+
if (result.status !== 0) return null;
|
|
138
|
+
const text = String(result.stderr || '');
|
|
139
|
+
const values = [...text.matchAll(/lavfi\.blur=([0-9]+(?:\.[0-9]+)?)/g)]
|
|
140
|
+
.map((match) => Number(match[1]))
|
|
141
|
+
.filter((value) => Number.isFinite(value));
|
|
142
|
+
if (values.length) return values[0];
|
|
143
|
+
const mean = text.match(/blur mean:\s*([0-9]+(?:\.[0-9]+)?)/);
|
|
144
|
+
return mean ? Number(mean[1]) : null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Extract one representative frame per source time, choosing the sharpest
|
|
149
|
+
* post-transition candidate. Scene cuts happen before animated text has fully
|
|
150
|
+
* appeared, so the cut timestamp itself is often a blurry transition frame.
|
|
151
|
+
*/
|
|
152
|
+
function extractSharpFramesAt(file, outDir, prefix, times, {
|
|
153
|
+
duration = null,
|
|
154
|
+
timeout = 60000,
|
|
155
|
+
offsets = [0.2, 0.55, 0.95],
|
|
156
|
+
maxFrames = 24,
|
|
157
|
+
} = {}) {
|
|
158
|
+
const baseTimes = [...new Set((Array.isArray(times) ? times : [])
|
|
159
|
+
.map((value) => Number(value))
|
|
160
|
+
.filter((value) => Number.isFinite(value) && value >= 0))]
|
|
161
|
+
.sort((a, b) => a - b)
|
|
162
|
+
.slice(0, maxFrames);
|
|
163
|
+
if (!baseTimes.length) return [];
|
|
164
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
165
|
+
const total = Number.isFinite(Number(duration)) && Number(duration) > 0 ? Number(duration) : null;
|
|
166
|
+
const tempDir = fs.mkdtempSync(path.join(outDir, '.sharp-frames-'));
|
|
167
|
+
const selected = [];
|
|
168
|
+
try {
|
|
169
|
+
for (let index = 0; index < baseTimes.length; index += 1) {
|
|
170
|
+
const base = baseTimes[index];
|
|
171
|
+
const next = baseTimes[index + 1];
|
|
172
|
+
const limit = Math.min(
|
|
173
|
+
total === null ? Number.POSITIVE_INFINITY : total - 0.05,
|
|
174
|
+
Number.isFinite(next) ? next - 0.12 : Number.POSITIVE_INFINITY,
|
|
175
|
+
);
|
|
176
|
+
const candidates = [];
|
|
177
|
+
for (const offset of offsets) {
|
|
178
|
+
const at = Math.round((base + offset) * 100) / 100;
|
|
179
|
+
if (at > limit) continue;
|
|
180
|
+
const candidateFile = path.join(tempDir, 'candidate_' + String(index).padStart(3, '0')
|
|
181
|
+
+ '_' + String(candidates.length).padStart(2, '0') + '.jpg');
|
|
182
|
+
if (!extractFrameAt(file, candidateFile, at, timeout)) continue;
|
|
183
|
+
let size = 0;
|
|
184
|
+
try { size = fs.statSync(candidateFile).size; } catch { /* ignore */ }
|
|
185
|
+
candidates.push({ time: at, file: candidateFile, size, blur: frameBlurScore(candidateFile) });
|
|
186
|
+
}
|
|
187
|
+
if (!candidates.length) {
|
|
188
|
+
// Near the end of the clip there may be no room for post-roll.
|
|
189
|
+
const fallbackFile = path.join(tempDir, 'candidate_' + String(index).padStart(3, '0') + '_base.jpg');
|
|
190
|
+
if (extractFrameAt(file, fallbackFile, base, timeout)) {
|
|
191
|
+
candidates.push({ time: base, file: fallbackFile, size: 0, blur: frameBlurScore(fallbackFile) });
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
if (!candidates.length) continue;
|
|
195
|
+
const scored = candidates.filter((item) => Number.isFinite(item.blur));
|
|
196
|
+
if (scored.length) {
|
|
197
|
+
const best = Math.min(...scored.map((item) => item.blur));
|
|
198
|
+
const acceptable = scored.filter((item) => item.blur <= best * 1.15 + 0.5);
|
|
199
|
+
// Prefer the latest acceptable frame: animated text has had time to
|
|
200
|
+
// finish, while blurdetect still rejects transition ghosting.
|
|
201
|
+
selected.push(acceptable[acceptable.length - 1]);
|
|
202
|
+
} else {
|
|
203
|
+
// No blurdetect support: use the largest JPEG as a sharpness proxy.
|
|
204
|
+
selected.push(candidates.slice().sort((a, b) => b.size - a.size)[0]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
} finally {
|
|
208
|
+
try { fs.rmSync(tempDir, { recursive: true, force: true }); } catch { /* ignore */ }
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const distinct = [];
|
|
212
|
+
for (const item of selected) {
|
|
213
|
+
if (distinct.some((other) => Math.abs(other.time - item.time) < 0.3)) continue;
|
|
214
|
+
distinct.push(item);
|
|
215
|
+
}
|
|
216
|
+
return extractFramesAt(file, outDir, prefix, distinct.map((item) => item.time), { timeout });
|
|
217
|
+
}
|
|
218
|
+
|
|
126
219
|
module.exports = {
|
|
127
220
|
probeDuration,
|
|
128
221
|
detectSceneTimes,
|
|
@@ -130,4 +223,6 @@ module.exports = {
|
|
|
130
223
|
fixedVideoTimes,
|
|
131
224
|
mergeFrameTimes,
|
|
132
225
|
extractFramesAt,
|
|
226
|
+
extractSharpFramesAt,
|
|
227
|
+
frameBlurScore,
|
|
133
228
|
};
|