tt-help-cli-ycl 1.3.45 → 1.3.47

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.
Files changed (67) hide show
  1. package/README.md +33 -33
  2. package/cli.js +9 -9
  3. package/package.json +52 -52
  4. package/scripts/run-explore copy.bat +101 -101
  5. package/scripts/run-explore.bat +134 -134
  6. package/scripts/run-explore.ps1 +159 -159
  7. package/scripts/run-explore.sh +121 -121
  8. package/src/cli/attach.js +331 -313
  9. package/src/cli/auto.js +265 -265
  10. package/src/cli/comments.js +620 -620
  11. package/src/cli/config.js +170 -170
  12. package/src/cli/db-import.js +51 -51
  13. package/src/cli/explore.js +555 -555
  14. package/src/cli/info.js +10 -16
  15. package/src/cli/open.js +111 -111
  16. package/src/cli/progress.js +111 -111
  17. package/src/cli/refresh.js +288 -288
  18. package/src/cli/scrape.js +47 -47
  19. package/src/cli/utils.js +18 -18
  20. package/src/cli/videos.js +41 -41
  21. package/src/cli/videostats.js +196 -196
  22. package/src/cli/watch.js +30 -30
  23. package/src/cli/webserver.js +19 -0
  24. package/src/lib/api-interceptor.js +161 -161
  25. package/src/lib/args.js +809 -778
  26. package/src/lib/browser/anti-detect.js +23 -23
  27. package/src/lib/browser/cdp.js +261 -261
  28. package/src/lib/browser/health-checker.js +114 -114
  29. package/src/lib/browser/launch.js +43 -43
  30. package/src/lib/browser/page.js +184 -184
  31. package/src/lib/constants.js +297 -287
  32. package/src/lib/delay.js +54 -54
  33. package/src/lib/explore-fetch.js +118 -118
  34. package/src/lib/fetcher.js +45 -45
  35. package/src/lib/filter.js +66 -66
  36. package/src/lib/io.js +54 -54
  37. package/src/lib/output.js +80 -80
  38. package/src/lib/page-error-detector.js +109 -109
  39. package/src/lib/parse-ssr.mjs +69 -69
  40. package/src/lib/parser.js +47 -47
  41. package/src/lib/retry.js +45 -45
  42. package/src/lib/scrape.js +90 -89
  43. package/src/lib/target-locations.js +61 -61
  44. package/src/lib/tiktok-scraper.mjs +173 -105
  45. package/src/lib/url.js +52 -52
  46. package/src/main.js +73 -70
  47. package/src/npm-main.js +70 -69
  48. package/src/scraper/auto-core.js +203 -203
  49. package/src/scraper/core.js +255 -255
  50. package/src/scraper/explore-core.js +208 -208
  51. package/src/scraper/modules/captcha-handler.js +114 -114
  52. package/src/scraper/modules/follow-extractor.js +250 -250
  53. package/src/scraper/modules/guess-extractor.js +51 -51
  54. package/src/scraper/modules/page-helpers.js +48 -48
  55. package/src/scraper/refresh-core.js +213 -213
  56. package/src/videos/core.js +143 -143
  57. package/src/watch/data-store.js +2980 -2978
  58. package/src/watch/public/index.html +2355 -2345
  59. package/src/watch/server.js +727 -727
  60. package/src/webserver/server.mjs +174 -0
  61. package/scripts/test-captcha-lib.mjs +0 -68
  62. package/scripts/test-captcha.mjs +0 -81
  63. package/scripts/test-incognito-lib.mjs +0 -36
  64. package/scripts/test-login-state.mjs +0 -128
  65. package/scripts/test-safe-click.mjs +0 -45
  66. package/scripts/test-watch-db-smoke.mjs +0 -246
  67. package/src/results/user-videos-bar.lar.lar.moeta.json +0 -37
