@mks2508/bundlp 0.1.13 → 0.1.14
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/dist/index.mjs +12 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1433,31 +1433,33 @@ var Player = class {
|
|
|
1433
1433
|
* Downloads and parses the YouTube player.js to extract cipher functions.
|
|
1434
1434
|
* Uses cache-first strategy to minimize network requests.
|
|
1435
1435
|
* @param playerUrl - Optional direct URL to player.js, auto-detected if not provided
|
|
1436
|
+
* @param videoId - Optional video ID to fetch player URL from watch page (more reliable)
|
|
1436
1437
|
* @returns Result indicating success or failure
|
|
1437
1438
|
*/
|
|
1438
|
-
async initialize(playerUrl) {
|
|
1439
|
+
async initialize(playerUrl, videoId) {
|
|
1439
1440
|
if (this.initialized) return ok(void 0);
|
|
1440
1441
|
if (this.cache && !playerUrl) {
|
|
1441
1442
|
const latestResult = this.cache.getLatest();
|
|
1442
1443
|
if (isOk(latestResult) && latestResult.value) return this.restoreFromCache(latestResult.value);
|
|
1443
1444
|
}
|
|
1444
1445
|
if (!playerUrl) {
|
|
1445
|
-
|
|
1446
|
-
|
|
1446
|
+
const fetchUrl = videoId ? `${YOUTUBE_BASE_URL}/watch?v=${videoId}` : YOUTUBE_BASE_URL;
|
|
1447
|
+
log$6.info(`Fetching player URL from: ${fetchUrl}`);
|
|
1448
|
+
const htmlResult = await httpClient.get(fetchUrl);
|
|
1447
1449
|
if (!isOk(htmlResult)) {
|
|
1448
|
-
log$6.error("Failed to fetch
|
|
1450
|
+
log$6.error("Failed to fetch page:", htmlResult.error.message);
|
|
1449
1451
|
return err(htmlResult.error);
|
|
1450
1452
|
}
|
|
1451
1453
|
const html = await htmlResult.value.text();
|
|
1452
|
-
log$6.info(`
|
|
1453
|
-
|
|
1454
|
-
if (html.includes("Sign in to confirm")) log$6.error(
|
|
1454
|
+
log$6.info(`Response: ${html.length} chars`);
|
|
1455
|
+
const title = html.match(/<title>([^<]*)<\/title>/)?.[1] || "";
|
|
1456
|
+
if (html.includes("Sign in to confirm") || title.toLowerCase().includes("sign in")) log$6.error(`BOT DETECTION: YouTube returned login page (title: ${title})`);
|
|
1455
1457
|
if (html.includes("robot") || html.includes("captcha")) log$6.error("BOT DETECTION: YouTube returned robot/captcha page");
|
|
1456
1458
|
const match$1 = html.match(/\/s\/player\/[a-zA-Z0-9_-]+\/[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+\/base\.js/);
|
|
1457
1459
|
if (!match$1) {
|
|
1458
1460
|
log$6.error("Player URL pattern not found in HTML");
|
|
1459
|
-
log$6.error(`HTML title: ${
|
|
1460
|
-
return err(createError("PLAYER_FETCH_FAILED",
|
|
1461
|
+
log$6.error(`HTML title: ${title}`);
|
|
1462
|
+
return err(createError("PLAYER_FETCH_FAILED", `Could not determine player URL from ${fetchUrl}`));
|
|
1461
1463
|
}
|
|
1462
1464
|
playerUrl = YOUTUBE_BASE_URL + match$1[0];
|
|
1463
1465
|
log$6.success(`Found player URL: ${playerUrl}`);
|
|
@@ -2361,7 +2363,7 @@ var YouTubeExtractor = class {
|
|
|
2361
2363
|
return err(createError("INVALID_URL", `Could not extract video ID from: ${url}`));
|
|
2362
2364
|
}
|
|
2363
2365
|
async realExtract(videoId) {
|
|
2364
|
-
const playerResult = await this.player.initialize();
|
|
2366
|
+
const playerResult = await this.player.initialize(void 0, videoId);
|
|
2365
2367
|
if (isErr(playerResult)) return err(playerResult.error);
|
|
2366
2368
|
const responseResult = await this.client.fetchPlayerWithFallback(videoId, {
|
|
2367
2369
|
signatureTimestamp: this.player.getSignatureTimestamp(),
|