Skip to content

Commit 81f0b83

Browse files
committed
update:修正规则类型可以看小说
1 parent 57510cf commit 81f0b83

File tree

11 files changed

+220
-9
lines changed

11 files changed

+220
-9
lines changed

Diff for: README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
nodejs作为服务端的drpy实现。全面升级异步写法
44

5+
[本地配置接口](/config)
6+
57
## 更新记录
68

79
20241203
10+
811
1. 新增misc工具类
912
2. 新增utils工具类
1013
3. 更新atob、btoa函数逻辑
@@ -24,10 +27,10 @@ todo:
2427
2. js里的源,像一级这种异步js,里面调用未定义的函数,能否不通过函数参数传入直接注入调用
2528
3. 在源的各个函数调用的时候动态注入input、MY_URL等局部变量不影响全局。搞了半天没成功,有点难受,待解决
2629

27-
2830
写源的函数不可以使用箭头函数,箭头函数无法拿到this作用域就没法获取input和MY_URL变量
2931

3032
精简去除的库:
33+
3134
1. axios
3235
2. jsonpath
3336
3. underscore

Diff for: custom.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"sites": [
3+
{
4+
"key": "drpyS_番茄小说",
5+
"name": "番茄小说(drpyS)",
6+
"type": 4,
7+
"api": "http://127.0.0.1:5757/api/番茄小说[书]",
8+
"searchable": 1,
9+
"ext": ""
10+
},
11+
{
12+
"key": "drpyS_金牌影视",
13+
"name": "金牌影视(drpyS)",
14+
"type": 4,
15+
"api": "http://127.0.0.1:5757/api/金牌影视",
16+
"searchable": 1,
17+
"ext": ""
18+
}
19+
]
20+
}

Diff for: index.js

+40-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@ import './utils/marked.min.js';
99

1010
const fastify = Fastify({logger: true});
1111

12+
const PORT = 5757;
1213
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1314
console.log('__dirname:', __dirname);
15+
// 配置目标目录
16+
const jsDir = path.join(__dirname, 'js');
17+
console.log('jsDir:', jsDir);
18+
1419