package/src/lib/parser.js CHANGED
@@ -1,47 +1,47 @@
1
- export const USER_SECTION_SIZE = 12000;
2
-
3
- export function extractUserSection(html) {
4
- const idx = html.indexOf('"uniqueId"');
5
- if (idx < 0) return null;
6
- return html.substring(idx, idx + USER_SECTION_SIZE);
7
- }
8
-
9
- export function parseUserSection(section) {
10
- const data = {};
11
-
12
- for (const key of ['uniqueId', 'uid', 'secUid']) {
13
- const m = section.match(new RegExp(`"${key}":"([^"]*)`));
14
- if (m) data[key] = m[1];
15
- }
16
-
17
- for (const key of ['nickname', 'signature']) {
18
- const m = section.match(new RegExp(`"${key}":"((?:[^"\\\\]|\\\\.)*)"`, 'g'));
19
- if (m) {
20
- const raw = m[0].replace(`"${key}":"`, '').replace(/"$/, '');
21
- data[key] = raw.replace(/\\n/g, '\n').replace(/\\\\/g, '\\');
22
- }
23
- }
24
-
25
- for (const key of ['ttSeller', 'verified']) {
26
- const m = section.match(new RegExp(`"${key}":\\s*(true|false)`));
27
- data[key] = m ? m[1] === 'true' : undefined;
28
- }
29
-
30
- for (const key of ['followerCount', 'followingCount', 'heartCount', 'videoCount', 'diggCount']) {
31
- const m = section.match(new RegExp(`"${key}":(\\d+)`));
32
- if (m) data[key] = parseInt(m[1], 10);
33
- }
34
-
35
- const mt = section.match(/"createTime":(\d+)/);
36
- if (mt) data.createTime = parseInt(mt[1], 10);
37
-
38
- const ma = section.match(/"avatarLarger":"([^"]*)/);
39
- if (ma) data.avatarLarger = ma[1].replace(/\\u002F/g, '/');
40
-
41
- return data;
42
- }
43
-
44
- export function extractLocationCreated(html) {
45
- const m = html.match(/"locationCreated":"([^"]*)/);
46
- return m ? m[1] : null;
47
- }
1
+ export const USER_SECTION_SIZE = 12000;
2
+
3
+ export function extractUserSection(html) {
4
+ const idx = html.indexOf('"uniqueId"');
5
+ if (idx < 0) return null;
6
+ return html.substring(idx, idx + USER_SECTION_SIZE);
7
+ }
8
+
9
+ export function parseUserSection(section) {
10
+ const data = {};
11
+
12
+ for (const key of ['uniqueId', 'uid', 'secUid']) {
13
+ const m = section.match(new RegExp(`"${key}":"([^"]*)`));
14
+ if (m) data[key] = m[1];
15
+ }
16
+
17
+ for (const key of ['nickname', 'signature']) {
18
+ const m = section.match(new RegExp(`"${key}":"((?:[^"\\\\]|\\\\.)*)"`, 'g'));
19
+ if (m) {
20
+ const raw = m[0].replace(`"${key}":"`, '').replace(/"$/, '');
21
+ data[key] = raw.replace(/\\n/g, '\n').replace(/\\\\/g, '\\');
22
+ }
23
+ }
24
+
25
+ for (const key of ['ttSeller', 'verified']) {
26
+ const m = section.match(new RegExp(`"${key}":\\s*(true|false)`));
27
+ data[key] = m ? m[1] === 'true' : undefined;
28
+ }
29
+
30
+ for (const key of ['followerCount', 'followingCount', 'heartCount', 'videoCount', 'diggCount']) {
31
+ const m = section.match(new RegExp(`"${key}":(\\d+)`));
32
+ if (m) data[key] = parseInt(m[1], 10);
33
+ }
34
+
35
+ const mt = section.match(/"createTime":(\d+)/);
36
+ if (mt) data.createTime = parseInt(mt[1], 10);
37
+
38
+ const ma = section.match(/"avatarLarger":"([^"]*)/);
39
+ if (ma) data.avatarLarger = ma[1].replace(/\\u002F/g, '/');
40
+
41
+ return data;
42
+ }
43
+
44
+ export function extractLocationCreated(html) {
45
+ const m = html.match(/"locationCreated":"([^"]*)/);
46
+ return m ? m[1] : null;
47
+ }
package/src/lib/retry.js CHANGED
@@ -1,45 +1,45 @@
1
- import { delay } from './delay.js';
2
-
3
- const RETRYABLE_PATTERNS = [
4
- 'interrupted',
5
- 'Navigation.*interrupted',
6
- 'net::',
7
- 'ECONN',
8
- 'ETIMEDOUT',
9
- 'ENOTFOUND',
10
- 'EAI_AGAIN',
11
- 'ESOCKETRESET',
12
- 'connection.*refused',
13
- 'connection.*reset',
14
- 'failed.*navigate',
15
- 'target.*closed',
16
- 'crash',
17
- '代理错误',
18
- ];
19
-
20
- export function isRetryableError(error) {
21
- if (!error) return false;
22
- const msg = error.message || error.toString() || '';
23
- return RETRYABLE_PATTERNS.some(p => new RegExp(p, 'i').test(msg));
24
- }
25
-
26
- export async function retryWithBackoff(fn, { maxRetries = 3, baseDelay = 3000, log } = {}) {
27
- let lastError;
28
- for (let attempt = 0; attempt <= maxRetries; attempt++) {
29
- try {
30
- return await fn();
31
- } catch (error) {
32
- lastError = error;
33
- if (attempt >= maxRetries || !isRetryableError(error)) {
34
- throw error;
35
- }
36
- const jitter = Math.random() * 2000;
37
- const waitTime = baseDelay * Math.pow(2, attempt) + jitter;
38
- if (log) {
39
- log(` [重试] ${attempt + 1}/${maxRetries},${Math.round(waitTime / 1000)}s 后重试...`);
40
- }
41
- await delay(Math.round(waitTime), Math.round(waitTime));
42
- }
43
- }
44
- throw lastError;
45
- }
1
+ import { delay } from './delay.js';
2
+
3
+ const RETRYABLE_PATTERNS = [
4
+ 'interrupted',
5
+ 'Navigation.*interrupted',
6
+ 'net::',
7
+ 'ECONN',
8
+ 'ETIMEDOUT',
9
+ 'ENOTFOUND',
10
+ 'EAI_AGAIN',
11
+ 'ESOCKETRESET',
12
+ 'connection.*refused',
13
+ 'connection.*reset',
14
+ 'failed.*navigate',
15
+ 'target.*closed',
16
+ 'crash',
17
+ '代理错误',
18
+ ];
19
+
20
+ export function isRetryableError(error) {
21
+ if (!error) return false;
22
+ const msg = error.message || error.toString() || '';
23
+ return RETRYABLE_PATTERNS.some(p => new RegExp(p, 'i').test(msg));
24
+ }
25
+
26
+ export async function retryWithBackoff(fn, { maxRetries = 3, baseDelay = 3000, log } = {}) {
27
+ let lastError;
28
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
29
+ try {
30
+ return await fn();
31
+ } catch (error) {
32
+ lastError = error;
33
+ if (attempt >= maxRetries || !isRetryableError(error)) {
34
+ throw error;
35
+ }
36
+ const jitter = Math.random() * 2000;
37
+ const waitTime = baseDelay * Math.pow(2, attempt) + jitter;
38
+ if (log) {
39
+ log(` [重试] ${attempt + 1}/${maxRetries},${Math.round(waitTime / 1000)}s 后重试...`);
40
+ }
41
+ await delay(Math.round(waitTime), Math.round(waitTime));
42
+ }
43
+ }
44
+ throw lastError;
45
+ }
package/src/lib/scrape.js CHANGED
@@ -1,89 +1,90 @@
1
- import { TikTokScraper } from './tiktok-scraper.mjs';
2
- import { isProfileUrl, isVideoUrl, extractUniqueId, normalizeUsername } from './url.js';
3
-
4
- // Lazy singleton for TikTokScraper
5
- let scraperInstance = null;
6
- let scraperInitPromise = null;
7
-
8
- async function getScraper() {
9
- if (scraperInstance) return scraperInstance;
10
- if (scraperInitPromise) return scraperInitPromise;
11
- scraperInitPromise = (async () => {
12
- const scraper = new TikTokScraper();
13
- await scraper.init();
14
- scraperInstance = scraper;
15
- scraperInitPromise = null;
16
- return scraper;
17
- })();
18
- return scraperInitPromise;
19
- }
20
-
21
- export async function closeScraper() {
22
- if (scraperInstance) {
23
- await scraperInstance.close();
24
- scraperInstance = null;
25
- }
26
- }
27
-
28
- // Map parseUserInfo output to legacy parser.js format
29
- function mapUserInfo(user) {
30
- if (!user) return null;
31
- return {
32
- uniqueId: user.uniqueId,
33
- uid: user.id,
34
- secUid: user.secUid,
35
- nickname: user.nickname,
36
- signature: user.bio,
37
- ttSeller: user.ttSeller,
38
- verified: user.verified,
39
- followerCount: user.followerCount,
40
- followingCount: user.followingCount,
41
- heartCount: user.heartCount,
42
- videoCount: user.videoCount,
43
- diggCount: user.diggCount,
44
- avatarLarger: user.avatar,
45
- locationCreated: user.locationCreated,
46
- };
47
- }
48
-
49
- // Map parseVideoInfo output to legacy format
50
- function mapVideoLocation(video) {
51
- if (!video) return null;
52
- return video.locationCreated;
53
- }
54
-
55
- export async function extractUserData(url) {
56
- const scraper = await getScraper();
57
- const uniqueId = extractUniqueId(url);
58
- if (!uniqueId) throw new Error(`无法从URL提取用户名: ${url}`);
59
- const user = await scraper.getUserInfo(normalizeUsername(uniqueId));
60
- if (!user) throw new Error('无法解析用户信息');
61
- return mapUserInfo(user);
62
- }
63
-
64
- export async function extractVideoLocation(videoUrl) {
65
- const scraper = await getScraper();
66
- const video = await scraper.getVideoInfo(videoUrl);
67
- return mapVideoLocation(video);
68
- }
69
-
70
- export async function processUrl(url) {
71
- if (isProfileUrl(url)) {
72
- const profileData = await extractUserData(url);
73
- return [profileData];
74
- }
75
-
76
- if (isVideoUrl(url)) {
77
- const profileHandle = extractUniqueId(url);
78
- if (!profileHandle) throw new Error(`无法从视频URL提取用户主页: ${url}`);
79
-
80
- const [profileData, locationCreated] = await Promise.all([
81
- extractUserData(url),
82
- extractVideoLocation(url),
83
- ]);
84
-
85
- return [{ ...profileData, locationCreated }];
86
- }
87
-
88
- return [];
89
- }
1
+ import { TikTokScraper } from './tiktok-scraper.mjs';
2
+ import { isProfileUrl, isVideoUrl, extractUniqueId, normalizeUsername } from './url.js';
3
+
4
+ // Lazy singleton for TikTokScraper
5
+ let scraperInstance = null;
6
+ let scraperInitPromise = null;
7
+
8
+ async function getScraper() {
9
+ if (scraperInstance) return scraperInstance;
10
+ if (scraperInitPromise) return scraperInitPromise;
11
+ scraperInitPromise = (async () => {
12
+ const scraper = new TikTokScraper();
13
+ await scraper.init();
14
+ scraperInstance = scraper;
15
+ scraperInitPromise = null;
16
+ return scraper;
17
+ })();
18
+ return scraperInitPromise;
19
+ }
20
+
21
+ export async function closeScraper() {
22
+ if (scraperInstance) {
23
+ await scraperInstance.close();
24
+ scraperInstance = null;
25
+ }
26
+ }
27
+
28
+ // Map parseUserInfo output to legacy parser.js format
29
+ function mapUserInfo(user) {
30
+ if (!user) return null;
31
+ return {
32
+ uniqueId: user.uniqueId,
33
+ uid: user.id,
34
+ secUid: user.secUid,
35
+ nickname: user.nickname,
36
+ signature: user.bio,
37
+ ttSeller: user.ttSeller,
38
+ verified: user.verified,
39
+ followerCount: user.followerCount,
40
+ followingCount: user.followingCount,
41
+ heartCount: user.heartCount,
42
+ videoCount: user.videoCount,
43
+ diggCount: user.diggCount,
44
+ avatarLarger: user.avatar,
45
+ locationCreated: user.locationCreated,
46
+ };
47
+ }
48
+
49
+ // Map parseVideoInfo output to legacy format
50
+ function mapVideoLocation(video) {
51
+ if (!video) return null;
52
+ return video.locationCreated;
53
+ }
54
+
55
+ export async function extractUserData(url) {
56
+ const scraper = await getScraper();
57
+ const uniqueId = extractUniqueId(url);
58
+ if (!uniqueId) throw new Error(`无法从URL提取用户名: ${url}`);
59
+ const user = await scraper.getUserInfo(normalizeUsername(uniqueId));
60
+ if (!user) return null;
61
+ return mapUserInfo(user);
62
+ }
63
+
64
+ export async function extractVideoLocation(videoUrl) {
65
+ const scraper = await getScraper();
66
+ const video = await scraper.getVideoInfo(videoUrl);
67
+ return mapVideoLocation(video);
68
+ }
69
+
70
+ export async function processUrl(url) {
71
+ if (isProfileUrl(url)) {
72
+ const profileData = await extractUserData(url);
73
+ return profileData ? [profileData] : [];
74
+ }
75
+
76
+ if (isVideoUrl(url)) {
77
+ const profileHandle = extractUniqueId(url);
78
+ if (!profileHandle) throw new Error(`无法从视频URL提取用户主页: ${url}`);
79
+
80
+ const [profileData, locationCreated] = await Promise.all([
81
+ extractUserData(url),
82
+ extractVideoLocation(url),
83
+ ]);
84
+
85
+ if (!profileData) return [];
86
+ return [{ ...profileData, locationCreated }];
87
+ }
88
+
89
+ return [];
90
+ }
@@ -1,61 +1,61 @@
1
- const DEFAULT_TARGET_LOCATIONS = [
2
- "CZ",
3
- "GR",
4
- "HU",
5
- "PT",
6
- "ES",
7
- "PL",
8
- "NL",
9
- "BE",
10
- "DE",
11
- "FR",
12
- "IT",
13
- "IE",
14
- "AT",
15
- ];
16
-
17
- const DEFAULT_TARGET_LOCATIONS_CSV = DEFAULT_TARGET_LOCATIONS.join(",");
18
-
19
- function normalizeLocation(location) {
20
- if (location == null) return null;
21
- const normalized = String(location).trim().toUpperCase();
22
- return normalized || null;
23
- }
24
-
25
- function normalizeLocationList(locations, fallback = DEFAULT_TARGET_LOCATIONS) {
26
- const source = Array.isArray(locations)
27
- ? locations
28
- : String(locations == null ? "" : locations).split(",");
29
- const normalized = source
30
- .map((location) => normalizeLocation(location))
31
- .filter(Boolean);
32
- return normalized.length > 0 ? [...new Set(normalized)] : [...fallback];
33
- }
34
-
35
- function isLocationInList(location, locations) {
36
- const normalizedLocation = normalizeLocation(location);
37
- if (!normalizedLocation) return false;
38
- return normalizeLocationList(locations).includes(normalizedLocation);
39
- }
40
-
41
- function findFirstMatchingLocation(
42
- locations,
43
- targetLocations = DEFAULT_TARGET_LOCATIONS,
44
- ) {
45
- const normalizedTargetLocations = normalizeLocationList(targetLocations);
46
- const normalizedLocations = normalizeLocationList(locations, []);
47
- return (
48
- normalizedLocations.find((location) =>
49
- normalizedTargetLocations.includes(location),
50
- ) || null
51
- );
52
- }
53
-
54
- export {
55
- DEFAULT_TARGET_LOCATIONS,
56
- DEFAULT_TARGET_LOCATIONS_CSV,
57
- findFirstMatchingLocation,
58
- isLocationInList,
59
- normalizeLocation,
60
- normalizeLocationList,
61
- };
1
+ const DEFAULT_TARGET_LOCATIONS = [
2
+ "CZ",
3
+ "GR",
4
+ "HU",
5
+ "PT",
6
+ "ES",
7
+ "PL",
8
+ "NL",
9
+ "BE",
10
+ "DE",
11
+ "FR",
12
+ "IT",
13
+ "IE",
14
+ "AT",
15
+ ];
16
+
17
+ const DEFAULT_TARGET_LOCATIONS_CSV = DEFAULT_TARGET_LOCATIONS.join(",");
18
+
19
+ function normalizeLocation(location) {
20
+ if (location == null) return null;
21
+ const normalized = String(location).trim().toUpperCase();
22
+ return normalized || null;
23
+ }
24
+
25
+ function normalizeLocationList(locations, fallback = DEFAULT_TARGET_LOCATIONS) {
26
+ const source = Array.isArray(locations)
27
+ ? locations
28
+ : String(locations == null ? "" : locations).split(",");
29
+ const normalized = source
30
+ .map((location) => normalizeLocation(location))
31
+ .filter(Boolean);
32
+ return normalized.length > 0 ? [...new Set(normalized)] : [...fallback];
33
+ }
34
+
35
+ function isLocationInList(location, locations) {
36
+ const normalizedLocation = normalizeLocation(location);
37
+ if (!normalizedLocation) return false;
38
+ return normalizeLocationList(locations).includes(normalizedLocation);
39
+ }
40
+
41
+ function findFirstMatchingLocation(
42
+ locations,
43
+ targetLocations = DEFAULT_TARGET_LOCATIONS,
44
+ ) {
45
+ const normalizedTargetLocations = normalizeLocationList(targetLocations);
46
+ const normalizedLocations = normalizeLocationList(locations, []);
47
+ return (
48
+ normalizedLocations.find((location) =>
49
+ normalizedTargetLocations.includes(location),
50
+ ) || null
51
+ );
52
+ }
53
+
54
+ export {
55
+ DEFAULT_TARGET_LOCATIONS,
56
+ DEFAULT_TARGET_LOCATIONS_CSV,
57
+ findFirstMatchingLocation,
58
+ isLocationInList,
59
+ normalizeLocation,
60
+ normalizeLocationList,
61
+ };