forked from yydfys/CatPawOpen
-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdrpyS.js
More file actions
287 lines (267 loc) · 10 KB
/
drpyS.js
File metadata and controls
287 lines (267 loc) · 10 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
import {request, post, mergeQuery} from '../../util/request.js';
import {base64Encode, md5} from '../../util/crypto-util.js';
import * as cfg from '../../index.config.js';
const sitesCache = new Map();
// const SKEY = md5('nodejs_drpyS');
const SKEY = md5('4');
const API = cfg.default.drpyS.home_site;
sitesCache.set(SKEY, {
api: API,
extend: '',
});
function getSiteUrl(skeyHash) {
const site = sitesCache.get(skeyHash);
let url = site.api;
if (site.extend) {
url = mergeQuery(url, {extend: site.extend});
}
return url
}
function updateSiteMap(sites) {
sites.forEach((site) => {
let skeyHash = md5(site.key);
sitesCache.set(skeyHash, Object.assign(sitesCache.get(skeyHash) || {}, {
api: site.ext.api,
extend: site.ext.extend,
}));
});
}
async function support(_inReq, _outResp) {
// const clip = inReq.body.clip;
const prefix = _inReq.server.prefix;
const skey = prefix.slice(prefix.lastIndexOf('/') + 1);
if (skey === 'push') {
return 'true';
}
return 'false'
}
async function init(_inReq, _outResp) {
const {ext, skey, stype} = _inReq.body;
const skeyHash = md5(skey);
console.log('ext:', ext);
console.log('skey:', skey);
console.log('stype:', stype);
if (sitesCache.has(skeyHash)) {
const cached = sitesCache.get(skeyHash);
console.log('已储存:', cached);
return cached
}
const storeSites = {
api: ext.api,
extend: ext.ext,
}
sitesCache.set(skeyHash, storeSites);
console.log('未储存:', storeSites);
return storeSites
}
async function home(_inReq, _outResp) {
const prefix = _inReq.server.prefix;
const skeyHash = md5(prefix.slice(prefix.lastIndexOf('/') + 1));
let url = getSiteUrl(skeyHash);
const result = await request(url);
const site = sitesCache.get(skeyHash);
if (result.list.length > 0 && Array.isArray(result['class'])) {
site['home_videos'] = result.list;
result['class'].unshift({"type_name": "推荐", "type_id": "dsHome"},)
}
sitesCache.set(skeyHash, site);
return result
}
async function category(_inReq, _outResp) {
const prefix = _inReq.server.prefix;
const skeyHash = md5(prefix.slice(prefix.lastIndexOf('/') + 1));
let url = getSiteUrl(skeyHash);
const tid = _inReq.body.id;
const pg = _inReq.body.page || 1;
if (tid === 'dsHome') {
if (pg === 1) {
const site = sitesCache.get(skeyHash);
return {list: site['home_videos']}
} else {
return {list: []}
}
}
const filters = _inReq.body.filters || {};
let ext = undefined;
if (Object.keys(filters).length > 0) {
ext = base64Encode(JSON.stringify(filters));
}
const query = {
ac: 'list',
t: tid,
pg: pg,
ext: ext,
}
url = mergeQuery(url, query);
const result = await request(url);
return result;
}
async function detail(_inReq, _outResp) {
const prefix = _inReq.server.prefix;
const skeyHash = md5(prefix.slice(prefix.lastIndexOf('/') + 1));
let url = getSiteUrl(skeyHash);
const ids = !Array.isArray(_inReq.body.id) ? [_inReq.body.id] : _inReq.body.id;
const query = {ac: 'detail', ids: ids.join(',')};
url = mergeQuery(url, query);
const result = await request(url);
// const data = {ac: 'detail', ids: ids.join(',')};
// const result = await post(url, data);
if (result.list && Array.isArray(result.list)) {
const vod_play_url = result.list[0].vod_play_url;
// 手动处理push:// 调用push_agent
if (vod_play_url && vod_play_url.includes('push://')) {
console.log('vod_play_url:', vod_play_url);
let vod_play_urls = [];
let vod_play_froms = result.list[0].vod_play_from.split('$$$');
let vod_play_arr = vod_play_url.split('$$$');
for (let i in vod_play_arr) {
const play_url = vod_play_url[i];
if (play_url.includes('push://')) {
const tab_urls = play_url.split('#');
let _vod_play_urls = [];
for (const tab_url of tab_urls) {
let _title = tab_url.split('$')[0];
let vod_url = tab_url.split('$')[1];
if (vod_url && vod_url.startsWith('push://')) {
let _ids = vod_url.slice(7);
let _url = getSiteUrl(md5('push_agent'));
// let _data = {ac: 'detail', ids: _ids};
// let _result = await post(_url, _data);
const _query = {ac: 'detail', ids: _ids};
_url = mergeQuery(_url, _query);
const _result = await request(_url);
if (_result && Array.isArray(_result.list)) {
let _vod_play_url = _result.list[0].vod_play_url;
vod_play_froms[i] = _result.list[0].vod_play_from;
_vod_play_urls = _vod_play_urls.concat(_vod_play_url.split('#').map(i => i.replace('$', '$push://')).join('#'));
}
} else {
_vod_play_urls.push(tab_url)
}
}
vod_play_urls.push(_vod_play_urls.join('#'));
} else {
vod_play_urls.push(play_url)
}
}
result.list[0].vod_play_url = vod_play_urls.join('$$$');
result.list[0].vod_play_from = vod_play_froms.join('$$$');
}
}
return result;
}
async function play(_inReq, _outResp) {
const prefix = _inReq.server.prefix;
const skeyHash = md5(prefix.slice(prefix.lastIndexOf('/') + 1));
let url = getSiteUrl(skeyHash);
let id = _inReq.body.id;
if (id && id.startsWith('push://')) {
url = getSiteUrl(md5('push_agent'));
id = id.slice(7);
}
const flag = _inReq.body.flag;
const flags = _inReq.body.flags;
const query = {play: `${id}`, flag: flag};
url = mergeQuery(url, query);
const result = await request(url);
return result;
}
async function search(_inReq, _outResp) {
const prefix = _inReq.server.prefix;
const skeyHash = md5(prefix.slice(prefix.lastIndexOf('/') + 1));
let url = getSiteUrl(skeyHash);
const wd = _inReq.body.wd;
const pg = Number(_inReq.body.page) || 1;
const quick = _inReq.body.quick || undefined;
const query = {wd: wd, pg: pg, quick: quick};
url = mergeQuery(url, query);
const result = await request(url);
return result;
}
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 = {};
const skey = prefix.slice(prefix.lastIndexOf('/') + 1);
let resp = await _inReq.server.inject().post(`${prefix}/init`).payload({
ext: {api: API, extend: ''}, skey, stype: 4
});
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: 'drpyS',
name: '道长DS',
type: 7,
},
updateSiteMap,
api: async (fastify) => {
fastify.post('/support', support);
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);
},
};