This commit is contained in:
2026-04-16 15:19:48 +08:00
commit 1c892259a9
127 changed files with 17390 additions and 0 deletions
+80
View File
@@ -0,0 +1,80 @@
const fs = require('fs');
const path = require('path');
const sqlite3 = require('node:sqlite');
const https = require('https');
const sign = require(path.join(process.argv[2], 'index.js'));
const db = new sqlite3.DatabaseSync(process.argv[3]);
const rows = db.prepare("select Key, Value from AppSettings where Key in ('douyin.cookie','douyin.user_agent')").all();
const settings = Object.fromEntries(rows.map(r => [r.Key, r.Value]));
const webRid = '24482384478';
function request(url, headers) {
return new Promise((resolve, reject) => {
https.get(url, { headers }, res => {
const chunks = [];
res.on('data', chunk => chunks.push(chunk));
res.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
}).on('error', reject);
});
}
(async () => {
const headers = {
'user-agent': settings['douyin.user_agent'] || 'Mozilla/5.0',
'referer': `https://live.douyin.com/${webRid}`,
'origin': 'https://live.douyin.com',
'cookie': settings['douyin.cookie'] || ''
};
const html = await request(`https://live.douyin.com/${webRid}`, headers);
const match = html.match(/<script\snonce="\S+?"\s>self\.__pace_f\.push\(\[1,"[a-z]?:\[\\"\$\\",\\"\$L\d+\\",null,([\s\S]+?state[\s\S]+?)\]\\n"\]\)<\/script>/);
const json = match ? match[1].replace(/\\{1,7}"/g, '"') : '';
const roomId = (json.match(/\"roomId\":\"(\d+)\"/) || [])[1];
const uniqueId = '7300000000000000000';
const msToken = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv';
const params = new URLSearchParams({
aid: '6383',
app_name: 'douyin_web',
browser_language: 'zh-CN',
browser_name: 'Mozilla',
browser_online: 'true',
browser_platform: 'Win32',
browser_version: settings['douyin.user_agent'] || 'Mozilla/5.0',
cookie_enabled: 'true',
cursor: '',
device_id: '',
device_platform: 'web',
did_rule: '3',
endpoint: 'live_pc',
fetch_rule: '1',
identity: 'audience',
insert_task_id: '',
internal_ext: '',
last_rtt: '0',
live_id: '1',
live_reason: '',
need_persist_msg_count: '15',
resp_content_type: 'protobuf',
screen_height: '1080',
screen_width: '1920',
support_wrds: '1',
tz_name: 'Asia/Shanghai',
version_code: '180800',
room_id: roomId,
user_unique_id: uniqueId,
live_pc: roomId,
msToken
});
const rawQuery = params.toString();
const xb = sign(`https://live.douyin.com/webcast/im/fetch/?${rawQuery}`, headers['user-agent']);
params.set('a_bogus', xb);
const url = `https://live.douyin.com/webcast/im/fetch/?${params.toString()}`;
const body = await new Promise((resolve, reject) => {
https.get(url, { headers: { ...headers, accept: 'application/protobuf, application/octet-stream, */*' } }, res => {
const chunks = [];
res.on('data', chunk => chunks.push(chunk));
res.on('end', () => resolve(Buffer.concat(chunks)));
}).on('error', reject);
});
console.log('ROOM_ID', roomId);
console.log('A_BOGUS_LEN', xb.length);
console.log('RESP_LEN', body.length);
console.log('RESP_HEAD', Array.from(body.subarray(0, 48)));
})();