@cloud411716/fancy-webnovel 4.9.0 → 4.11.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 +47 -3
- package/docs/material-library/README.md +2 -0
- package/docs/material-library/schema.surql +48 -1
- package/docs/workspace-mcp.md +2 -2
- package/lib/material-db.js +7 -2
- package/package.json +1 -1
- package/plugins/fancy-bootstrap/index.js +1 -1
- package/plugins/fancy-db/index.js +1 -1
- package/plugins/fancy-douyin/index.js +824 -276
- package/plugins/fancy-douyin/jobs.js +184 -0
- package/plugins/fancy-douyin/scripts/scan-account.cjs +19 -0
- package/plugins/fancy-douyin/state.js +54 -15
- package/plugins/fancy-douyin/subagents.js +106 -0
- package/plugins/fancy-douyin/templates.js +9 -2
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Douyin job state stored in the material database.
|
|
3
|
+
*
|
|
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. The
|
|
6
|
+
* workspace `crawled.json` remains only as a legacy migration source/backup.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import fs from 'fs';
|
|
10
|
+
import path from 'path';
|
|
11
|
+
import { RecordId } from 'surrealdb';
|
|
12
|
+
|
|
13
|
+
import { connectMaterial } from '#material-db';
|
|
14
|
+
import { accountSlug, douyinPaths, readAccounts, readCrawled } from './state.js';
|
|
15
|
+
|
|
16
|
+
export const JOB_TABLE = 'douyin_job';
|
|
17
|
+
export const META_TABLE = 'douyin_meta';
|
|
18
|
+
|
|
19
|
+
export function jobKeyFor(accountUrl, workId) {
|
|
20
|
+
return accountSlug(accountUrl) + '_' + workId;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function jobRelDir(accountUrl, workId) {
|
|
24
|
+
return path.join(accountSlug(accountUrl), String(workId));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export async function openJobStore(root) {
|
|
28
|
+
const { db } = await connectMaterial(root);
|
|
29
|
+
return {
|
|
30
|
+
db,
|
|
31
|
+
async close() {
|
|
32
|
+
try { await db.close(); } catch { /* ignore */ }
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function firstRows(result) {
|
|
38
|
+
return Array.isArray(result) && Array.isArray(result[0]) ? result[0] : [];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function getJob(db, key) {
|
|
42
|
+
const rows = firstRows(await db.query('SELECT * FROM douyin_job WHERE job_key = $key LIMIT 1;', { key }));
|
|
43
|
+
return rows[0] || null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export async function listJobsForAccount(db, accountUrl) {
|
|
47
|
+
const rows = firstRows(await db.query(
|
|
48
|
+
'SELECT * FROM douyin_job WHERE account_url = $account_url ORDER BY work_id;',
|
|
49
|
+
{ account_url: accountUrl },
|
|
50
|
+
));
|
|
51
|
+
return rows;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function countJobsByAccount(db) {
|
|
55
|
+
const rows = firstRows(await db.query(
|
|
56
|
+
"SELECT account_url, count() AS n FROM douyin_job WHERE import_status IN ['imported', 'skipped', 'failed'] GROUP BY account_url;",
|
|
57
|
+
));
|
|
58
|
+
const counts = new Map();
|
|
59
|
+
for (const row of rows) {
|
|
60
|
+
if (!row || !row.account_url) continue;
|
|
61
|
+
counts.set(String(row.account_url), Number(row.n) || 0);
|
|
62
|
+
}
|
|
63
|
+
return counts;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export async function createJob(db, data) {
|
|
67
|
+
const key = data.job_key || jobKeyFor(data.account_url, data.work_id);
|
|
68
|
+
const existing = await getJob(db, key);
|
|
69
|
+
if (existing) return existing;
|
|
70
|
+
const record = {
|
|
71
|
+
job_key: key,
|
|
72
|
+
account_url: data.account_url,
|
|
73
|
+
account_name: data.account_name || '',
|
|
74
|
+
douyin_id: data.douyin_id || '',
|
|
75
|
+
account_sec_uid: data.account_sec_uid || '',
|
|
76
|
+
work_id: String(data.work_id),
|
|
77
|
+
work_type: data.work_type,
|
|
78
|
+
work_url: data.work_url,
|
|
79
|
+
title: data.title || '',
|
|
80
|
+
crawl_status: data.crawl_status || 'pending',
|
|
81
|
+
analysis_status: data.analysis_status || 'pending',
|
|
82
|
+
import_status: data.import_status || 'pending',
|
|
83
|
+
dir_rel: data.dir_rel || '',
|
|
84
|
+
material_count: Number(data.material_count) || 0,
|
|
85
|
+
attempts: Number(data.attempts) || 0,
|
|
86
|
+
reason: data.reason || '',
|
|
87
|
+
error: data.error || '',
|
|
88
|
+
created_at: new Date(),
|
|
89
|
+
updated_at: new Date(),
|
|
90
|
+
...(data.imported_at ? { imported_at: new Date(data.imported_at) } : {}),
|
|
91
|
+
};
|
|
92
|
+
await db.upsert(new RecordId(JOB_TABLE, key)).content(record);
|
|
93
|
+
return record;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function updateJob(db, key, patch) {
|
|
97
|
+
await db.upsert(new RecordId(JOB_TABLE, key)).merge({
|
|
98
|
+
...patch,
|
|
99
|
+
updated_at: new Date(),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async function getMeta(db, key) {
|
|
104
|
+
const rows = firstRows(await db.query('SELECT meta_value FROM douyin_meta WHERE meta_key = $key LIMIT 1;', { key }));
|
|
105
|
+
return rows[0] ? String(rows[0].meta_value || '') : '';
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function setMeta(db, key, value) {
|
|
109
|
+
await db.upsert(new RecordId(META_TABLE, key)).content({
|
|
110
|
+
meta_key: key,
|
|
111
|
+
meta_value: String(value),
|
|
112
|
+
updated_at: new Date(),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function inferWorkType(record, workId) {
|
|
117
|
+
if (record.type === 'note' || record.type === 'video' || record.type === 'article') return record.type;
|
|
118
|
+
const url = String(record.url || '');
|
|
119
|
+
if (url.includes('/article/')) return 'article';
|
|
120
|
+
if (url.includes('/video/')) return 'video';
|
|
121
|
+
return 'note';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* One-time migration from the legacy workspace crawled.json into douyin_job.
|
|
126
|
+
* Existing database rows win; the marker prevents re-running the migration.
|
|
127
|
+
*/
|
|
128
|
+
export async function migrateCrawledJobs(db, root) {
|
|
129
|
+
if (await getMeta(db, 'crawled_migrated') === '1') return { migrated: 0 };
|
|
130
|
+
const crawled = readCrawled(root);
|
|
131
|
+
const accounts = new Map(readAccounts(root).map((item) => [item.url, item]));
|
|
132
|
+
let migrated = 0;
|
|
133
|
+
for (const [workId, record] of Object.entries(crawled)) {
|
|
134
|
+
if (!record || typeof record !== 'object' || !record.account_url) continue;
|
|
135
|
+
const key = jobKeyFor(record.account_url, workId);
|
|
136
|
+
if (await getJob(db, key)) continue;
|
|
137
|
+
const account = accounts.get(record.account_url) || {};
|
|
138
|
+
const failed = record.failed === true;
|
|
139
|
+
const skipped = record.skip === true;
|
|
140
|
+
const inserted = Number(record.inserted) || 0;
|
|
141
|
+
const parsedImportedAt = record.crawled_at ? new Date(record.crawled_at) : new Date();
|
|
142
|
+
const importedAt = Number.isNaN(parsedImportedAt.getTime()) ? new Date() : parsedImportedAt;
|
|
143
|
+
await createJob(db, {
|
|
144
|
+
job_key: key,
|
|
145
|
+
account_url: record.account_url,
|
|
146
|
+
account_name: account.name || '',
|
|
147
|
+
douyin_id: account.douyin_id || '',
|
|
148
|
+
account_sec_uid: account.sec_uid || '',
|
|
149
|
+
work_id: String(workId),
|
|
150
|
+
work_type: inferWorkType(record, workId),
|
|
151
|
+
work_url: record.url || '',
|
|
152
|
+
title: record.title || '',
|
|
153
|
+
crawl_status: failed ? 'failed' : 'crawled',
|
|
154
|
+
analysis_status: failed ? 'failed' : 'analyzed',
|
|
155
|
+
import_status: failed ? 'failed' : (skipped ? 'skipped' : 'imported'),
|
|
156
|
+
dir_rel: '',
|
|
157
|
+
material_count: inserted,
|
|
158
|
+
reason: record.reason || '',
|
|
159
|
+
error: failed ? (record.reason || '') : '',
|
|
160
|
+
imported_at: importedAt,
|
|
161
|
+
});
|
|
162
|
+
migrated += 1;
|
|
163
|
+
}
|
|
164
|
+
await setMeta(db, 'crawled_migrated', '1');
|
|
165
|
+
return { migrated };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function legacyCrawledPath(root) {
|
|
169
|
+
return douyinPaths(root).crawled;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function jobArtifactsExist(root, record) {
|
|
173
|
+
if (!record || !record.dir_rel) return false;
|
|
174
|
+
const dir = path.join(douyinPaths(root).base, 'jobs', record.dir_rel);
|
|
175
|
+
try {
|
|
176
|
+
if (!fs.statSync(dir).isDirectory()) return false;
|
|
177
|
+
return fs.existsSync(path.join(dir, 'materials.jsonl'))
|
|
178
|
+
|| fs.existsSync(path.join(dir, 'note.json'))
|
|
179
|
+
|| fs.existsSync(path.join(dir, 'video.json'))
|
|
180
|
+
|| fs.existsSync(path.join(dir, 'article.json'));
|
|
181
|
+
} catch {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
@@ -20,6 +20,23 @@ function normalize(url) {
|
|
|
20
20
|
return String(url);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
async function readProfile(page) {
|
|
24
|
+
return await page.evaluate(() => {
|
|
25
|
+
const title = String(document.title || '')
|
|
26
|
+
.replace(/\s*-\s*抖音\s*$/, '')
|
|
27
|
+
.replace(/的抖音.*$/, '')
|
|
28
|
+
.trim();
|
|
29
|
+
const body = document.body && document.body.innerText ? document.body.innerText : '';
|
|
30
|
+
const idMatch = body.match(/抖音号[::]\s*([A-Za-z0-9_.-]+)/);
|
|
31
|
+
const secMatch = location.pathname.match(/\/user\/([^/?#]+)/);
|
|
32
|
+
return {
|
|
33
|
+
name: title || '',
|
|
34
|
+
douyin_id: idMatch ? idMatch[1] : '',
|
|
35
|
+
sec_uid: secMatch ? secMatch[1] : '',
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
23
40
|
async function collectCards(page) {
|
|
24
41
|
const cards = new Map();
|
|
25
42
|
let stable = 0;
|
|
@@ -162,11 +179,13 @@ async function main() {
|
|
|
162
179
|
const notes = cards.filter((card) => card.kind === 'note');
|
|
163
180
|
const videos = cards.filter((card) => card.kind === 'video');
|
|
164
181
|
const articles = cards.filter((card) => card.kind === 'article');
|
|
182
|
+
const profile = await readProfile(page);
|
|
165
183
|
printJson({
|
|
166
184
|
ok: true,
|
|
167
185
|
login_required: false,
|
|
168
186
|
account,
|
|
169
187
|
title: await page.title(),
|
|
188
|
+
profile,
|
|
170
189
|
notes,
|
|
171
190
|
videos,
|
|
172
191
|
articles,
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* live under <workspace>/.fancy/douyin. The deployed crawler scripts live under
|
|
6
6
|
* <workspace>/.fancy-tools/fancy-douyin.
|
|
7
7
|
*
|
|
8
|
-
* The crawl history is keyed by the
|
|
9
|
-
* /
|
|
8
|
+
* The crawl history is keyed by the work id parsed from /note/<id>, /video/<id>
|
|
9
|
+
* or /article/<id>. A work is written only after its analysis has been imported into
|
|
10
10
|
* the material library, or after it was confirmed irrelevant/long and skipped,
|
|
11
11
|
* so failed works are retried on the next run.
|
|
12
12
|
*/
|
|
@@ -28,6 +28,7 @@ export function douyinPaths(root) {
|
|
|
28
28
|
profile: path.join(base, 'chrome-profile'),
|
|
29
29
|
captchaLog: path.join(base, 'captcha.log'),
|
|
30
30
|
output: path.join(base, 'output'),
|
|
31
|
+
jobs: path.join(base, 'jobs'),
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -98,6 +99,10 @@ export function readAccounts(root) {
|
|
|
98
99
|
.map((item) => ({
|
|
99
100
|
url: item.url,
|
|
100
101
|
added_at: item.added_at || '',
|
|
102
|
+
name: typeof item.name === 'string' ? item.name : '',
|
|
103
|
+
douyin_id: typeof item.douyin_id === 'string' ? item.douyin_id : '',
|
|
104
|
+
sec_uid: typeof item.sec_uid === 'string' ? item.sec_uid : '',
|
|
105
|
+
last_scan_at: typeof item.last_scan_at === 'string' ? item.last_scan_at : '',
|
|
101
106
|
}));
|
|
102
107
|
}
|
|
103
108
|
|
|
@@ -106,6 +111,7 @@ export function writeAccounts(root, accounts) {
|
|
|
106
111
|
atomicWriteJson(paths.accounts, {
|
|
107
112
|
version: 1,
|
|
108
113
|
accounts: accounts.map((item) => ({
|
|
114
|
+
...item,
|
|
109
115
|
url: item.url,
|
|
110
116
|
added_at: item.added_at || new Date().toISOString(),
|
|
111
117
|
})),
|
|
@@ -128,6 +134,31 @@ export function addAccount(root, rawUrl) {
|
|
|
128
134
|
return { added: true, url, accounts };
|
|
129
135
|
}
|
|
130
136
|
|
|
137
|
+
/**
|
|
138
|
+
* Record the profile fields discovered while scanning an account homepage.
|
|
139
|
+
* Existing accounts keep all other state; unknown accounts are ignored.
|
|
140
|
+
*
|
|
141
|
+
* @param {string} root workspace directory
|
|
142
|
+
* @param {string} url normalized account URL
|
|
143
|
+
* @param {{name?: string, douyin_id?: string, sec_uid?: string, last_scan_at?: string}} profile
|
|
144
|
+
* @returns {object|null} updated account
|
|
145
|
+
*/
|
|
146
|
+
export function updateAccountProfile(root, url, profile) {
|
|
147
|
+
const accounts = readAccounts(root);
|
|
148
|
+
const index = accounts.findIndex((item) => item.url === url);
|
|
149
|
+
if (index < 0) return null;
|
|
150
|
+
const next = {
|
|
151
|
+
...accounts[index],
|
|
152
|
+
...(profile && typeof profile.name === 'string' && profile.name.trim() ? { name: profile.name.trim() } : {}),
|
|
153
|
+
...(profile && typeof profile.douyin_id === 'string' && profile.douyin_id.trim() ? { douyin_id: profile.douyin_id.trim() } : {}),
|
|
154
|
+
...(profile && typeof profile.sec_uid === 'string' && profile.sec_uid.trim() ? { sec_uid: profile.sec_uid.trim() } : {}),
|
|
155
|
+
last_scan_at: new Date().toISOString(),
|
|
156
|
+
};
|
|
157
|
+
accounts[index] = next;
|
|
158
|
+
writeAccounts(root, accounts);
|
|
159
|
+
return next;
|
|
160
|
+
}
|
|
161
|
+
|
|
131
162
|
/**
|
|
132
163
|
* Remove an account by 1-based list index or by homepage URL.
|
|
133
164
|
*
|
|
@@ -174,7 +205,7 @@ export function markCrawled(root, noteId, data) {
|
|
|
174
205
|
return state[noteId];
|
|
175
206
|
}
|
|
176
207
|
|
|
177
|
-
export function accountListText(root) {
|
|
208
|
+
export function accountListText(root, countsOverride = null) {
|
|
178
209
|
const accounts = readAccounts(root);
|
|
179
210
|
if (!accounts.length) {
|
|
180
211
|
return [
|
|
@@ -182,17 +213,25 @@ export function accountListText(root) {
|
|
|
182
213
|
'先添加账号主页:/fancy-douyin add https://www.douyin.com/user/...',
|
|
183
214
|
].join('\n');
|
|
184
215
|
}
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
216
|
+
const counts = countsOverride instanceof Map ? countsOverride : new Map();
|
|
217
|
+
if (!(countsOverride instanceof Map)) {
|
|
218
|
+
const crawled = readCrawled(root);
|
|
219
|
+
for (const item of Object.values(crawled)) {
|
|
220
|
+
if (!item || typeof item !== 'object' || !item.account_url) continue;
|
|
221
|
+
counts.set(item.account_url, (counts.get(item.account_url) || 0) + 1);
|
|
222
|
+
}
|
|
190
223
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
224
|
+
const lines = ['已记录的抖音账号:'];
|
|
225
|
+
accounts.forEach((item, index) => {
|
|
226
|
+
const count = counts.get(item.url) || 0;
|
|
227
|
+
if (item.name) {
|
|
228
|
+
const idText = item.douyin_id ? '抖音号:' + item.douyin_id : '抖音号未获取';
|
|
229
|
+
lines.push(`${index + 1}. ${item.name}(${idText})`);
|
|
230
|
+
lines.push(' ' + item.url);
|
|
231
|
+
} else {
|
|
232
|
+
lines.push(`${index + 1}. ${item.url}(未获取账号名/抖音号)`);
|
|
233
|
+
}
|
|
234
|
+
lines.push(` 已采集 ${count} 篇`);
|
|
235
|
+
});
|
|
236
|
+
return lines.join('\n');
|
|
198
237
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helpers for the optional DSH subagent analysis pool.
|
|
3
|
+
*
|
|
4
|
+
* The Douyin crawler still runs in the parent process. Only the LLM analysis
|
|
5
|
+
* of already-prepared works is delegated to child agents. That keeps Chrome,
|
|
6
|
+
* `crawled.json`, and material imports single-writer while allowing several
|
|
7
|
+
* image/video/article analyses to run at once.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export const DEFAULT_SUBAGENT_WORKERS = 3;
|
|
11
|
+
export const MAX_SUBAGENT_WORKERS = 6;
|
|
12
|
+
|
|
13
|
+
export function subagentWorkerCount(env = process.env) {
|
|
14
|
+
const raw = env && env.FANCY_DOUYIN_SUBAGENTS;
|
|
15
|
+
if (raw === undefined || raw === null || String(raw).trim() === '') return DEFAULT_SUBAGENT_WORKERS;
|
|
16
|
+
const value = Number(String(raw).trim());
|
|
17
|
+
if (!Number.isFinite(value) || value <= 0) return 0;
|
|
18
|
+
return Math.max(1, Math.min(MAX_SUBAGENT_WORKERS, Math.floor(value)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Resolve the DSH subagent runtime from a plugin context. The service is
|
|
23
|
+
* optional: older hosts or a profile without subagents simply fall back to the
|
|
24
|
+
* existing single-agent path.
|
|
25
|
+
*/
|
|
26
|
+
export function getSubagentRuntime(ctx, provider = 'spawn') {
|
|
27
|
+
if (!ctx) return null;
|
|
28
|
+
let service = null;
|
|
29
|
+
try {
|
|
30
|
+
service = typeof ctx.get === 'function' ? ctx.get('subagents') : ctx.subagents;
|
|
31
|
+
} catch {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
if (!service || typeof service.startActivation !== 'function') return null;
|
|
35
|
+
if (typeof service.getProvider === 'function' && !service.getProvider(provider)) return null;
|
|
36
|
+
return service;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Run a fixed list of jobs through at most `concurrency` workers.
|
|
41
|
+
* `worker` receives each item and is awaited before that worker takes another.
|
|
42
|
+
*/
|
|
43
|
+
export async function runJobPool(items, concurrency, worker) {
|
|
44
|
+
const list = Array.isArray(items) ? items : [];
|
|
45
|
+
const limit = Math.max(1, Math.min(Number(concurrency) || 1, list.length || 1));
|
|
46
|
+
let cursor = 0;
|
|
47
|
+
const runners = Array.from({ length: limit }, async () => {
|
|
48
|
+
while (true) {
|
|
49
|
+
const index = cursor;
|
|
50
|
+
cursor += 1;
|
|
51
|
+
if (index >= list.length) return;
|
|
52
|
+
await worker(list[index], index);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
await Promise.all(runners);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A small async mutex. Finalization is deliberately serialized because it
|
|
60
|
+
* writes crawled.json and opens the material database; the LLM work itself is
|
|
61
|
+
* already parallel.
|
|
62
|
+
*/
|
|
63
|
+
export function createSerialLock() {
|
|
64
|
+
let chain = Promise.resolve();
|
|
65
|
+
return function withLock(fn) {
|
|
66
|
+
const next = chain.then(fn, fn);
|
|
67
|
+
chain = next.catch(() => {});
|
|
68
|
+
return next;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* A single-producer / multi-consumer async queue. The parent pushes crawled
|
|
74
|
+
* jobs as soon as their files are ready; analysis workers consume them while
|
|
75
|
+
* the parent continues scanning and crawling.
|
|
76
|
+
*/
|
|
77
|
+
export function createJobQueue() {
|
|
78
|
+
const items = [];
|
|
79
|
+
const waiters = [];
|
|
80
|
+
let closed = false;
|
|
81
|
+
const wake = () => {
|
|
82
|
+
const waiter = waiters.shift();
|
|
83
|
+
if (waiter) waiter();
|
|
84
|
+
};
|
|
85
|
+
return {
|
|
86
|
+
push(item) {
|
|
87
|
+
if (closed) throw new Error('job queue is closed');
|
|
88
|
+
items.push(item);
|
|
89
|
+
wake();
|
|
90
|
+
},
|
|
91
|
+
close() {
|
|
92
|
+
closed = true;
|
|
93
|
+
while (waiters.length) wake();
|
|
94
|
+
},
|
|
95
|
+
async next() {
|
|
96
|
+
while (true) {
|
|
97
|
+
if (items.length) return items.shift();
|
|
98
|
+
if (closed) return null;
|
|
99
|
+
await new Promise((resolve) => waiters.push(resolve));
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
get size() {
|
|
103
|
+
return items.length;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
@@ -16,7 +16,7 @@ export function helpText() {
|
|
|
16
16
|
return `🎬 抖音素材采集 用法
|
|
17
17
|
|
|
18
18
|
/fancy-douyin add <主页地址> 记录一个抖音账号主页
|
|
19
|
-
/fancy-douyin list
|
|
19
|
+
/fancy-douyin list 查看账号名、抖音号和已采集数量
|
|
20
20
|
/fancy-douyin remove <序号|地址> 删除已记录的账号
|
|
21
21
|
/fancy-douyin 依次采集所有账号下未处理的图文、视频和文章作品
|
|
22
22
|
/fancy-douyin help 显示本帮助
|
|
@@ -29,11 +29,15 @@ export function helpText() {
|
|
|
29
29
|
- 图片和视频能力都没有时,跳过图文/视频,只处理文章。
|
|
30
30
|
- 图文作品会下载轮播原图并转成 JPG;如果轮播里混有视频页,会下载该页短视频,用场景变化检测 + 固定间隔兜底抽取关键帧拼图。
|
|
31
31
|
- 文章作品直接提取标题、发布日期、阅读时长和正文,按长文设定拆成原子素材。
|
|
32
|
+
- 扫描一个账号后,未处理作品会边采集边交给子 Agent 分析,不再等所有账号采集完。
|
|
33
|
+
- 父进程负责采集、校验、入库和任务状态;子 Agent 只写各作品的 materials.jsonl。
|
|
34
|
+
- 作品任务状态记录在素材库的 douyin_job 表;中途重启会复用稳定任务目录,已导入/已跳过的作品不会重采。
|
|
35
|
+
- 子 Agent 并发数由 FANCY_DOUYIN_SUBAGENTS 控制(默认 3,0 关闭);DSH 没有 subagent 服务或 spawn provider 时自动回退单 Agent 串行。
|
|
32
36
|
- 视频作品先判断时长:超过 1 分钟直接跳过;不超过 1 分钟的先看前 5 秒,
|
|
33
37
|
与网文创作无关就跳过,有关才继续分析关键帧。
|
|
34
38
|
- 如果内容与网文创作无关,LLM 会写入 skip 标记,该作品记为已处理并跳过。
|
|
35
39
|
- 素材按 material JSONL 格式写入数据库,source 固定为 other,kind 用中文作品主题。
|
|
36
|
-
-
|
|
40
|
+
- 已成功入库、确认无关或作品级失败的作品记录在素材库 douyin_job 表,后续跳过;账号级失败仍会重试。
|
|
37
41
|
- 登录态保存在 <工作区>/.fancy/douyin/chrome-profile/,并镜像到 login-state.json。
|
|
38
42
|
- 首次需要登录时用有头 Chrome;登录态有效后后续运行自动使用无头 Chrome。
|
|
39
43
|
- 每次运行结束会自动关闭 Chrome,释放资源。
|
|
@@ -237,11 +241,14 @@ export function summaryText({
|
|
|
237
241
|
stateFile,
|
|
238
242
|
aborted,
|
|
239
243
|
mode,
|
|
244
|
+
analysisMode = 'single',
|
|
245
|
+
subagentWorkers = 0,
|
|
240
246
|
}) {
|
|
241
247
|
const lines = [
|
|
242
248
|
aborted ? '⚠️ 抖音采集已中断' : '✅ 抖音采集完成',
|
|
243
249
|
'账号:' + accounts + ' 个(本次扫描 ' + scannedAccounts + ' 个)',
|
|
244
250
|
'浏览器:' + (mode === 'headless' ? '无头' : '有头'),
|
|
251
|
+
'分析模式:' + (analysisMode === 'subagent' ? '子 Agent 并行(' + subagentWorkers + ' 个)' : '单 Agent 串行'),
|
|
245
252
|
'发现图文:' + foundNotes + ' 篇',
|
|
246
253
|
'发现视频:' + foundVideos + ' 个',
|
|
247
254
|
'发现文章:' + foundArticles + ' 篇',
|