1520
// 添加 / 接口
1621
fastify.get('/', async (request, reply) => {
@@ -53,6 +58,38 @@ fastify.get('/', async (request, reply) => {
5358
`);
5459
});
5560

61+
// 工具函数:生成 JSON 数据
62+
function generateSiteJSON() {
63+
const files = readdirSync(jsDir);
64+
const sites = files
65+
.filter((file) => file.endsWith('.js') && !file.startsWith('_')) // 筛选出不是 "_" 开头的 .js 文件
66+
.map((file) => {
67+
const baseName = path.basename(file, '.js'); // 去掉文件扩展名
68+
const key = `drpyS_${baseName}`;
69+
const name = `${baseName}(drpyS)`;
70+
const api = `http://127.0.0.1:${PORT}/api/${baseName}`;
71+
return {
72+
key,
73+
name,
74+
type: 4, // 固定值
75+
api,
76+
searchable: 1, // 固定值
77+
ext: "", // 固定为空字符串
78+
};
79+
});
80+
return { sites };
81+
}
82+
83+
// 定义接口
84+
fastify.get('/config', async (request, reply) => {
85+
try {
86+
const siteJSON = generateSiteJSON();
87+
reply.send(siteJSON);
88+
} catch (error) {
89+
reply.status(500).send({ error: 'Failed to generate site JSON', details: error.message });
90+
}
91+
});
92+
5693
// 动态加载模块并根据 query 执行不同逻辑
5794
fastify.get('/api/:module', async (request, reply) => {
5895
const moduleName = request.params.module;
@@ -124,10 +161,10 @@ fastify.get('/api/:module', async (request, reply) => {
124161
const start = async () => {
125162
try {
126163
// 监听 0.0.0.0
127-
await fastify.listen({port: 5757, host: '0.0.0.0'});
164+
await fastify.listen({port: PORT, host: '0.0.0.0'});
128165

129166
// 获取本地地址
130-
const localAddress = `http://localhost:5757`;
167+
const localAddress = `http://localhost:${PORT}`;
131168

132169
// 获取局域网地址
133170
const interfaces = os.networkInterfaces();
@@ -136,7 +173,7 @@ const start = async () => {
136173
if (!iface) continue;
137174
for (const config of iface) {
138175
if (config.family === 'IPv4' && !config.internal) {
139-
lanAddress = `http://${config.address}:5757`;
176+
lanAddress = `http://${config.address}:${PORT}`;
140177
break;
141178
}
142179
}

Diff for: js/360.js renamed to js/_360.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// js/360.js
1+
// js/_360.js
22

33
var rule = {
44
title: '标题1',

Diff for: js/fq.js renamed to js/_fq.js

File renamed without changes.

Diff for: js/qq.js renamed to js/_qq.js

File renamed without changes.

Diff for: js/test.js renamed to js/_test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// js/test.js
1+
// js/_test.js
22
console.log('加载test...')
33
globalThis.check = ()=>{
44
console.log('check...')

Diff for: js/金牌影院.js

+142
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// http://localhost:5757/api/金牌影院?ac=list&t=1&pg=1
2+
// http://localhost:5757/api/金牌影院?ac=detail&ids=/detail/131374
3+
// http://localhost:5757/api/金牌影院?wd=我的&pg=1
4+
// http://localhost:5757/api/金牌影院?play=&flag=金牌影院
5+
var rule = {
6+
类型: '影视',
7+
title: '金牌影院',
8+
desc: '金牌影院纯js版本',
9+
host: 'https://m.cfkj86.com/',
10+
homeUrl:'https://www.cfkj86.com',
11+
url: 'https://m.cfkj86.com/api/mw-movie/anonymous/video/list?pageNum=fypage&pageSize=30&sort=1&sortBy=1&type1=fyclass',
12+
searchUrl: '/api/mw-movie/anonymous/video/searchByWordPageable?keyword=**&pageNum=fypage&pageSize=12&type=false',
13+
searchable: 2,
14+
quickSearch: 0,
15+
timeout: 5000,
16+
play_parse: true,
17+
class_parse: async () => {
18+
let classes = [{
19+
type_id: '1',
20+
type_name: '电影',
21+
},{
22+
type_id: '2',
23+
type_name: '剧集',
24+
},{
25+
type_id: '3',
26+
type_name: '综艺',
27+
},{
28+
type_id: '4',
29+
type_name: '动漫',
30+
}];
31+
return {
32+
class: classes,
33+
}
34+
},
35+
预处理: async () => {
36+
return []
37+
},
38+
推荐: async () => {
39+
return []
40+
},
41+
一级: async function (tid, pg, filter, extend) {
42+
let {MY_CATE, input} = this;
43+
if (pg <= 0) pg = 1;
44+
const t = new Date().getTime()
45+
const signkey = `pageNum=${pg}&pageSize=30&sort=1&sortBy=1&type1=${tid}&key=cb808529bae6b6be45ecfab29a4889bc&t=`+t
46+
const key = CryptoJS.SHA1(CryptoJS.MD5(signkey).toString()).toString()
47+
const html = JSON.parse((await req(`https://m.cfkj86.com/api/mw-movie/anonymous/video/list?pageNum=${pg}&pageSize=30&sort=1&sortBy=1&type1=${tid}`,
48+
{
49+
headers:{
50+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
51+
'Accept': 'application/json, text/plain, */*',
52+
'deviceId': misc.randUUID(),
53+
'sign': key,
54+
't': t
55+
}
56+
})).content);
57+
let d = [];
58+
const list = html.data.list
59+
list.forEach((it)=>{
60+
d.push({
61+
title: it.vodName,
62+
url: '/detail/'+it.vodId,
63+
desc: it.vodRemarks || '暂无更新',
64+
pic_url: it.vodPic,
65+
})
66+
})
67+
return setResult(d)
68+
},
69+
二级: async function (ids) {
70+
log(this)
71+
let {input} = this;
72+
const html = (await req(`${input}`)).content;
73+
const $ = pq(html)
74+
const vod = {
75+
vod_id: input,
76+
vod_name: $('h1').text().trim(),
77+
};
78+
let playFroms = [];
79+
let playUrls = [];
80+
const temp = [];
81+
let playlist=$('div.main-list-sections__BodyArea-sc-8bb7334b-2 .listitem')
82+
for (const it of playlist) {
83+
const a = $(it).find('a')[0]
84+
temp.push(a.children[0].data+'$'+a.attribs.href)
85+
}
86+
playFroms.push('不知道倾情打造');
87+
playUrls.push(temp.join('#'));
88+
vod.vod_play_from = playFroms.join('$$$');
89+
vod.vod_play_url = playUrls.join('$$$');
90+
91+
return vod
92+
},
93+
搜索: async function (wd, quick, pg) {
94+
let {input} = this
95+
const t = new Date().getTime()
96+
//keyword=你&pageNum=1&pageSize=12&type=false&key=cb808529bae6b6be45ecfab29a4889bc&t=1722904806016
97+
const signkey = 'keyword='+wd+'&pageNum='+pg+'&pageSize=12&type=false&key=cb808529bae6b6be45ecfab29a4889bc&t='+t
98+
const key = CryptoJS.SHA1(CryptoJS.MD5(signkey).toString()).toString()
99+
let html = JSON.parse((await req(`${rule.homeUrl}${input}`,
100+
{
101+
headers:{
102+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
103+
'Accept': 'application/json, text/plain, */*',
104+
'deviceId': misc.randUUID(),
105+
'sign': key,
106+
't': t
107+
}
108+
})).content);
109+
let d = [];
110+
const list = html.data.list
111+
list.forEach((it)=>{
112+
d.push({
113+
title: it.vodName,
114+
url: '/detail/'+it.vodId,
115+
desc: it.vodRemarks || '暂无更新',
116+
pic_url: it.vodPic,
117+
})
118+
})
119+
return setResult(d)
120+
},
121+
lazy: async function (flag, id, flags) {
122+
let {input} = this;
123+
const pid = input.split('/')[3]
124+
const nid = input.split('/')[5]
125+
const t = new Date().getTime()
126+
const signkey = 'id='+pid+'&nid='+nid+'&key=cb808529bae6b6be45ecfab29a4889bc&t='+t
127+
const key = CryptoJS.SHA1(CryptoJS.MD5(signkey).toString()).toString()
128+
const relurl = rule.homeUrl+'/api/mw-movie/anonymous/v1/video/episode/url?id='+pid+'&nid='+nid
129+
const html = JSON.parse((await req(relurl,
130+
{
131+
headers:{
132+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36',
133+
'Accept': 'application/json, text/plain, */*',
134+
'deviceId': misc.randUUID(),
135+
'sign': key,
136+
't': t
137+
}
138+
})).content)
139+
return {parse: 0, url: html.data.playUrl, js: ''}
140+
},
141+
};
142+

Diff for: jstest/360test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ console.log('__dirname:', __dirname);
88

99
(async () => {
1010
// 使用 __dirname 来确保正确的相对路径,避免路径出错
11-
const modulePath = path.join(__dirname, '../js/360.js');
11+
const modulePath = path.join(__dirname, '../js/_360.js');
1212

1313
try {
1414
console.log('Initializing module...');

Diff for: libs/drpyS.js

+9
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function init(filePath, refresh) {
8181
pjfh,
8282
pj,
8383
pjfa,
84+
pq,
8485
local,
8586
md5X,
8687
rsaX,
@@ -179,6 +180,9 @@ async function invokeWithInjectVars(rule, method, injectVars, args) {
179180
// 这样每次调用时,方法内部的 `this` 会指向 `injectVars`,避免了共享状态,确保数据的隔离性。
180181
let result = await method.apply(injectVars, args); // 使用 apply 临时注入 injectVars 作为上下文,并执行方法
181182
switch (injectVars['method']) {
183+
case 'class_parse':
184+
result = await homeParseAfter(result,rule.类型);
185+
break;
182186
case '一级':
183187
result = await cateParseAfter(result, args[1]);
184188
break;
@@ -328,6 +332,11 @@ async function initParse(rule) {
328332
return rule
329333
}
330334

335+
async function homeParseAfter(d, _type) {
336+
d.type = _type||'影视';
337+
return d
338+
}
339+
331340
async function cateParse(rule, tid, pg, filter, extend) {
332341
log(tid, pg, filter, extend);
333342
let url = rule.url.replaceAll('fyclass', tid);

Diff for: 对话1.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ export function sleepSync(ms) {
232232
export const deepCopy = cloneDeep
233233

234234

235-
5. js/360.js
236-
// js/360.js
235+
5. js/_360.js
236+
// js/_360.js
237237

238238
var rule = {
239239
title: '标题1',

0 commit comments

Comments
 (0)