tt-help-cli-ycl 1.3.46 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tt-help-cli-ycl",
3
- "version": "1.3.46",
3
+ "version": "1.3.47",
4
4
  "description": "TikTok user & video data scraper - extract ttSeller, verified, locationCreated from HTML source",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,7 +9,7 @@ const DEFAULT_WAF_TTL = 120000;
9
9
  const DEFAULT_WARM_URL = "https://www.tiktok.com/@nike";
10
10
  const BROWSER_CLOSE_TIMEOUT = 5000;
11
11
  const DEFAULT_MAX_REQUESTS_PER_PAGE = 50;
12
- const FALLBACK_PROFILE_PORT = 9222;
12
+ const FALLBACK_PROFILE_PORT = 9999;
13
13
 
14
14
  function delay(ms) {
15
15
  return new Promise((r) => setTimeout(r, ms));
@@ -25,6 +25,12 @@ function getFallbackProfileDir() {
25
25
  );
26
26
  }
27
27
 
28
+ function fallbackProfileExists() {
29
+ const fs = require("fs");
30
+ const dir = getFallbackProfileDir();
31
+ return fs.existsSync(dir);
32
+ }
33
+
28
34
  class PageSlot {
29
35
  constructor(page) {
30
36
  this.page = page;
@@ -139,12 +145,16 @@ export class TikTokScraper {
139
145
 
140
146
  async _ensureFallback(executablePath) {
141
147
  if (this._fallbackContext) return;
148
+ if (!fallbackProfileExists()) {
149
+ return false;
150
+ }
142
151
  const fallbackDir = getFallbackProfileDir();
143
152
  console.error(`[TikTokScraper] 无登录态获取失败,fallback 到登录态 profile: ${fallbackDir}`);
144
153
  const { browser, context, slots } = await initContext(executablePath, 1, fallbackDir);
145
154
  this._fallbackBrowser = browser;
146
155
  this._fallbackContext = context;
147
156
  this._fallbackSlots = slots;
157
+ return true;
148
158
  }
149
159
 
150
160
  async close() {
@@ -275,9 +285,11 @@ export class TikTokScraper {
275
285
 
276
286
  // 解析失败:fallback 到登录态
277
287
  if (!result) {
278
- await this._ensureFallback(executablePath);
279
- rawHtml = await this._fetchViewSource(url, this._fallbackContext);
280
- result = rawHtml ? parseUserInfo(rawHtml) : null;
288
+ const ok = await this._ensureFallback(executablePath);
289
+ if (ok) {
290
+ rawHtml = await this._fetchViewSource(url, this._fallbackContext);
291
+ result = rawHtml ? parseUserInfo(rawHtml) : null;
292
+ }
281
293
  }
282
294
 
283
295
  return result || null;
@@ -292,9 +304,11 @@ export class TikTokScraper {
292
304
 
293
305
  // 解析失败:fallback 到登录态
294
306
  if (!result) {
295
- await this._ensureFallback(executablePath);
296
- rawHtml = await this._fetchViewSource(videoUrl, this._fallbackContext);
297
- result = rawHtml ? parseVideoInfo(rawHtml) : null;
307
+ const ok = await this._ensureFallback(executablePath);
308
+ if (ok) {
309
+ rawHtml = await this._fetchViewSource(videoUrl, this._fallbackContext);
310
+ result = rawHtml ? parseVideoInfo(rawHtml) : null;
311
+ }
298
312
  }
299
313
 
300
314
  return result || null;