tiktok-live-api 1.2.2 → 1.2.3
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/LICENSE +21 -21
- package/README.md +1 -1
- package/bin/demo.mjs +185 -0
- package/package.json +5 -1
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 TikTool
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 TikTool
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
package/bin/demo.mjs
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* tiktok-live-api CLI
|
|
5
|
+
* Instantly connects to a live TikTok stream and prints real-time events.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* npx tiktok-live-api auto-find a live stream
|
|
9
|
+
* npx tiktok-live-api @username connect to a specific stream
|
|
10
|
+
* npx tiktok-live-api --key YOUR_KEY use your own API key
|
|
11
|
+
*
|
|
12
|
+
* Unofficial third-party API by TikTool · https://tik.tools
|
|
13
|
+
* Not affiliated with TikTok or ByteDance.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import WebSocket from 'ws';
|
|
17
|
+
|
|
18
|
+
const WS_BASE = 'wss://api.tik.tools';
|
|
19
|
+
const DEMO_KEY = 'demo_tiktokliveapi_public_2026';
|
|
20
|
+
|
|
21
|
+
const CHANNELS = [
|
|
22
|
+
'aljazeeraenglish', 'cgtnofficial', 'france24_en',
|
|
23
|
+
'weathernewslive', 'gbnews', 'bbcnews',
|
|
24
|
+
'skynews', 'tv_asahi_news', 'abc7chicago', 'thairath_news',
|
|
25
|
+
];
|
|
26
|
+
|
|
27
|
+
// ── ANSI ───────────────────────────────────────────────────────────────
|
|
28
|
+
const R = '\x1b[0m';
|
|
29
|
+
const B = '\x1b[1m';
|
|
30
|
+
const D = '\x1b[2m';
|
|
31
|
+
const I = '\x1b[3m';
|
|
32
|
+
const C = {
|
|
33
|
+
cyan: '\x1b[38;5;80m', green: '\x1b[38;5;114m', yellow: '\x1b[38;5;222m',
|
|
34
|
+
mag: '\x1b[38;5;176m', blue: '\x1b[38;5;111m', red: '\x1b[38;5;203m',
|
|
35
|
+
gray: '\x1b[38;5;242m', white: '\x1b[38;5;252m', pink: '\x1b[38;5;218m',
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const TAG = {
|
|
39
|
+
chat: `${C.cyan}chat${R}`,
|
|
40
|
+
gift: `${C.yellow}gift${R}`,
|
|
41
|
+
like: `${C.mag}like${R}`,
|
|
42
|
+
member: `${C.green}join${R}`,
|
|
43
|
+
follow: `${C.green}follow${R}`,
|
|
44
|
+
viewer: `${C.blue}viewers${R}`,
|
|
45
|
+
share: `${C.white}share${R}`,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// ── Parse args ─────────────────────────────────────────────────────────
|
|
49
|
+
let target = '';
|
|
50
|
+
let apiKey = DEMO_KEY;
|
|
51
|
+
|
|
52
|
+
const args = process.argv.slice(2);
|
|
53
|
+
for (let i = 0; i < args.length; i++) {
|
|
54
|
+
const a = args[i];
|
|
55
|
+
if (a === '--key' || a === '-k') { apiKey = args[++i] || DEMO_KEY; }
|
|
56
|
+
else if (a === '--help' || a === '-h') { help(); process.exit(0); }
|
|
57
|
+
else if (!a.startsWith('-')) { target = a.replace(/^@/, ''); }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function help() {
|
|
61
|
+
console.log(`
|
|
62
|
+
${B}tiktok-live-api${R} ${D}Real-time TikTok Live events in your terminal${R}
|
|
63
|
+
|
|
64
|
+
${B}Usage${R}
|
|
65
|
+
${C.cyan}npx tiktok-live-api${R} ${D}auto-find a live stream${R}
|
|
66
|
+
${C.cyan}npx tiktok-live-api${R} ${C.white}@username${R} ${D}connect to a specific user${R}
|
|
67
|
+
${C.cyan}npx tiktok-live-api${R} ${C.gray}--key KEY${R} ${D}use your own API key${R}
|
|
68
|
+
|
|
69
|
+
${D}Unofficial third-party API by TikTool${R}
|
|
70
|
+
${D}https://tik.tools · Not affiliated with TikTok or ByteDance${R}
|
|
71
|
+
`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// ── WebSocket probe ────────────────────────────────────────────────────
|
|
75
|
+
function probe(uid, ms = 8000) {
|
|
76
|
+
return new Promise(resolve => {
|
|
77
|
+
const ws = new WebSocket(`${WS_BASE}?uniqueId=${uid}&apiKey=${apiKey}`);
|
|
78
|
+
const t = setTimeout(() => { ws.close(); resolve(null); }, ms);
|
|
79
|
+
ws.on('message', () => { clearTimeout(t); resolve(ws); });
|
|
80
|
+
ws.on('error', () => { clearTimeout(t); resolve(null); });
|
|
81
|
+
ws.on('close', () => { clearTimeout(t); });
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// ── Banner ─────────────────────────────────────────────────────────────
|
|
86
|
+
function banner() {
|
|
87
|
+
console.log();
|
|
88
|
+
console.log(` ${B}tiktok-live-api${R} ${D}·${R} ${D}Real-time TikTok Live events${R}`);
|
|
89
|
+
console.log(` ${D}Unofficial API by TikTool · https://tik.tools${R}`);
|
|
90
|
+
console.log();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ── Format ─────────────────────────────────────────────────────────────
|
|
94
|
+
function ts() {
|
|
95
|
+
const d = new Date();
|
|
96
|
+
return `${C.gray}${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}:${String(d.getSeconds()).padStart(2, '0')}${R}`;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function fmt(event, data) {
|
|
100
|
+
const tag = TAG[event] || `${C.gray}${event.padEnd(7)}${R}`;
|
|
101
|
+
const u = data.user?.uniqueId || '';
|
|
102
|
+
const pad = tag.length < 20 ? ' ' : ' ';
|
|
103
|
+
|
|
104
|
+
switch (event) {
|
|
105
|
+
case 'chat':
|
|
106
|
+
return `${ts()} ${tag}${pad} ${B}${u}${R} ${data.comment || ''}`;
|
|
107
|
+
case 'gift': {
|
|
108
|
+
const name = data.giftName || 'gift';
|
|
109
|
+
const n = data.repeatCount || 1;
|
|
110
|
+
const d2 = data.diamondCount || 0;
|
|
111
|
+
return `${ts()} ${tag}${pad} ${B}${u}${R} ${C.yellow}${name}${R} x${n} ${D}(${d2}💎)${R}`;
|
|
112
|
+
}
|
|
113
|
+
case 'like':
|
|
114
|
+
return `${ts()} ${tag}${pad} ${B}${u}${R} ${D}total ${(data.totalLikeCount || 0).toLocaleString()}${R}`;
|
|
115
|
+
case 'member':
|
|
116
|
+
return `${ts()} ${tag}${pad} ${C.green}${u}${R}`;
|
|
117
|
+
case 'follow':
|
|
118
|
+
return `${ts()} ${tag} ${C.green}${u}${R}`;
|
|
119
|
+
case 'viewer':
|
|
120
|
+
return `${ts()} ${tag} ${B}${(data.viewerCount || 0).toLocaleString()}${R}`;
|
|
121
|
+
case 'share':
|
|
122
|
+
return `${ts()} ${tag} ${u}`;
|
|
123
|
+
default:
|
|
124
|
+
return null; // skip noisy unknown events
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ── Main ───────────────────────────────────────────────────────────────
|
|
129
|
+
async function main() {
|
|
130
|
+
banner();
|
|
131
|
+
let ws = null, who = '';
|
|
132
|
+
|
|
133
|
+
if (target) {
|
|
134
|
+
process.stdout.write(` ${D}connecting to${R} ${B}@${target}${R} ${D}...${R}`);
|
|
135
|
+
ws = await probe(target);
|
|
136
|
+
if (ws) { who = target; console.log(` ${C.green}●${R}`); }
|
|
137
|
+
else { console.log(` ${C.red}✗${R}\n\n ${C.red}Stream not found.${R} Make sure ${B}@${target}${R} is live.\n`); process.exit(1); }
|
|
138
|
+
} else {
|
|
139
|
+
console.log(` ${D}scanning for live streams...${R}\n`);
|
|
140
|
+
for (const uid of CHANNELS) {
|
|
141
|
+
process.stdout.write(` ${C.gray}@${uid}${R}`);
|
|
142
|
+
ws = await probe(uid);
|
|
143
|
+
if (ws) { who = uid; console.log(` ${C.green}● live${R}`); break; }
|
|
144
|
+
else { console.log(` ${D}—${R}`); }
|
|
145
|
+
}
|
|
146
|
+
if (!ws) {
|
|
147
|
+
console.log(`\n ${C.red}No live streams found.${R} Try: ${C.cyan}npx tiktok-live-api @username${R}\n`);
|
|
148
|
+
console.log(` ${D}Get your own API key at${R} ${C.cyan}https://tik.tools${R}\n`);
|
|
149
|
+
process.exit(1);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
console.log();
|
|
154
|
+
console.log(` ${C.green}●${R} ${B}@${who}${R} ${D}— streaming events. Ctrl+C to stop.${R}`);
|
|
155
|
+
console.log(` ${D}${'─'.repeat(50)}${R}`);
|
|
156
|
+
console.log();
|
|
157
|
+
|
|
158
|
+
let count = 0;
|
|
159
|
+
ws.on('message', raw => {
|
|
160
|
+
try {
|
|
161
|
+
const m = JSON.parse(raw.toString());
|
|
162
|
+
const ev = m.event || 'unknown';
|
|
163
|
+
const d = m.data || m;
|
|
164
|
+
const line = fmt(ev, d);
|
|
165
|
+
if (line) { count++; console.log(` ${line}`); }
|
|
166
|
+
} catch { }
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
ws.on('close', () => {
|
|
170
|
+
console.log(`\n ${D}disconnected — ${B}${count}${R}${D} events received${R}`);
|
|
171
|
+
console.log(` ${D}Get unlimited access:${R} ${C.cyan}https://tik.tools${R}\n`);
|
|
172
|
+
process.exit(0);
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
ws.on('error', e => console.error(` ${C.red}error${R} ${e.message}`));
|
|
176
|
+
|
|
177
|
+
process.on('SIGINT', () => {
|
|
178
|
+
console.log(`\n\n ${D}stopped — ${B}${count}${R}${D} events received${R}`);
|
|
179
|
+
console.log(` ${D}Get your own key:${R} ${C.cyan}https://tik.tools${R}\n`);
|
|
180
|
+
ws.close();
|
|
181
|
+
process.exit(0);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
main().catch(e => { console.error(` ${C.red}${e.message}${R}`); process.exit(1); });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiktok-live-api",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.3",
|
|
4
4
|
"description": "Unofficial TikTok LIVE API Client — Real-time chat, gifts, viewers, battles, and AI live captions from any TikTok livestream. Managed WebSocket API with 99.9% uptime.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -12,8 +12,12 @@
|
|
|
12
12
|
"require": "./dist/index.js"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"tiktok-live-api": "./bin/demo.mjs"
|
|
17
|
+
},
|
|
15
18
|
"files": [
|
|
16
19
|
"dist",
|
|
20
|
+
"bin",
|
|
17
21
|
"README.md",
|
|
18
22
|
"LICENSE"
|
|
19
23
|
],
|