@cloud411716/fancy-webnovel 4.20.0 → 4.22.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 +4 -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/scripts/crawl-note.cjs +72 -21
- 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
|
|
|
@@ -201,6 +201,7 @@ id / kind / subkind / name / tags / genres / note / source
|
|
|
201
201
|
滚动、懒加载或页面动画截到残缺图片。
|
|
202
202
|
- 图文作品的轮播可以混合图片页和视频页。视频页会下载该页短视频,15 秒以内每 0.2 秒采样、15–60 秒每 0.5 秒采样,
|
|
203
203
|
再按稳定画面段选帧并拼成一张关键帧图交给 LLM;这样快速切换的画面和动态字幕/标语不会被封面漏掉。
|
|
204
|
+
- 图文轮播必须以页面计数器 `当前页/总页数` 为准:页面刚打开时 DOM 里可能只挂载 1–2 个 `.dySwiperSlide`,不能当作总页数。插件会逐页推进并等待当前页内容切换完成,确保 `note.json` 记录所有页。
|
|
204
205
|
- 独立视频作品会先尝试下载原片并用 ffmpeg 抽帧;下载失败时退化为播放器元素截图。
|
|
205
206
|
视频时长超过 1 分钟直接跳过;前 5 秒与网文创作无关也跳过。
|
|
206
207
|
- 场景切换点本身常是过渡虚影。插件会在密集采样后用 ffmpeg blurdetect 给每帧打分,在每个稳定画面段的清晰中段选一帧,避免把文字尚未完全出现的模糊帧交给 LLM。
|
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';
|
|
@@ -63,7 +63,9 @@ async function activeSlideInfo(page) {
|
|
|
63
63
|
if (String(videoSrc).startsWith('//')) videoSrc = 'https:' + videoSrc;
|
|
64
64
|
duration = Number.isFinite(video.duration) && video.duration > 0 ? video.duration : null;
|
|
65
65
|
}
|
|
66
|
-
const img = el.querySelector('img[src*="tplv-dy-aweme-images"], img[src*="aweme-images"]')
|
|
66
|
+
const img = el.querySelector('img[src*="tplv-dy-aweme-images"], img[src*="aweme-images"]');
|
|
67
|
+
const anyImg = el.querySelector('img');
|
|
68
|
+
const fallbackImg = anyImg && anyImg.src && !/douyinDefault/i.test(anyImg.src) ? anyImg.src : '';
|
|
67
69
|
return {
|
|
68
70
|
domIndex: active.index,
|
|
69
71
|
x: Math.round(active.rect.x),
|
|
@@ -73,11 +75,33 @@ async function activeSlideInfo(page) {
|
|
|
73
75
|
hasVideo: Boolean(videoSrc && !videoSrc.startsWith('blob:')),
|
|
74
76
|
videoSrc,
|
|
75
77
|
duration,
|
|
76
|
-
|
|
78
|
+
// Never fall back to Douyin's placeholder image: if the real image has
|
|
79
|
+
// not loaded yet, the caller will wait or take an element screenshot.
|
|
80
|
+
imageSrc: img && img.src ? img.src : fallbackImg,
|
|
77
81
|
};
|
|
78
82
|
});
|
|
79
83
|
}
|
|
80
84
|
|
|
85
|
+
async function readSlidePosition(page) {
|
|
86
|
+
return await page.evaluate(() => {
|
|
87
|
+
const el = document.querySelector('.YoycnaPk');
|
|
88
|
+
if (el) {
|
|
89
|
+
const parts = [...el.querySelectorAll('span')].map((span) => String(span.textContent || '').trim());
|
|
90
|
+
const current = Number(parts[0]);
|
|
91
|
+
const total = Number(parts[parts.length - 1]);
|
|
92
|
+
if (Number.isFinite(current) && Number.isFinite(total) && total > 0) return { current, total };
|
|
93
|
+
}
|
|
94
|
+
const matches = [...String(document.body && document.body.innerText || '')
|
|
95
|
+
.matchAll(/(?:^|\s)(\d{1,3})\s*\/\s*(\d{1,3})(?=\s|$)/g)];
|
|
96
|
+
for (let index = matches.length - 1; index >= 0; index -= 1) {
|
|
97
|
+
const current = Number(matches[index][1]);
|
|
98
|
+
const total = Number(matches[index][2]);
|
|
99
|
+
if (current > 0 && total >= current && total <= 100) return { current, total };
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
81
105
|
async function freezeSlideVideos(page) {
|
|
82
106
|
await page.evaluate(() => {
|
|
83
107
|
const pause = () => {
|
|
@@ -138,12 +162,22 @@ async function clickNextSlide(page) {
|
|
|
138
162
|
return false;
|
|
139
163
|
}
|
|
140
164
|
|
|
141
|
-
|
|
165
|
+
function sameSlide(a, b) {
|
|
166
|
+
if (!a || !b) return false;
|
|
167
|
+
if (a.domIndex !== b.domIndex) return false;
|
|
168
|
+
if (a.videoSrc && b.videoSrc && a.videoSrc !== b.videoSrc) return false;
|
|
169
|
+
if (a.imageSrc && b.imageSrc && a.imageSrc !== b.imageSrc) return false;
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async function waitActiveSlide(page, previous = null) {
|
|
142
174
|
let info = null;
|
|
143
|
-
for (let attempt = 0; attempt <
|
|
175
|
+
for (let attempt = 0; attempt < 12; attempt += 1) {
|
|
144
176
|
info = await activeSlideInfo(page);
|
|
145
|
-
|
|
146
|
-
|
|
177
|
+
const changed = previous ? !sameSlide(info, previous) : true;
|
|
178
|
+
if (info && changed && info.hasVideo && info.duration) return info;
|
|
179
|
+
if (info && changed && !info.hasVideo && info.imageSrc) return info;
|
|
180
|
+
await page.waitForTimeout(300);
|
|
147
181
|
}
|
|
148
182
|
return info;
|
|
149
183
|
}
|
|
@@ -281,21 +315,25 @@ async function captureSlides(page, context, outDir) {
|
|
|
281
315
|
try {
|
|
282
316
|
converter = await context.newPage();
|
|
283
317
|
await freezeSlideVideos(page);
|
|
284
|
-
|
|
318
|
+
const initialSlides = await page.evaluate(() => document.querySelectorAll('.dySwiperSlide').length);
|
|
285
319
|
if (initialSlides === 0) {
|
|
286
320
|
return await captureFallbackImages(page, context, converter, outDir);
|
|
287
321
|
}
|
|
288
322
|
|
|
289
323
|
let current = await waitActiveSlide(page);
|
|
324
|
+
const initialPosition = await readSlidePosition(page);
|
|
325
|
+
const expectedTotal = initialPosition && initialPosition.total > 0 ? initialPosition.total : null;
|
|
290
326
|
let guard = 0;
|
|
291
|
-
log('[note] carousel initial slides: ' + initialSlides
|
|
292
|
-
|
|
327
|
+
log('[note] carousel initial slides: ' + initialSlides
|
|
328
|
+
+ ', page: ' + (initialPosition ? initialPosition.current + '/' + initialPosition.total : 'unknown')
|
|
329
|
+
+ ', first domIndex: ' + (current && current.domIndex));
|
|
330
|
+
while (current && guard < 60) {
|
|
293
331
|
guard += 1;
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
log('[note] processing
|
|
297
|
-
if (!seen.has(
|
|
298
|
-
seen.add(
|
|
332
|
+
const position = await readSlidePosition(page);
|
|
333
|
+
const pageNo = position && position.current > 0 ? position.current : current.domIndex + 1;
|
|
334
|
+
log('[note] processing page ' + pageNo + ' (slide ' + (slides.length + 1) + ')');
|
|
335
|
+
if (!seen.has(pageNo)) {
|
|
336
|
+
seen.add(pageNo);
|
|
299
337
|
const slideNo = slides.length + 1;
|
|
300
338
|
if (current.hasVideo) {
|
|
301
339
|
const videoFile = path.join(outDir, 'slide_' + String(slideNo).padStart(2, '0') + '.mp4');
|
|
@@ -399,17 +437,24 @@ async function captureSlides(page, context, outDir) {
|
|
|
399
437
|
}
|
|
400
438
|
|
|
401
439
|
// 一次只前进一格。优先点轮播右侧箭头;视频播放时按钮偶尔会被
|
|
402
|
-
//
|
|
403
|
-
|
|
440
|
+
// 播放器层吃掉,先暂停再重试,仍失败才退回拖拽。页面计数器比
|
|
441
|
+
// DOM 节点数可靠:note.json 必须覆盖计数器的全部页数。
|
|
442
|
+
if (expectedTotal && seen.size >= expectedTotal) break;
|
|
443
|
+
const beforePage = pageNo;
|
|
404
444
|
let next = null;
|
|
405
445
|
for (let press = 0; press < 3 && !next; press += 1) {
|
|
406
446
|
const clicked = await clickNextSlide(page);
|
|
407
447
|
log('[note] next click ' + press + ': ' + clicked);
|
|
408
448
|
if (!clicked) await advanceSlide(page, current);
|
|
409
449
|
for (let wait = 0; wait < 8; wait += 1) {
|
|
410
|
-
await page.waitForTimeout(
|
|
450
|
+
await page.waitForTimeout(400);
|
|
411
451
|
const info = await activeSlideInfo(page);
|
|
412
|
-
|
|
452
|
+
const after = await readSlidePosition(page);
|
|
453
|
+
if (after && after.current !== beforePage) {
|
|
454
|
+
next = info || current;
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
if (!after && info && info.domIndex !== current.domIndex) {
|
|
413
458
|
next = info;
|
|
414
459
|
break;
|
|
415
460
|
}
|
|
@@ -419,9 +464,15 @@ async function captureSlides(page, context, outDir) {
|
|
|
419
464
|
await page.waitForTimeout(500);
|
|
420
465
|
}
|
|
421
466
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
467
|
+
const afterPosition = await readSlidePosition(page);
|
|
468
|
+
log('[note] next page: ' + (afterPosition ? afterPosition.current + '/' + afterPosition.total : 'unknown')
|
|
469
|
+
+ ', seen: ' + [...seen].join(','));
|
|
470
|
+
if (!next) break;
|
|
471
|
+
if (afterPosition && beforePage && afterPosition.current <= beforePage) break;
|
|
472
|
+
current = await waitActiveSlide(page, current);
|
|
473
|
+
}
|
|
474
|
+
if (expectedTotal && seen.size < expectedTotal) {
|
|
475
|
+
log('[note] WARNING incomplete carousel: captured ' + seen.size + '/' + expectedTotal + ' pages');
|
|
425
476
|
}
|
|
426
477
|
} finally {
|
|
427
478
|
await unfreezeSlideVideos(page);
|
|
@@ -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
|
}
|