tt-help-cli-ycl 1.3.35 → 1.3.37
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/README.md +17 -1
- package/cli.js +3 -3
- package/package.json +7 -2
- package/scripts/test-watch-db-smoke.mjs +246 -0
- package/src/cli/attach.js +149 -89
- package/src/cli/auto.js +180 -155
- package/src/cli/comments.js +301 -210
- package/src/cli/config.js +62 -44
- package/src/cli/db-import.js +51 -0
- package/src/cli/explore.js +373 -342
- package/src/cli/refresh.js +223 -151
- package/src/cli/videostats.js +140 -25
- package/src/cli/watch.js +15 -16
- package/src/lib/args.js +50 -6
- package/src/lib/constants.js +159 -92
- package/src/lib/tiktok-scraper.mjs +59 -21
- package/src/main.js +42 -20
- package/src/npm-main.js +69 -0
- package/src/watch/data-store.js +1560 -236
- package/src/watch/public/index.html +51 -15
- package/src/watch/server.js +63 -374
package/src/cli/config.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
HELP_TEXT,
|
|
3
|
+
configPath,
|
|
4
|
+
saveBrowser,
|
|
5
|
+
saveUserId,
|
|
6
|
+
saveMaxFollowing,
|
|
7
|
+
saveMaxFollowers,
|
|
8
|
+
saveMaxVideos,
|
|
9
|
+
saveMaxComments,
|
|
10
|
+
getConfigText,
|
|
11
|
+
} from "../lib/constants.js";
|
|
12
|
+
import { readFileSync, writeFileSync, existsSync } from "fs";
|
|
13
|
+
import { fileURLToPath } from "url";
|
|
14
|
+
import { dirname, join } from "path";
|
|
5
15
|
|
|
6
16
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
const pkgPath = join(__dirname,
|
|
8
|
-
const { version } = JSON.parse(readFileSync(pkgPath,
|
|
17
|
+
const pkgPath = join(__dirname, "..", "..", "package.json");
|
|
18
|
+
const { version } = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
9
19
|
|
|
10
20
|
function showConfig(urls, outputFile) {
|
|
11
21
|
const configLines = getConfigText();
|
|
@@ -13,101 +23,103 @@ function showConfig(urls, outputFile) {
|
|
|
13
23
|
configLines.push(`\n URL数量: ${urls.length}`);
|
|
14
24
|
}
|
|
15
25
|
if (outputFile) {
|
|
16
|
-
configLines.push(`
|
|
26
|
+
configLines.push(` 输出/锚点路径: ${outputFile}`);
|
|
17
27
|
}
|
|
18
|
-
console.error(configLines.join(
|
|
28
|
+
console.error(configLines.join("\n"));
|
|
19
29
|
}
|
|
20
30
|
|
|
21
|
-
function showUsage() {
|
|
22
|
-
console.error(
|
|
31
|
+
function showUsage(helpText = HELP_TEXT) {
|
|
32
|
+
console.error(helpText.join("\n"));
|
|
23
33
|
process.exit(0);
|
|
24
34
|
}
|
|
25
35
|
|
|
26
36
|
function handleConfig(action, key, value) {
|
|
27
37
|
switch (action) {
|
|
28
|
-
case
|
|
38
|
+
case "show": {
|
|
29
39
|
const configLines = getConfigText();
|
|
30
|
-
console.error(configLines.join(
|
|
40
|
+
console.error(configLines.join("\n"));
|
|
31
41
|
break;
|
|
32
42
|
}
|
|
33
43
|
|
|
34
|
-
case
|
|
44
|
+
case "set": {
|
|
35
45
|
if (!key) {
|
|
36
|
-
console.error(
|
|
37
|
-
console.error(
|
|
46
|
+
console.error("用法: tt-help config set <key> <value>");
|
|
47
|
+
console.error(
|
|
48
|
+
" 可用 key: proxy, server, browser, userId, maxFollowing, maxFollowers, maxVideos, maxComments",
|
|
49
|
+
);
|
|
38
50
|
return;
|
|
39
51
|
}
|
|
40
52
|
|
|
41
53
|
switch (key) {
|
|
42
|
-
case
|
|
54
|
+
case "proxy":
|
|
43
55
|
if (!value) {
|
|
44
|
-
console.error(
|
|
45
|
-
console.error(
|
|
56
|
+
console.error("请提供 proxy 的值");
|
|
57
|
+
console.error("用法: tt-help config set proxy <代理地址>");
|
|
46
58
|
return;
|
|
47
59
|
}
|
|
48
60
|
saveProxy(value);
|
|
49
61
|
console.error(`代理已更新: ${value}`);
|
|
50
62
|
break;
|
|
51
63
|
|
|
52
|
-
case
|
|
64
|
+
case "server":
|
|
53
65
|
if (!value) {
|
|
54
|
-
console.error(
|
|
66
|
+
console.error("请提供 server 的值");
|
|
55
67
|
return;
|
|
56
68
|
}
|
|
57
69
|
saveServer(value);
|
|
58
70
|
console.error(`服务器已更新: ${value}`);
|
|
59
71
|
break;
|
|
60
72
|
|
|
61
|
-
case
|
|
73
|
+
case "browser":
|
|
62
74
|
if (!value) {
|
|
63
|
-
console.error(
|
|
64
|
-
console.error(
|
|
65
|
-
console.error(
|
|
75
|
+
console.error("请提供 browser 的值");
|
|
76
|
+
console.error("用法: tt-help config set browser <浏览器路径>");
|
|
77
|
+
console.error(" 或: tt-help config set-browser <浏览器路径>");
|
|
66
78
|
return;
|
|
67
79
|
}
|
|
68
80
|
saveBrowser(value);
|
|
69
81
|
console.error(`浏览器路径已更新: ${value}`);
|
|
70
82
|
break;
|
|
71
83
|
|
|
72
|
-
case
|
|
84
|
+
case "userId":
|
|
73
85
|
if (!value) {
|
|
74
|
-
console.error(
|
|
86
|
+
console.error("请提供 userId 的值");
|
|
75
87
|
return;
|
|
76
88
|
}
|
|
77
89
|
saveUserId(value);
|
|
78
90
|
console.error(`用户号已更新: ${value}`);
|
|
79
91
|
break;
|
|
80
92
|
|
|
81
|
-
case
|
|
93
|
+
case "maxFollowing":
|
|
82
94
|
if (!value) {
|
|
83
|
-
console.error(
|
|
95
|
+
console.error("请提供 maxFollowing 的值");
|
|
84
96
|
return;
|
|
85
97
|
}
|
|
86
98
|
saveMaxFollowing(value);
|
|
87
99
|
console.error(`商家关注采集数已更新: ${value}`);
|
|
88
100
|
break;
|
|
89
101
|
|
|
90
|
-
case
|
|
102
|
+
case "maxFollowers":
|
|
91
103
|
if (!value) {
|
|
92
|
-
console.error(
|
|
104
|
+
console.error("请提供 maxFollowers 的值");
|
|
93
105
|
return;
|
|
94
106
|
}
|
|
95
107
|
saveMaxFollowers(value);
|
|
96
108
|
console.error(`粉丝采集数已更新: ${value}`);
|
|
97
109
|
break;
|
|
98
110
|
|
|
99
|
-
case
|
|
111
|
+
case "maxVideos":
|
|
100
112
|
if (!value) {
|
|
101
|
-
console.error(
|
|
113
|
+
console.error("请提供 maxVideos 的值");
|
|
102
114
|
return;
|
|
103
115
|
}
|
|
104
116
|
saveMaxVideos(value);
|
|
105
117
|
console.error(`视频采集数已更新: ${value}`);
|
|
106
118
|
break;
|
|
107
119
|
|
|
108
|
-
case
|
|
120
|
+
case "maxComments":
|
|
109
121
|
if (!value) {
|
|
110
|
-
console.error(
|
|
122
|
+
console.error("请提供 maxComments 的值");
|
|
111
123
|
return;
|
|
112
124
|
}
|
|
113
125
|
saveMaxComments(value);
|
|
@@ -116,37 +128,43 @@ function handleConfig(action, key, value) {
|
|
|
116
128
|
|
|
117
129
|
default:
|
|
118
130
|
console.error(`未知配置项: ${key}`);
|
|
119
|
-
console.error(
|
|
131
|
+
console.error(
|
|
132
|
+
" 可用 key: proxy, server, browser, userId, maxFollowing, maxFollowers, maxVideos, maxComments",
|
|
133
|
+
);
|
|
120
134
|
}
|
|
121
135
|
break;
|
|
122
136
|
}
|
|
123
137
|
|
|
124
|
-
case
|
|
138
|
+
case "reset": {
|
|
125
139
|
if (existsSync(configPath)) {
|
|
126
|
-
writeFileSync(configPath,
|
|
127
|
-
console.error(
|
|
140
|
+
writeFileSync(configPath, "{}", "utf-8");
|
|
141
|
+
console.error("配置已重置为默认");
|
|
128
142
|
} else {
|
|
129
|
-
console.error(
|
|
143
|
+
console.error("配置文件不存在或已是默认状态");
|
|
130
144
|
}
|
|
131
145
|
break;
|
|
132
146
|
}
|
|
133
147
|
|
|
134
148
|
default:
|
|
135
149
|
console.error(`未知配置命令: ${action}`);
|
|
136
|
-
console.error(
|
|
150
|
+
console.error("用法: tt-help config [show|set|reset]");
|
|
137
151
|
}
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
function saveProxy(newProxy) {
|
|
141
|
-
const cfg = existsSync(configPath)
|
|
155
|
+
const cfg = existsSync(configPath)
|
|
156
|
+
? JSON.parse(readFileSync(configPath, "utf-8"))
|
|
157
|
+
: {};
|
|
142
158
|
cfg.proxy = newProxy;
|
|
143
|
-
writeFileSync(configPath, JSON.stringify(cfg, null, 2),
|
|
159
|
+
writeFileSync(configPath, JSON.stringify(cfg, null, 2), "utf-8");
|
|
144
160
|
}
|
|
145
161
|
|
|
146
162
|
function saveServer(newServer) {
|
|
147
|
-
const cfg = existsSync(configPath)
|
|
163
|
+
const cfg = existsSync(configPath)
|
|
164
|
+
? JSON.parse(readFileSync(configPath, "utf-8"))
|
|
165
|
+
: {};
|
|
148
166
|
cfg.server = newServer;
|
|
149
|
-
writeFileSync(configPath, JSON.stringify(cfg, null, 2),
|
|
167
|
+
writeFileSync(configPath, JSON.stringify(cfg, null, 2), "utf-8");
|
|
150
168
|
}
|
|
151
169
|
|
|
152
170
|
export { handleConfig, showConfig, showUsage, version };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { closeStoreDb, importLegacyJsonToDb } from "../watch/data-store.js";
|
|
2
|
+
|
|
3
|
+
export async function handleDbImport(options) {
|
|
4
|
+
const { dbPath, usersFilePath, doneFilePath, videosFilePath, showHelp } =
|
|
5
|
+
options;
|
|
6
|
+
|
|
7
|
+
if (showHelp) {
|
|
8
|
+
console.error(
|
|
9
|
+
"用法: tt-help db-import --db <db路径> [--users users.json] [--done done.json] [--videos videos.json]",
|
|
10
|
+
);
|
|
11
|
+
console.error("");
|
|
12
|
+
console.error("示例:");
|
|
13
|
+
console.error(
|
|
14
|
+
" tt-help db-import --db data/result.db --users data/result.json --done data/result-done.json --videos data/result-videos.json",
|
|
15
|
+
);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!dbPath) {
|
|
20
|
+
console.error("请提供 --db <db路径>");
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!usersFilePath && !doneFilePath && !videosFilePath) {
|
|
25
|
+
console.error("至少提供一个导入源:--users / --done / --videos");
|
|
26
|
+
process.exit(1);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = importLegacyJsonToDb({
|
|
31
|
+
dbFilePath: dbPath,
|
|
32
|
+
usersFilePath,
|
|
33
|
+
doneFilePath,
|
|
34
|
+
videosFilePath,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
console.error("[db-import] 导入完成");
|
|
38
|
+
console.error(`[db-import] 数据库: ${result.dbPath}`);
|
|
39
|
+
console.error(
|
|
40
|
+
`[db-import] 新增 users: ${result.usersImported}, 总数: ${result.totalUsers}`,
|
|
41
|
+
);
|
|
42
|
+
console.error(
|
|
43
|
+
`[db-import] 新增 jobs: ${result.jobsImported}, 总数: ${result.totalJobs}`,
|
|
44
|
+
);
|
|
45
|
+
console.error(
|
|
46
|
+
`[db-import] 新增 videos: ${result.videosImported}, 总数: ${result.totalVideos}`,
|
|
47
|
+
);
|
|
48
|
+
} finally {
|
|
49
|
+
closeStoreDb();
|
|
50
|
+
}
|
|
51
|
+
}
|