Skip to content

Commit 1cb86fd

Browse files
author
Taois
committed
feat:优化map.txt,修改后立即生效,无需重启ds服务
1 parent 8061fff commit 1cb86fd

File tree

6 files changed

+161
-46
lines changed

6 files changed

+161
-46
lines changed

config/map.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,5 @@ AppHs@@{"host":"https://dy.jmzp.net.cn","app_id":"shiguang","deviceid":"","versi
5757
AppHs@@{"host":"https://dy.jszdzs.com","app_id":"xuebao","deviceid":"","versionCode":"21300","UMENG_CHANNEL":"share"}@@雪豹视频[Hs]
5858
AppHs@@{"host":"https://dy.stxbed.com","app_id":"haigou","deviceid":"","versionCode":"20100","UMENG_CHANNEL":"zhuan"}@@海狗视频[Hs]
5959
AppYqk@@{"host":"https://gapi0320.3njzmrx1.com/config.json,https://gapi0320.lq0okex8.com/config.json,https://gapi0320.zabqs8xp.com/config.json,https://yappconfig-20250628-1318635097.cos.ap-shanghai.myqcloud.com/config.json,https://yconfig-20250628-1360051343.cos.ap-guangzhou.myqcloud.com/config.json","appId":"d6d520ea90904f1ba680ed6c9c9f9007","appkey":"70af67d2b6cf47679b397ea4c1886877","udid":"bfc18c00-c866-46cb-8d7b-121c39b942d4","bundlerId":"com.flotimingo.ts","source":"1001_default","version":"1.3.10","versionCode":1104}@@一起看[Ayq]
60-
AppYqk@@{"host":"https://gapi0725.5p8jcjc.com/config.json,https://gapi0725.olrv5gz.com/config.json,https://gapi0725.mvljeat.com/config.json,https://jzapp-1318635097.cos.ap-shanghai.myqcloud.com/config.json,https://juzi-config-1360051343.cos.ap-shanghai.myqcloud.com/config.json","appId":"fea23e11fc1241409682880e15fb2851","appkey":"f384b87cc9ef41e4842dda977bae2c7f","udid":"bfc18c00-c866-46cb-8d7b-121c39b942d4","bundlerId":"com.voraguzzee.ts","source":"1003_default","version":"1.0.1","versionCode":1000}@@橘子TV[Ayq]
60+
AppYqk@@{"host":"https://gapi0725.5p8jcjc.com/config.json,https://gapi0725.olrv5gz.com/config.json,https://gapi0725.mvljeat.com/config.json,https://jzapp-1318635097.cos.ap-shanghai.myqcloud.com/config.json,https://juzi-config-1360051343.cos.ap-shanghai.myqcloud.com/config.json","appId":"fea23e11fc1241409682880e15fb2851","appkey":"f384b87cc9ef41e4842dda977bae2c7f","udid":"bfc18c00-c866-46cb-8d7b-121c39b942d4","bundlerId":"com.voraguzzee.ts","source":"1003_default","version":"1.0.1","versionCode":1000}@@橘子TV[Ayq]
61+
php@@{"host":"https://www.baidu.com"}@@php测试

libs/drpyS.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import AIS from '../utils/ais.js';
1414
import PanS from '../utils/pans.js';
1515
import {ENV} from '../utils/env.js';
1616
import {getContentType, getMimeType} from "../utils/mime-type.js";
17-
import {getParsesDict, SitesMap, pathLib, es6_extend_code, req_extend_code} from "../utils/file.js";
17+
import {getParsesDict, getSitesMap, pathLib, es6_extend_code, req_extend_code} from "../utils/file.js";
1818
import {getFirstLetter} from "../utils/pinyin-tool.js";
1919
import {reqs} from "../utils/req.js";
2020
import "../utils/random-http-ua.js";
@@ -364,6 +364,7 @@ export async function init(filePath, env = {}, refresh) {
364364
// 计算文件的 hash 值
365365
const fileHash = computeHash(fileContent);
366366
const moduleName = path.basename(filePath, '.js');
367+
const SitesMap = getSitesMap();
367368
let moduleExt = env.ext || '';
368369
// log('moduleName:', moduleName);
369370
// log('moduleExt:', moduleExt);

libs_drpy/drpyCustom.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,4 +969,5 @@ export const stringify = JSON.stringify;
969969
globalThis.base64Encode = base64Encode;
970970
globalThis.base64Decode = base64Decode;
971971
globalThis.gzip = gzip;
972-
globalThis.ungzip = ungzip;
972+
globalThis.ungzip = ungzip;
973+
globalThis.parseQueryString = parseQueryString;

spider/js/php.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
@header({
3+
searchable: 1,
4+
filterable: 0,
5+
quickSearch: 0,
6+
title: '',
7+
'类型': '影视',
8+
lang: 'ds'
9+
})
10+
*/
11+
// php@@{"host":"https://jingyu4k-1312635929.cos.ap-nanjing.myqcloud.com/1.json"}@@php测试
12+
var rule = {
13+
类型: '影视',
14+
title: '',
15+
host: '',
16+
url: '',
17+
searchUrl: '',
18+
headers: {'User-Agent': 'UC_UA'},
19+
searchable: 1,
20+
quickSearch: 0,
21+
filterable: 0,
22+
double: true,
23+
play_parse: true,
24+
limit: 6,
25+
class_name: '电影&电视剧&动漫&短剧&综艺',
26+
class_url: '1&2&3&4&5',
27+
hostJs: async function () {
28+
let {HOST} = this;
29+
return await request(HOST);
30+
},
31+
预处理: async function () {
32+
log('rule.params:', rule.params);
33+
let extObject = JSON5.parse(rule.params);
34+
log('extObject:', extObject);
35+
},
36+
class_parse: async function () {
37+
let {input, pdfa, pdfh, pd} = this;
38+
return {}
39+
},
40+
lazy: async function () {
41+
let {input} = this;
42+
return input
43+
},
44+
推荐: async function () {
45+
let {input, pdfa, pdfh, pd} = this;
46+
let d = [];
47+
return setResult(d)
48+
},
49+
一级: async function () {
50+
let {input, pdfa, pdfh, pd} = this;
51+
let d = [];
52+
return setResult(d)
53+
},
54+
二级: async function () {
55+
let {input, pdfa, pdfh, pd} = this;
56+
let VOD = {};
57+
return VOD
58+
},
59+
搜索: async function () {
60+
let {input, pdfa, pdfh, pd} = this;
61+
let d = [];
62+
return setResult(d)
63+
}
64+
}

utils/file.js

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
11
/**
22
* 文件操作工具模块
3-
*
3+
*
44
* 功能:提供文件读写、路径处理、解析器配置等核心文件操作功能
55
* 包含安全的文件访问控制和路径解析功能
6-
*
6+
*
77
* @author drpy
88
* @version 1.0.0
99
*/
1010

1111
import path from "path";
1212
import {readFileSync, existsSync, mkdirSync, writeFileSync} from 'fs';
1313
import {fileURLToPath} from "url";
14-
import {getSitesMap} from "./sites-map.js";
1514
import '../libs_drpy/jinja.js'
1615

1716
// 获取当前模块的目录路径
1817
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1918

2019
// 定义核心路径常量
2120
const _data_path = path.join(__dirname, '../data'); // 数据文件存储路径
22-
const _config_path = path.join(__dirname, '../config'); // 配置文件路径
2321
const _lib_path = path.join(__dirname, '../spider/js'); // 库文件路径
2422

23+
export {getSitesMap} from "./sites-map.js";
2524
// ES6扩展代码路径和内容
2625
const es6JsPath = path.join(__dirname, '../libs_drpy/es6-extend.js');
2726
/**
@@ -38,62 +37,56 @@ const reqJsPath = path.join(__dirname, '../libs_drpy/req-extend.js');
3837
*/
3938
export const req_extend_code = readFileSync(reqJsPath, 'utf8');
4039

41-
/**
42-
* 站点映射配置
43-
* 从配置路径获取站点映射信息
44-
*/
45-
export const SitesMap = getSitesMap(_config_path);
46-
4740
/**
4841
* 路径操作库
4942
* 提供安全的文件读写和路径操作功能
5043
*/
5144
export const pathLib = {
5245
basename: path.basename, // 获取文件名
5346
extname: path.extname, // 获取文件扩展名
54-
47+
5548
/**
5649
* 安全读取数据文件
57-
*
50+
*
5851
* @param {string} filename - 相对于data目录的文件名
5952
* @returns {string} 文件内容,失败返回空字符串
6053
*/
6154
readFile: function (filename) {
6255
let _file_path = path.join(_data_path, filename);
6356
const resolvedPath = path.resolve(_data_path, _file_path); // 将路径解析为绝对路径
64-
57+
6558
// 安全检查:确保访问路径在允许的数据目录内
6659
if (!resolvedPath.startsWith(_data_path)) {
6760
log(`[pathLib.readFile] no access for read ${_file_path}`)
6861
return '';
6962
}
70-
63+
7164
// 检查文件是否存在
7265
if (!existsSync(resolvedPath)) {
7366
log(`[pathLib.readFile] file not found for read ${resolvedPath}`)
7467
return '';
7568
}
76-
69+
7770
return readFileSync(resolvedPath, 'utf8')
7871
},
79-
72+
8073
/**
8174
* 安全写入数据文件
82-
*
75+
*
8376
* @param {string} filename - 相对于data目录的文件名
8477
* @param {string} text - 要写入的文本内容
8578
* @returns {boolean} 写入成功返回true,失败返回false
8679
*/
8780
writeFile: function (filename, text) {
8881
let _file_path = path.join(_data_path, filename);
8982
const resolvedPath = path.resolve(_data_path, _file_path); // 将路径解析为绝对路径
90-
83+
9184
// 安全检查:确保访问路径在允许的数据目录内
9285
if (!resolvedPath.startsWith(_data_path)) {
9386
log(`[pathLib.writeFile] no access for read ${_file_path}`)
9487
return '';
9588
}
96-
89+
9790
try {
9891
const dirPath = path.dirname(resolvedPath);
9992
// 检查目录是否存在,不存在则创建
@@ -107,39 +100,39 @@ export const pathLib = {
107100
return false
108101
}
109102
},
110-
103+
111104
/**
112105
* 安全读取库文件
113-
*
106+
*
114107
* @param {string} filename - 相对于库目录的文件名
115108
* @returns {string} 文件内容,失败返回空字符串
116109
*/
117110
readLib: function (filename) {
118111
let _file_path = path.join(_lib_path, filename);
119112
const resolvedPath = path.resolve(_data_path, _file_path); // 将路径解析为绝对路径
120-
113+
121114
// 安全检查:确保访问路径在允许的库目录内
122115
if (!resolvedPath.startsWith(_lib_path)) {
123116
log(`[pathLib.readLib] no access for read ${_file_path}`)
124117
return '';
125118
}
126-
119+
127120
// 检查文件是否存在
128121
if (!existsSync(resolvedPath)) {
129122
log(`[pathLib.readLib] file not found for read ${resolvedPath}`)
130123
return '';
131124
}
132-
125+
133126
return readFileSync(resolvedPath, 'utf8')
134127
},
135128
};
136129

137130
/**
138131
* 获取解析器配置字典
139-
*
132+
*
140133
* 功能:从配置文件中读取解析器列表,支持模板变量替换
141134
* 解析parses.conf配置文件,生成解析器对象数组
142-
*
135+
*
143136
* @param {string} host - 主机地址,用于模板变量替换
144137
* @returns {Array} 解析器配置对象数组
145138
*/
@@ -148,26 +141,26 @@ export function getParsesDict(host) {
148141
const __dirname = path.dirname(__filename);
149142
const jx_conf = path.join(__dirname, '../config/parses.conf');
150143
let jx_list = [];
151-
144+
152145
// 检查解析器配置文件是否存在
153146
if (existsSync(jx_conf)) {
154147
const jx_conf_text = readFileSync(jx_conf, 'utf-8');
155148
let jx_conf_content = jx_conf_text.trim();
156-
149+
157150
// 准备模板变量字典
158151
let var_dict = {
159-
host,
152+
host,
160153
hostName: host.split(':').length > 1 ? host.slice(0, host.lastIndexOf(":")) : host
161154
};
162-
155+
163156
// 使用Jinja模板引擎渲染配置内容
164157
jx_conf_content = jinja.render(jx_conf_content, var_dict);
165-
158+
166159
// 解析配置行:过滤空行和注释行
167160
const jxs = jx_conf_content.split('\n')
168161
.filter(it => it.trim() && !it.trim().startsWith('#'))
169162
.map(it => it.trim());
170-
163+
171164
// 处理每个解析器配置行
172165
jxs.forEach((jx) => {
173166
let jx_arr = jx.split(',');
@@ -176,7 +169,7 @@ export function getParsesDict(host) {
176169
let jx_type = jx_arr.length > 2 ? Number(jx_arr[2]) || 0 : 0; // 解析器类型
177170
let jx_ua = jx_arr.length > 3 ? jx_arr[3] : 'Mozilla/5.0'; // User-Agent
178171
let jx_flag = jx_arr.length > 4 ? jx_arr[4] : ''; // 标志位
179-
172+
180173
// 构建解析器对象
181174
let jx_obj = {
182175
'name': jx_name,
@@ -186,17 +179,17 @@ export function getParsesDict(host) {
186179
"User-Agent": jx_ua
187180
},
188181
}
189-
182+
190183
// 如果有标志位,添加扩展配置
191184
if (jx_flag) {
192185
jx_obj.ext = {
193186
"flag": jx_flag.split('|')
194187
}
195188
}
196-
189+
197190
jx_list.push(jx_obj);
198191
});
199192
}
200-
193+
201194
return jx_list
202195
}

0 commit comments

Comments
 (0)