tt-help-cli-ycl 1.3.0 → 1.3.2

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 (58) hide show
  1. package/README.md +17 -17
  2. package/cli.js +9 -9
  3. package/package.json +44 -44
  4. package/src/cli/auto.js +94 -0
  5. package/src/cli/explore.js +117 -0
  6. package/src/cli/progress.js +111 -0
  7. package/src/cli/scrape.js +47 -0
  8. package/src/cli/utils.js +18 -0
  9. package/src/cli/videos.js +41 -0
  10. package/src/cli/watch.js +28 -0
  11. package/src/lib/args.js +386 -397
  12. package/src/lib/browser/anti-detect.js +23 -0
  13. package/src/lib/browser/cdp.js +142 -0
  14. package/src/lib/browser/launch.js +43 -0
  15. package/src/lib/browser/page.js +80 -0
  16. package/src/lib/constants.js +85 -168
  17. package/src/lib/delay.js +54 -0
  18. package/src/lib/explore-fetch.js +118 -0
  19. package/src/lib/fetcher.js +45 -60
  20. package/src/lib/filter.js +66 -66
  21. package/src/lib/io.js +54 -76
  22. package/src/lib/output.js +80 -80
  23. package/src/lib/parser.js +47 -47
  24. package/src/lib/retry.js +44 -0
  25. package/src/lib/scrape.js +40 -39
  26. package/src/lib/url.js +52 -0
  27. package/src/main.mjs +199 -962
  28. package/src/results/user-videos-bar.lar.lar.moeta.json +37 -0
  29. package/src/scraper/auto-core.mjs +183 -0
  30. package/src/scraper/{core.cjs → core.mjs} +188 -214
  31. package/src/{explore-core.cjs → scraper/explore-core.mjs} +44 -42
  32. package/src/scraper/modules/captcha-handler.mjs +114 -0
  33. package/src/scraper/modules/comment-extractor.mjs +69 -0
  34. package/src/scraper/modules/follow-extractor.mjs +121 -0
  35. package/src/scraper/modules/{guess-extractor.cjs → guess-extractor.mjs} +51 -53
  36. package/src/scraper/modules/page-error-detector.mjs +70 -0
  37. package/src/scraper/modules/page-helpers.mjs +46 -0
  38. package/src/scraper/modules/scroll-collector.mjs +189 -0
  39. package/src/{get-user-videos-core.cjs → videos/core.mjs} +126 -143
  40. package/src/watch/data-store.mjs +239 -0
  41. package/src/watch/public/index.html +446 -271
  42. package/src/watch/server.mjs +257 -153
  43. package/src/auto-core.cjs +0 -367
  44. package/src/data-store.cjs +0 -69
  45. package/src/get-user-videos.cjs +0 -59
  46. package/src/lib/auto-browser.mjs +0 -13
  47. package/src/lib/explore.js +0 -225
  48. package/src/lib/get-user-videos-browser.mjs +0 -6
  49. package/src/lib/scrape-browser.mjs +0 -6
  50. package/src/scraper/index.cjs +0 -97
  51. package/src/scraper/modules/comment-extractor.cjs +0 -49
  52. package/src/scraper/modules/follow-extractor.cjs +0 -112
  53. package/src/scraper/modules/page-helpers.cjs +0 -422
  54. package/src/scraper/modules/scroll-collector.cjs +0 -173
  55. package/src/scraper/modules/video-scanner.cjs +0 -43
  56. package/src/test-auto-follow.cjs +0 -109
  57. package/src/test-extractors.cjs +0 -75
  58. package/src/test-follow.cjs +0 -41
