@tiktool/live 2.6.3 → 2.6.5
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 +80 -20
- package/dist/index.d.mts +142 -1
- package/dist/index.d.ts +142 -1
- package/dist/index.js +47 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1454,7 +1454,7 @@ var TikTokCaptions = class extends EventEmitter2 {
|
|
|
1454
1454
|
break;
|
|
1455
1455
|
default:
|
|
1456
1456
|
if (this.debug) {
|
|
1457
|
-
console.log(`[Captions] Unknown message type: ${msg.type}`, msg);
|
|
1457
|
+
if (this.debug) console.log(`[Captions] Unknown message type: ${msg.type}`, msg);
|
|
1458
1458
|
}
|
|
1459
1459
|
}
|
|
1460
1460
|
} catch {
|
|
@@ -1485,10 +1485,10 @@ var TikTokCaptions = class extends EventEmitter2 {
|
|
|
1485
1485
|
audioFramesSent++;
|
|
1486
1486
|
audioBytesSent += adtsFrame.length;
|
|
1487
1487
|
if (this.debug && (audioFramesSent <= 3 || audioFramesSent % 100 === 0)) {
|
|
1488
|
-
console.log(`[Captions] Audio frame #${audioFramesSent}: ${adtsFrame.length}b (total: ${audioBytesSent}b)`);
|
|
1488
|
+
if (this.debug) console.log(`[Captions] Audio frame #${audioFramesSent}: ${adtsFrame.length}b (total: ${audioBytesSent}b)`);
|
|
1489
1489
|
}
|
|
1490
1490
|
} else if (this.debug && audioFramesSent === 0) {
|
|
1491
|
-
console.log(`[Captions] WARNING: WS not open (readyState=${this.ws?.readyState}), cannot send audio`);
|
|
1491
|
+
if (this.debug) console.log(`[Captions] WARNING: WS not open (readyState=${this.ws?.readyState}), cannot send audio`);
|
|
1492
1492
|
}
|
|
1493
1493
|
});
|
|
1494
1494
|
try {
|
|
@@ -1521,7 +1521,7 @@ var TikTokCaptions = class extends EventEmitter2 {
|
|
|
1521
1521
|
this.flvExtractor.push(value);
|
|
1522
1522
|
}
|
|
1523
1523
|
if (this.debug && chunks <= 3) {
|
|
1524
|
-
console.log(`[Captions] FLV chunk #${chunks}: ${value?.length || 0}b`);
|
|
1524
|
+
if (this.debug) console.log(`[Captions] FLV chunk #${chunks}: ${value?.length || 0}b`);
|
|
1525
1525
|
}
|
|
1526
1526
|
}
|
|
1527
1527
|
} catch (err) {
|
|
@@ -1529,7 +1529,7 @@ var TikTokCaptions = class extends EventEmitter2 {
|
|
|
1529
1529
|
if (this.debug) console.error("[Captions] FLV stream read error:", err.message);
|
|
1530
1530
|
this.emit("error", { code: "STREAM_READ_ERROR", message: err.message });
|
|
1531
1531
|
} else if (this.debug) {
|
|
1532
|
-
console.log(`[Captions] FLV stream aborted after ${chunks} chunks, ${audioFramesSent} audio frames`);
|
|
1532
|
+
if (this.debug) console.log(`[Captions] FLV stream aborted after ${chunks} chunks, ${audioFramesSent} audio frames`);
|
|
1533
1533
|
}
|
|
1534
1534
|
}
|
|
1535
1535
|
};
|
|
@@ -1546,7 +1546,7 @@ var TikTokCaptions = class extends EventEmitter2 {
|
|
|
1546
1546
|
this.flvExtractor.push(u8);
|
|
1547
1547
|
}
|
|
1548
1548
|
if (this.debug && chunks <= 3) {
|
|
1549
|
-
console.log(`[Captions] FLV chunk #${chunks}: ${u8.length}b`);
|
|
1549
|
+
if (this.debug) console.log(`[Captions] FLV chunk #${chunks}: ${u8.length}b`);
|
|
1550
1550
|
}
|
|
1551
1551
|
}
|
|
1552
1552
|
if (this.debug) console.log(`[Captions] Node stream ended, chunks=${chunks}, audioFrames=${audioFramesSent}`);
|
|
@@ -1555,7 +1555,7 @@ var TikTokCaptions = class extends EventEmitter2 {
|
|
|
1555
1555
|
if (this.debug) console.error("[Captions] FLV stream read error:", err.message);
|
|
1556
1556
|
this.emit("error", { code: "STREAM_READ_ERROR", message: err.message });
|
|
1557
1557
|
} else if (this.debug) {
|
|
1558
|
-
console.log(`[Captions] FLV node stream aborted after ${chunks} chunks, ${audioFramesSent} audio frames`);
|
|
1558
|
+
if (this.debug) console.log(`[Captions] FLV node stream aborted after ${chunks} chunks, ${audioFramesSent} audio frames`);
|
|
1559
1559
|
}
|
|
1560
1560
|
}
|
|
1561
1561
|
};
|
|
@@ -1565,7 +1565,7 @@ var TikTokCaptions = class extends EventEmitter2 {
|
|
|
1565
1565
|
}
|
|
1566
1566
|
} catch (err) {
|
|
1567
1567
|
if (err.name !== "AbortError" && !this.intentionalClose) {
|
|
1568
|
-
console.error("[Captions] FLV stream connect error:", err.message);
|
|
1568
|
+
if (this.debug) console.error("[Captions] FLV stream connect error:", err.message);
|
|
1569
1569
|
this.emit("error", { code: "STREAM_CONNECT_ERROR", message: err.message });
|
|
1570
1570
|
}
|
|
1571
1571
|
}
|
|
@@ -1627,9 +1627,46 @@ async function getRegionalRanklist(opts) {
|
|
|
1627
1627
|
}
|
|
1628
1628
|
return data;
|
|
1629
1629
|
}
|
|
1630
|
+
async function getLiveFeed(opts) {
|
|
1631
|
+
const base = (opts.serverUrl || DEFAULT_SIGN_SERVER2).replace(/\/$/, "");
|
|
1632
|
+
const params = new URLSearchParams();
|
|
1633
|
+
params.set("apiKey", opts.apiKey);
|
|
1634
|
+
if (opts.region) params.set("region", opts.region);
|
|
1635
|
+
if (opts.channelId) params.set("channel_id", opts.channelId);
|
|
1636
|
+
if (opts.count !== void 0) params.set("count", String(Math.min(opts.count, 50)));
|
|
1637
|
+
if (opts.maxTime) params.set("max_time", opts.maxTime);
|
|
1638
|
+
if (opts.sessionId) params.set("session_id", opts.sessionId);
|
|
1639
|
+
if (opts.ttwid) params.set("ttwid", opts.ttwid);
|
|
1640
|
+
if (opts.msToken) params.set("ms_token", opts.msToken);
|
|
1641
|
+
const resp = await fetch(`${base}/webcast/feed?${params.toString()}`);
|
|
1642
|
+
const data = await resp.json();
|
|
1643
|
+
if (resp.status === 429) {
|
|
1644
|
+
throw new Error(data.error || "Feed daily limit reached. Upgrade your plan for more calls.");
|
|
1645
|
+
}
|
|
1646
|
+
if (!resp.ok) {
|
|
1647
|
+
throw new Error(data.error || `Feed request failed (HTTP ${resp.status})`);
|
|
1648
|
+
}
|
|
1649
|
+
return data;
|
|
1650
|
+
}
|
|
1651
|
+
async function fetchFeed(opts) {
|
|
1652
|
+
const signed = await getLiveFeed(opts);
|
|
1653
|
+
const headers = { ...signed.headers || {} };
|
|
1654
|
+
if (signed.cookies) {
|
|
1655
|
+
headers["Cookie"] = signed.cookies;
|
|
1656
|
+
}
|
|
1657
|
+
const resp = await fetch(signed.signed_url, { headers, redirect: "follow" });
|
|
1658
|
+
const text = await resp.text();
|
|
1659
|
+
try {
|
|
1660
|
+
return JSON.parse(text);
|
|
1661
|
+
} catch {
|
|
1662
|
+
return null;
|
|
1663
|
+
}
|
|
1664
|
+
}
|
|
1630
1665
|
export {
|
|
1631
1666
|
TikTokCaptions,
|
|
1632
1667
|
TikTokLive,
|
|
1668
|
+
fetchFeed,
|
|
1669
|
+
getLiveFeed,
|
|
1633
1670
|
getRanklist,
|
|
1634
1671
|
getRegionalRanklist
|
|
1635
1672
|
};
|