-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallinone.js
More file actions
349 lines (293 loc) · 13 KB
/
allinone.js
File metadata and controls
349 lines (293 loc) · 13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
function main(item) {
const url = item.url;
const type = ku9.getQuery(url, "type") || ku9.getQuery(url, "id") ? "fjdn" : "bst"; // 默认类型
const id = ku9.getQuery(url, "id");
switch(type) {
case "bst":
return bstHandler(id);
case "cwjd":
return cwjdHandler();
case "fjdn":
return fjdnHandler(id);
case "hbgd":
return hbgdHandler(id);
case "pt":
return ptHandler(id);
default:
return JSON.stringify({error: "未知的类型参数"});
}
}
// 1. 百视通BST功能
function bstHandler(id) {
id = id || "165";
const cacheKey = "bst_" + ku9.md5(id);
const ttl = 300000;
const cachedData = ku9.getCache(cacheKey);
if (cachedData) {
const data = JSON.parse(cachedData);
if (Date.now() - data.timestamp < ttl && data.playUrl) {
return processM3U8(data.playUrl);
}
}
let clientInfo = ku9.getCache("bst_client") ? JSON.parse(ku9.getCache("bst_client")) : {timestamp: 0, clientID: ""};
if (!clientInfo.clientID || Date.now() - clientInfo.timestamp >= ttl) {
const timestamp = Math.floor(Date.now() / 1000);
const salt = "557f1d838112de4fc349b8558781fe17";
const deviceId = generateDeviceId();
const param = `deviceid=${deviceId}&market=coocaa×tamp=${timestamp}&version=1.2305.0713`;
const signature = ku9.md5(param + salt);
const firstUrl = `https://kylinapi.bbtv.cn/5g/v1/client-id-by-region?${param}&signature=${signature}`;
const firstJson = ku9.get(firstUrl, {
'Content-Type': 'application/x-www-form-urlencoded',
'User-Agent': 'SDK/1.0.0/coocaa//'
});
try {
const data = JSON.parse(firstJson);
if (data.clientID) {
clientInfo = {
timestamp: timestamp * 1000,
clientID: data.clientID
};
ku9.setCache("bst_client", JSON.stringify(clientInfo), ttl);
}
} catch (e) {
return JSON.stringify({error: "解析clientID失败"});
}
}
if (!clientInfo.clientID) {
return JSON.stringify({error: "无法获取clientID"});
}
const timestamp = Math.floor(Date.now() / 1000);
const secondUrl = `https://kylinapi.bbtv.cn/5g/v1/tv/now/${id}?client=${clientInfo.clientID}`;
const secondJson = ku9.get(secondUrl, {
'Content-Type': 'application/x-www-form-urlencoded',
'app': 'android',
'release': '1',
'channel': 'standard',
'version': '1.2305.0713',
'timestamp': timestamp.toString(),
'User-Agent': 'SDK/1.0.0/coocaa//',
'sign': ku9.md5(timestamp + "557f1d838112de4fc349b8558781fe17")
});
try {
const data = JSON.parse(secondJson);
const playUrl = data.playUrl;
if (playUrl) {
ku9.setCache(cacheKey, JSON.stringify({
timestamp: Date.now(),
playUrl: playUrl
}), ttl);
return processM3U8(playUrl);
}
} catch (e) {
return JSON.stringify({error: "解析播放地址失败"});
}
return JSON.stringify({error: "无法获取播放地址"});
}
// 2. 长威基地CWJD功能
function cwjdHandler() {
const cacheKey = "cwjd_hd";
const ttl = 600000;
const cachedUrl = ku9.getCache(cacheKey);
if (cachedUrl) {
return JSON.stringify({url: cachedUrl});
}
try {
const firstSign = generateSign('/v1/resourceProductRightsAuth', true);
const resp1 = ku9.post(
'https://saleservice.5gtv.com.cn/v1/resourceProductRightsAuth',
getCommonHeaders().concat([
'sign: ' + firstSign,
'Host: saleservice.5gtv.com.cn',
'Content-Type: application/json'
]),
JSON.stringify({resId: '30167', resourceStreamId: '30167'})
);
const json1 = JSON.parse(resp1);
const firstUrl = json1.data.url + '&t=1&v=203';
const uri = ku9.Uri(firstUrl);
const pathWithQuery = uri.FullPath;
const secondSign = generateSign(pathWithQuery, true);
const resp2 = ku9.get(firstUrl, getCommonHeaders().concat([
'sign: ' + secondSign,
'Host: live-dispatcher.5gtv.com.cn'
]));
const json2 = JSON.parse(resp2);
const playUrl = json2.data.url;
ku9.setCache(cacheKey, playUrl, ttl);
return JSON.stringify({url: playUrl});
} catch (e) {
return JSON.stringify({error: "无法获取播放地址"});
}
}
// 3. 福建电信FJDN功能
function fjdnHandler(id) {
if (!id) {
return JSON.stringify({error: "错误:缺少节目ID参数"});
}
try {
const currentTimestamp = Math.floor(Date.now() / 1000);
const nonce = Math.floor(1000000000 + Math.random() * 9000000000);
const url = `http://portal.setvn.com:8080/PortalServer-App/new/aaa_aut_aut002?appId=FuJianShengWang&authType=0&cid=20&d=c5d6b4ae6492b1b455e730567112ce5a&hmac=6ce3e31d4d&l=EJbaFsNCT7QZ1ciU7DGwmA%3D%3D&n=${id}&nonce=${nonce}&p=6&plocation=EJbaFsNCT7QZ1ciU7DGwmA%3D%3D&pserialNumber=c5d6b4ae6492b1b455e730567112ce5a&pserverAddress=portal.setvn.com&ptoken=c5d6b4ae6492b1b455e730567112ce5a&puser=freeuser&pversion=0.5.15&sscert=true&t=c5d6b4ae6492b1b455e730567112ce5a×tamp=${currentTimestamp}&u=freeuser&v=2`;
const data = ku9.get(url, [
'X-FORWARDED-FOR: 127.0.0.1',
'CLIENT-IP: 127.0.0.1'
]);
if (!data) {
return JSON.stringify({error: "错误:API未返回数据"});
}
const match = data.match(/aaa?(.*?)&ip/);
if (!match || !match[1]) {
return JSON.stringify({error: "无法解析令牌"});
}
const liveUrl = `http://rdt.setvn.com:8060/live/${id}.m3u8?${match[1]}`;
return JSON.stringify({url: liveUrl});
} catch (e) {
return JSON.stringify({error: "获取播放地址失败"});
}
}
// 4. 湖北广电H BGD功能
function hbgdHandler(id) {
id = id || "cctv1hd";
const channelList = {
'cctv1hd': 'http://live1.hrtn.net/live/cctv1hd_3000.m3u8',
'cctv2hd': 'http://live1.hrtn.net/live/cctv2hd_3000.m3u8',
'cctv3hd': 'http://live1.hrtn.net/live/cctv3hd_3000.m3u8',
'cctv4': 'http://live1.hrtn.net/live/cctv4_1000.m3u8',
'cctv5hd': 'http://live1.hrtn.net/live/cctv5hd_3000.m3u8',
'cctv6hd': 'http://live1.hrtn.net/live/cctv6hd_3000.m3u8',
'cctv7hd': 'http://live1.hrtn.net/live/cctv7hd_3000.m3u8',
'cctv8hd': 'http://live1.hrtn.net/live/cctv8hd_3000.m3u8',
'cctv9hd': 'http://live1.hrtn.net/live/cctv9hd_3000.m3u8',
'cctv10hd': 'http://live1.hrtn.net/live/cctv10hd_3000.m3u8',
'cctv11': 'http://live1.hrtn.net/live/cctv11_1000.m3u8',
'cctv12hd': 'http://live1.hrtn.net/live/cctv12hd_3000.m3u8',
'cctv13': 'http://live1.hrtn.net/live/cctv13_1000.m3u8',
'cctv14hd': 'http://live1.hrtn.net/live/cctv17hd_3000.m3u8',
'cctv15': 'http://live1.hrtn.net/live/cctv14_1000.m3u8',
'cctv16hd': 'http://live1.hrtn.net/live/cctv16hd_3000.m3u8',
'cctv17hd': 'http://live1.hrtn.net/live/cctv14hd_3000.m3u8',
'hbwshd': 'http://live1.hrtn.net/live/hbwshd_3000.m3u8',
'hnwshd': 'http://live1.hrtn.net/live/hnwshd_3000.m3u8',
'zjwshd': 'http://live1.hrtn.net/live/zjwshd_3000.m3u8',
'bjwshd': 'http://live1.hrtn.net/live/bjwshd_3000.m3u8',
'jswshd': 'http://live1.hrtn.net/live/jswshd_3000.m3u8',
'sdwdhd': 'http://live1.hrtn.net/live/sdwdhd_3000.m3u8',
'henwshd': 'http://live1.hrtn.net/live/henwshd_3000.m3u8',
'scwshd': 'http://live1.hrtn.net/live/scwshd_3000.m3u8',
'jlwshd': 'http://live1.hrtn.net/live/jlwshd_3000.m3u8',
'lnwshd': 'http://live1.hrtn.net/live/lnwshd_3000.m3u8',
'gdwshd': 'http://live1.hrtn.net/live/gdwshd_3000.m3u8',
'szwshd': 'http://live1.hrtn.net/live/szwshd_3000.m3u8',
'cqwshd': 'http://live1.hrtn.net/live/cqwshd_3000.m3u8',
'gxwshd': 'http://live1.hrtn.net/live/gxwshd_3000.m3u8',
'jxwshd': 'http://live1.hrtn.net/live/jxwshd_3000.m3u8',
'tjwshd': 'http://live1.hrtn.net/live/tjwshd_3000.m3u8'
};
const inputUrl = channelList[id];
if (!inputUrl) {
return JSON.stringify({error: "频道不存在"});
}
const authedUrl = generateAuthUrl(inputUrl, Date.now());
return JSON.stringify({url: authedUrl});
}
// 5. 平潭广播PT功能
function ptHandler(id) {
id = (id || '4').replace(/[^0-9]/g, '');
try {
const tm = Math.floor(Date.now() / 1000);
const sign = ku9.md5(`f33ba15effa5c10e873bf3842afb46a6&YWFkZDYwMjNkNzMzNzUwZWJjYjE4NWFjZjY3YmQyYzE=&1.0.0&${tm}`);
const headers = {
"X-API-KEY": "f33ba15effa5c10e873bf3842afb46a6",
"X-API-TIMESTAMP": tm.toString(),
"X-API-VERSION": "1.0.0",
"X-AUTH-TYPE": "md5",
"X-API-SIGNATURE": sign,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
};
const url = `https://www.ptbtv.com/m2o/channel/channel_info.php?channel_id=${id}`;
const response = ku9.get(url, headers);
const jsonData = JSON.parse(response);
if (!jsonData || !jsonData[0] || !jsonData[0].m3u8) {
return JSON.stringify({error: "无法获取播放地址"});
}
const playUrl = jsonData[0].m3u8;
return JSON.stringify({url: playUrl});
} catch (e) {
return JSON.stringify({error: "获取播放地址失败"});
}
}
// 通用工具函数
function generateDeviceId() {
const hex = 'xxxxxxxxxxxx4xxxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16).toUpperCase();
});
return 'COOCAA_' + hex.substr(0,8) + '-' + hex.substr(8,4) + '-' + hex.substr(12,4) + '-' + hex.substr(16,4) + '-' + hex.substr(20,12);
}
function processM3U8(playUrl) {
const m3u8Content = ku9.get(playUrl, {
'Accept': '*/*',
'User-Agent': 'BesTV Media Player 1.0'
});
if (!m3u8Content) {
return JSON.stringify({error: "无法获取M3U8内容"});
}
const urlObj = ku9.Uri(playUrl);
const basePath = urlObj.Path.substring(0, urlObj.Path.lastIndexOf('/') + 1);
const baseUrl = `${urlObj.Scheme}://${urlObj.Host}${basePath}`;
const realM3u8Body = m3u8Content.replace(/((?i).*?\.ts)/g, function(match) {
return baseUrl + match;
});
return JSON.stringify({m3u8: realM3u8Body});
}
function getCommonHeaders() {
const deviceId = ku9.md5(Date.now().toString());
return [
'charset: UTF-8',
'channelId: cbn',
'deviceType: 2048',
'releaseVersion: 2.0.3',
'releaseVersionCode: 203',
'uId: ',
'os: Android',
"deviceId: " + deviceId,
'API-VERSION: 2',
'orgCode: ',
'token: ',
'isGd: ',
'User-Agent: okhttp/3.14.9',
'Accept: */*',
'Connection: keep-alive'
];
}
function generateSign(input, flag) {
const ts = Math.floor(Date.now() / 1000);
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
let randStr = '';
const randLen = Math.max(4, Math.floor(Math.random() * 8));
for (let i = 0; i < randLen; i++) {
randStr += charset[Math.floor(Math.random() * charset.length)];
}
const suffix = flag ? '01234ibcp9' : '0123456789';
const s1 = `${input}-${ts}-${randStr}-${suffix}`;
const hexMd5 = ku9.md5(s1);
return `${ts}-${randStr}-${hexMd5}`;
}
function generateAuthUrl(url, timestampMs) {
const expirationTs = Math.floor(timestampMs / 1000) + 172800;
const urlObj = ku9.Uri(url);
const path = urlObj.Path || "/";
const randomUuidHex = 'xxxxxxxxxxxx4xxxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
const r = Math.random() * 16 | 0;
const v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
const salt = "kK6QfSCS2X";
const stringToSign = `${path}-${expirationTs}-${randomUuidHex}-0-${salt}`;
const md5Hash = ku9.md5(stringToSign);
const authKey = `${expirationTs}-${randomUuidHex}-0-${md5Hash}`;
const separator = urlObj.Query ? '&' : '?';
return url + separator + 'auth_key=' + authKey;
}