forked from yydfys/CatPawOpen
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathkkys.js
More file actions
374 lines (360 loc) · 13.1 KB
/
kkys.js
File metadata and controls
374 lines (360 loc) · 13.1 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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import req from '../../util/req.js';
import CryptoJS from 'crypto-js';
import { formatPlayUrl, randDeviceWithId, jsonParse, randStr } from '../../util/misc.js';
import dayjs from 'dayjs';
let url = 'https://api1.baibaipei.com:8899';
let device = {};
async function request(reqUrl, postData, agentSp, get) {
let ts = dayjs().valueOf().toString();
let rand = randStr(32);
let sign = CryptoJS.enc.Hex.stringify(CryptoJS.MD5('H58d2%gLbeingX*%D4Y8!C!!@G_' + ts + '_' + rand))
.toString()
.toLowerCase();
let headers = {
'user-agent': agentSp || device.ua,
};
if (reqUrl.includes('baibaipei')) {
headers['device-id'] = device.id;
headers['push-token'] = '';
headers['sign'] = sign;
headers['time'] = ts;
headers['md5'] = rand;
headers['version'] = '2.1.5';
headers['system-model'] = device.model;
headers['system-brand'] = device.brand;
headers['system-version'] = device.release;
}
if (!get) {
headers['Content-Type'] = 'application/x-www-form-urlencoded';
}
let res = await req(reqUrl, {
method: get ? 'get' : 'post',
headers: headers,
data: postData || {},
});
let content = res.data;
// console.log(content);
if (typeof content === 'string') {
var key = CryptoJS.enc.Utf8.parse('IjhHsCB2B5^#%0Ag');
var iv = CryptoJS.enc.Utf8.parse('y8_m.3rauW/>j,}.');
var src = CryptoJS.enc.Base64.parse(content);
let dst = CryptoJS.AES.decrypt({ ciphertext: src }, key, { iv: iv, padding: CryptoJS.pad.Pkcs7 });
dst = CryptoJS.enc.Utf8.stringify(dst);
// console.log(dst);
return JSON.parse(dst);
}
return content;
}
async function init(inReq, _outResp) {
const deviceKey = inReq.server.prefix + '/device';
device = await inReq.server.db.getObjectDefault(deviceKey, {});
if (!device.id) {
device = randDeviceWithId(33);
device.id = device.id.toLowerCase();
device.ua = 'okhttp/4.1.0';
await inReq.server.db.push(deviceKey, device);
}
return {};
}
async function home(_inReq, _outResp) {
let data = (await request(url + '/api.php/Index/getTopVideoCategory')).data;
let classes = [];
let filterObj = {};
for (const type of data) {
let typeName = type.nav_name;
if (typeName == '推荐') continue;
let typeId = type.nav_type_id.toString();
classes.push({
type_id: typeId,
type_name: typeName,
});
try {
let filterAll = [];
let filterData = (await request(url + '/api.php/Video/getFilterType', { type: typeId })).data;
for (let key of Object.keys(filterData)) {
let itemValues = filterData[key];
if (key === 'plot') key = 'class';
let typeExtendName = '';
switch (key) {
case 'class':
typeExtendName = '类型';
break;
case 'area':
typeExtendName = '地区';
break;
case 'lang':
typeExtendName = '语言';
break;
case 'year':
typeExtendName = '年代';
break;
case 'sort':
typeExtendName = '排序';
break;
}
if (typeExtendName.length === 0) continue;
let newTypeExtend = {
key: key,
name: typeExtendName,
};
let newTypeExtendKV = [];
for (let j = 0; j < itemValues.length; j++) {
const name = itemValues[j];
let value = key === 'sort' ? j + '' : name === '全部' ? '0' : name;
newTypeExtendKV.push({ n: name, v: value });
}
newTypeExtend['init'] = key === 'sort' ? '1' : newTypeExtendKV[0]['v'];
newTypeExtend.value = newTypeExtendKV;
filterAll.push(newTypeExtend);
}
if (filterAll.length > 0) {
filterObj[typeId] = filterAll;
}
} catch (e) {
console.log(e);
}
}
return {
class: classes,
filters: filterObj,
};
}
async function category(inReq, _outResp) {
const tid = inReq.body.id;
const pg = inReq.body.page;
const extend = inReq.body.filters;
let page = pg || 1;
if (page == 0) page = 1;
let reqUrl = url + '/api.php/Video/getFilterVideoList';
var formData = {
type: tid,
p: page.toString(),
area: extend.area | 0,
year: extend.year | 0,
sort: extend.sort | 0,
class: extend.class | 0,
};
// console.log(formData);
let data = (await request(reqUrl, formData)).data;
let videos = [];
for (const vod of data.data) {
videos.push({
vod_id: vod.vod_id,
vod_name: vod.vod_name,
vod_pic: vod.vod_pic,
vod_remarks: vod.vod_remarks || vod.vod_score || '',
});
}
return {
page: parseInt(data.current_page),
pagecount: parseInt(data.last_page),
limit: parseInt(data.per_page),
total: parseInt(data.total),
list: videos,
};
}
async function detail(inReq, _outResp) {
const ids = !Array.isArray(inReq.body.id) ? [inReq.body.id] : inReq.body.id;
const videos = [];
for (const id of ids) {
let data = (await request(url + '/api.php/Video/getVideoInfo', { video_id: id })).data.video;
let vod = {
vod_id: data.vod_id,
vod_name: data.vod_name,
vod_pic: data.vod_pic,
type_name: data.vod_class,
vod_year: data.vod_year,
vod_area: data.vod_area,
vod_remarks: data.vod_remarks || '',
vod_actor: data.vod_actor,
vod_director: data.vod_director,
vod_content: data.vod_content.trim(),
};
let playlist = {};
for (const item of data.vod_play) {
let from = item.playerForm;
if (from === 'jp') continue;
if (from === 'xg') continue;
let urls = [];
for (const u of item.url) {
urls.push(formatPlayUrl(vod.vod_name, u.title) + '$' + u.play_url);
}
if (!playlist.hasOwnProperty(from) && urls.length > 0) {
playlist[from] = urls;
}
}
parse = data.parse || [];
vod.vod_play_from = Object.keys(playlist).join('$$$');
let urls = Object.values(playlist);
let vod_play_url = [];
for (const urlist of urls) {
vod_play_url.push(urlist.join('#'));
}
vod.vod_play_url = vod_play_url.join('$$$');
videos.push(vod);
}
return {
list: videos,
};
}
var parse = [];
async function play(inReq, _outResp) {
const id = inReq.body.id;
try {
if (id.indexOf('youku') >= 0 || id.indexOf('iqiyi') >= 0 || id.indexOf('v.qq.com') >= 0 || id.indexOf('pptv') >= 0 || id.indexOf('le.com') >= 0 || id.indexOf('1905.com') >= 0 || id.indexOf('mgtv') >= 0) {
if (parse.length > 0) {
for (let index = 0; index < parse.length; index++) {
try {
const p = parse[index];
let res = await req.get(p + id, {
headers: { 'user-agent': 'okhttp/4.1.0' },
});
var jj = res.data.replace('User - Agent', 'User-Agent');
if (!jj.url && jj.data && jj.data.url) {
jj = jj.data;
}
var result = jsonParse(id, jj);
if (result.url) {
result.parse = 0;
if (result.header) {
Object.keys(result.header).forEach((hk) => {
if (!result.header[hk]) delete result.header[hk];
});
}
return result;
}
} catch (error) {}
}
}
}
if (id.indexOf('jqq-') >= 0) {
var jqqHeader = await request(url + '/jqqheader.json', null, null, true);
var jqqHeaders = jqqHeader;
var ids = id.split('-');
var jxJqq = await req.get('https://api.juquanquanapp.com/app/drama/detail?dramaId=' + ids[1] + '&episodeSid=' + ids[2] + '&quality=LD', { headers: jqqHeaders });
var jqqInfo = jxJqq.content;
if (jqqInfo.data.playInfo.url) {
return {
parse: 0,
playUrl: '',
url: jqqInfo.data.playInfo.url,
};
}
}
let res = await request(url + '/video.php', { url: id });
var result = jsonParse(id, res.data);
if (result.url) {
result.parse = 0;
return result;
}
} catch (e) {
console.log(e);
}
return {
parse: 0,
url: id,
};
}
async function search(inReq, _outResp) {
const pg = inReq.body.page;
const wd = inReq.body.wd;
let page = pg || 1;
if (page == 0) page = 1;
let data = (await request(url + '/api.php/Search/getSearch', { key: wd, type_id: 0, p: page })).data;
let videos = [];
for (const vod of data.data) {
videos.push({
vod_id: vod.vod_id,
vod_name: vod.vod_name,
vod_pic: vod.vod_pic,
vod_remarks: vod.vod_remarks || vod.vod_score || '',
});
}
return {
list: videos,
page: data.current_page,
pagecount: data.last_page,
};
}
async function test(inReq, outResp) {
try {
const printErr = function (json) {
if (json.statusCode && json.statusCode == 500) {
console.error(json);
}
};
const prefix = inReq.server.prefix;
const dataResult = {};
let resp = await inReq.server.inject().post(`${prefix}/init`);
dataResult.init = resp.json();
printErr(resp.json());
resp = await inReq.server.inject().post(`${prefix}/home`);
dataResult.home = resp.json();
printErr(resp.json());
if (dataResult.home.class.length > 0) {
resp = await inReq.server.inject().post(`${prefix}/category`).payload({
id: dataResult.home.class[0].type_id,
page: 1,
filter: true,
filters: {},
});
dataResult.category = resp.json();
printErr(resp.json());
if (dataResult.category.list.length > 0) {
resp = await inReq.server.inject().post(`${prefix}/detail`).payload({
id: dataResult.category.list[0].vod_id, // dataResult.category.list.map((v) => v.vod_id),
});
dataResult.detail = resp.json();
printErr(resp.json());
if (dataResult.detail.list && dataResult.detail.list.length > 0) {
dataResult.play = [];
for (const vod of dataResult.detail.list) {
const flags = vod.vod_play_from.split('$$$');
const ids = vod.vod_play_url.split('$$$');
for (let j = 0; j < flags.length; j++) {
const flag = flags[j];
const urls = ids[j].split('#');
for (let i = 0; i < urls.length && i < 2; i++) {
resp = await inReq.server
.inject()
.post(`${prefix}/play`)
.payload({
flag: flag,
id: urls[i].split('$')[1],
});
dataResult.play.push(resp.json());
}
}
}
}
}
}
resp = await inReq.server.inject().post(`${prefix}/search`).payload({
wd: '爱',
page: 1,
});
dataResult.search = resp.json();
printErr(resp.json());
return dataResult;
} catch (err) {
console.error(err);
outResp.code(500);
return { err: err.message, tip: 'check debug console output' };
}
}
export default {
meta: {
key: 'kkys',
name: '快看影视',
type: 3,
},
api: async (fastify) => {
fastify.post('/init', init);
fastify.post('/home', home);
fastify.post('/category', category);
fastify.post('/detail', detail);
fastify.post('/play', play);
fastify.post('/search', search);
fastify.get('/test', test);
},
};