package/src/lib/parser.js CHANGED
@@ -1,47 +1,47 @@
1
- import { USER_SECTION_SIZE } from './constants.js';
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
+ }
@@ -0,0 +1,44 @@
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
+ export function isRetryableError(error) {
20
+ if (!error) return false;
21
+ const msg = (error.message || error.toString() || '').toLowerCase();
22
+ return RETRYABLE_PATTERNS.some(p => new RegExp(p, 'i').test(msg));
23
+ }
24
+
25
+ export async function retryWithBackoff(fn, { maxRetries = 3, baseDelay = 3000, log } = {}) {
26
+ let lastError;
27
+ for (let attempt = 0; attempt <= maxRetries; attempt++) {
28
+ try {
29
+ return await fn();
30
+ } catch (error) {
31
+ lastError = error;
32
+ if (attempt >= maxRetries || !isRetryableError(error)) {
33
+ throw error;
34
+ }
35
+ const jitter = Math.random() * 2000;
36
+ const waitTime = baseDelay * Math.pow(2, attempt) + jitter;
37
+ if (log) {
38
+ log(` [重试] ${attempt + 1}/${maxRetries},${Math.round(waitTime / 1000)}s 后重试...`);
39
+ }
40
+ await delay(Math.round(waitTime), Math.round(waitTime));
41
+ }
42
+ }
43
+ throw lastError;
44
+ }
package/src/lib/scrape.js CHANGED
@@ -1,39 +1,40 @@
1
- import { extractUserSection, parseUserSection, extractLocationCreated } from './parser.js';
2
- import { fetchHtml, makeProfileUrl, isProfileUrl, isVideoUrl, extractProfileHandle } from './fetcher.js';
3
-
4
- export async function extractUserData(profileUrl, proxyUrl) {
5
- const profileHtml = await fetchHtml(profileUrl, proxyUrl);
6
- const section = extractUserSection(profileHtml);
7
- if (!section) throw new Error('无法解析用户信息');
8
- const data = parseUserSection(section);
9
- data.locationCreated = extractLocationCreated(profileHtml);
10
- return data;
11
- }
12
-
13
- export async function extractVideoLocation(videoUrl, proxyUrl) {
14
- const videoHtml = await fetchHtml(videoUrl, proxyUrl);
15
- return extractLocationCreated(videoHtml);
16
- }
17
-
18
- export async function processUrl(url, proxyUrl) {
19
- if (isProfileUrl(url)) {
20
- const profileUrl = makeProfileUrl(url);
21
- const profileData = await extractUserData(profileUrl, proxyUrl);
22
- return [profileData];
23
- }
24
-
25
- if (isVideoUrl(url)) {
26
- const profileHandle = extractProfileHandle(url);
27
- if (!profileHandle) throw new Error(`无法从视频URL提取用户主页: ${url}`);
28
-
29
- const profileUrl = makeProfileUrl(profileHandle);
30
- const [profileData, locationCreated] = await Promise.all([
31
- extractUserData(profileUrl, proxyUrl),
32
- extractVideoLocation(url, proxyUrl),
33
- ]);
34
-
35
- return [{ ...profileData, locationCreated }];
36
- }
37
-
38
- return [];
39
- }
1
+ import { extractUserSection, parseUserSection, extractLocationCreated } from './parser.js';
2
+ import { fetchHtml, isProfileUrl } from './fetcher.js';
3
+ import { toProfileUrl, isVideoUrl, extractUniqueId } from './url.js';
4
+
5
+ export async function extractUserData(profileUrl, proxyUrl) {
6
+ const profileHtml = await fetchHtml(profileUrl, proxyUrl);
7
+ const section = extractUserSection(profileHtml);
8
+ if (!section) throw new Error('无法解析用户信息');
9
+ const data = parseUserSection(section);
10
+ data.locationCreated = extractLocationCreated(profileHtml);
11
+ return data;
12
+ }
13
+
14
+ export async function extractVideoLocation(videoUrl, proxyUrl) {
15
+ const videoHtml = await fetchHtml(videoUrl, proxyUrl);
16
+ return extractLocationCreated(videoHtml);
17
+ }
18
+
19
+ export async function processUrl(url, proxyUrl) {
20
+ if (isProfileUrl(url)) {
21
+ const profileUrl = toProfileUrl(url);
22
+ const profileData = await extractUserData(profileUrl, proxyUrl);
23
+ return [profileData];
24
+ }
25
+
26
+ if (isVideoUrl(url)) {
27
+ const profileHandle = extractUniqueId(url);
28
+ if (!profileHandle) throw new Error(`无法从视频URL提取用户主页: ${url}`);
29
+
30
+ const profileUrl = toProfileUrl(profileHandle);
31
+ const [profileData, locationCreated] = await Promise.all([
32
+ extractUserData(profileUrl, proxyUrl),
33
+ extractVideoLocation(url, proxyUrl),
34
+ ]);
35
+
36
+ return [{ ...profileData, locationCreated }];
37
+ }
38
+
39
+ return [];
40
+ }
package/src/lib/url.js ADDED
@@ -0,0 +1,52 @@
1
+ const BASE_URL = 'https://www.tiktok.com';
2
+
3
+ export function extractUniqueId(url) {
4
+ const m = url.match(/\/@([^/]+)/);
5
+ return m ? m[1] : null;
6
+ }
7
+
8
+ export function extractVideoId(url) {
9
+ const m = url.match(/\/video\/(\d+)/);
10
+ return m ? m[1] : null;
11
+ }
12
+
13
+ export function normalizeUsername(input) {
14
+ return (input || '').replace(/^@/, '');
15
+ }
16
+
17
+ export function toProfileUrl(handle) {
18
+ const clean = normalizeUsername(handle);
19
+ return `${BASE_URL}/@${clean}`;
20
+ }
21
+
22
+ export function toVideoUrl(handle, videoId) {
23
+ const clean = normalizeUsername(handle);
24
+ return `${BASE_URL}/@${clean}/video/${videoId}`;
25
+ }
26
+
27
+ export function ensureAbsoluteUrl(href) {
28
+ if (href.startsWith('http')) return href;
29
+ return `${BASE_URL}${href}`;
30
+ }
31
+
32
+ export function isProfileUrl(url) {
33
+ return /\/@[\w-]+(?:$|[?#])/.test(url);
34
+ }
35
+
36
+ export function isVideoUrl(url) {
37
+ return /\/video\/\d+/.test(url);
38
+ }
39
+
40
+ export function extractDisplayPath(url) {
41
+ try {
42
+ const parts = new URL(url).pathname.split('/').filter(Boolean);
43
+ return parts.slice(-2).join('/');
44
+ } catch {
45
+ return url;
46
+ }
47
+ }
48
+
49
+ export function extractAuthorFromVideoUrl(url) {
50
+ const m = url.match(/@([^/]+)\/video/);
51
+ return m ? '@' + m[1] : null;
52
+ }