drpy.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447
  1. import './lib/util.js';
  2. import cheerio from 'assets://js/lib/cheerio.min.js';
  3. import 'assets://js/lib/crypto-js.js'
  4. // import muban from 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js';
  5. // const key = 'drpy_zbk';
  6. // eval(req('http://192.168.1.124:5705/libs/es6py.js').content);
  7. function init_test() {
  8. console.log("init_test_start");
  9. console.log(RKEY);
  10. console.log(JSON.stringify(rule));
  11. // clearItem(RULE_CK);
  12. // console.log(JSON.stringify(rule));
  13. // let aa = base64Encode('编码测试一下')
  14. // log(aa);
  15. // let bb = base64Decode(aa);
  16. // log('bb:' + bb);
  17. // console.log(request('https://www.baidu.com',{withHeaders:true}));
  18. // console.log(request('https://www.baidu.com/favicon.ico', { toBase64: true }));
  19. // require('http://192.168.10.99:5705/txt/pluto/drT.js');
  20. // console.log(typeof(drT));
  21. // console.log(drT.renderText('{{fl.cate}},hi, {{fl}}哈哈.{{fl}}',{sort: 1,cate:'movie'},'fl'));
  22. console.log("init_test_end");
  23. }
  24. let rule = {};
  25. /** 已知问题记录
  26. * 1.影魔的jinjia2引擎不支持 {{fl}}对象直接渲染
  27. * Array.prototype.append = Array.prototype.push; 这种js执行后有毛病,for in 循环列表会把属性给打印出来
  28. * 2.import es6py.js但是里面的函数没有被装载进来.比如drpy规则报错setResult2 is undefiend
  29. * 3.无法重复导入cheerio(怎么解决drpy和parseTag里都需要导入cheerio的问题) 无法在副文件导入cheerio (现在是全部放在drpy一个文件里了,凑合解决?)
  30. * 4.有个错误不知道哪儿来的 executeScript: com.quickjs.JSObject$Undefined cannot be cast to java.lang.String 在 点击选集播放打印init_test_end后面打印
  31. * 5.需要实现 stringify 函数,比起JSON.stringify函数,它会原封不动保留中文不会编码unicode
  32. * todo: jsp:{pdfa,pdfh,pd},json:{pdfa,pdfh,pd},jq:{pdfa,pdfh,pd}
  33. * * 电脑看日志调试
  34. adb tcpip 5555
  35. adb connect 192.168.10.192
  36. adb devices -l
  37. adb logcat -c
  38. adb logcat | grep -i QuickJS
  39. * **/
  40. /*** 以下是内置变量和解析方法 **/
  41. const MOBILE_UA = 'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36';
  42. const PC_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36';
  43. const UA = 'Mozilla/5.0';
  44. const UC_UA = 'Mozilla/5.0 (Linux; U; Android 9; zh-CN; MI 9 Build/PKQ1.181121.001) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/57.0.2987.108 UCBrowser/12.5.5.1035 Mobile Safari/537.36';
  45. const IOS_UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1';
  46. const RULE_CK = 'cookie'; // 源cookie的key值
  47. // const KEY = typeof(key)!=='undefined'&&key?key:'drpy_' + (rule.title || rule.host); // 源的唯一标识
  48. const CATE_EXCLUDE = '首页|留言|APP|下载|资讯|新闻|动态';
  49. const TAB_EXCLUDE = '猜你|喜欢|APP|下载|剧情|热播';
  50. const OCR_RETRY = 3;//ocr验证重试次数
  51. // const OCR_API = 'http://dm.mudery.com:10000';//ocr在线识别接口
  52. // const OCR_API = 'http://192.168.3.239:5705/parse/ocr';//ocr在线识别接口
  53. const OCR_API = 'http://cms.nokia.press/parse/ocr';//ocr在线识别接口
  54. if (typeof (MY_URL) === 'undefined') {
  55. var MY_URL; // 全局注入变量,pd函数需要
  56. }
  57. var RKEY; // 源的唯一标识
  58. var fetch;
  59. var print;
  60. var log;
  61. var rule_fetch_params;
  62. var fetch_params; // 每个位置单独的
  63. var oheaders;
  64. var _pdfh;
  65. var _pdfa;
  66. var _pd;
  67. // const DOM_CHECK_ATTR = ['url', 'src', 'href', 'data-original', 'data-src'];
  68. const DOM_CHECK_ATTR = /(url|src|href|data-original|data-src)$/;
  69. const SELECT_REGEX = /:eq|:lt|:gt|#/g;
  70. const SELECT_REGEX_A = /:eq|:lt|:gt/g;
  71. function setResult(d) {
  72. if (!Array.isArray(d)) {
  73. return []
  74. }
  75. VODS = [];
  76. // print(d);
  77. d.forEach(function (it) {
  78. let obj = {
  79. vod_id: it.url || '',
  80. vod_name: it.title || '',
  81. vod_remarks: it.desc || '',
  82. vod_content: it.content || '',
  83. vod_pic: it.pic_url || it.img || '',
  84. };
  85. let keys = Object.keys(it);
  86. if (keys.includes('tname')) {
  87. obj.type_name = it.tname || '';
  88. }
  89. if (keys.includes('tid')) {
  90. obj.type_id = it.tid || '';
  91. }
  92. if (keys.includes('year')) {
  93. obj.vod_year = it.year || '';
  94. }
  95. if (keys.includes('actor')) {
  96. obj.vod_actor = it.actor || '';
  97. }
  98. if (keys.includes('director')) {
  99. obj.vod_director = it.director || '';
  100. }
  101. if (keys.includes('area')) {
  102. obj.vod_area = it.area || '';
  103. }
  104. VODS.push(obj);
  105. });
  106. return VODS
  107. }
  108. function setResult2(res) {
  109. VODS = res.list || [];
  110. return VODS
  111. }
  112. function setHomeResult(res) {
  113. if (!res || typeof (res) !== 'object') {
  114. return []
  115. }
  116. return setResult(res.list);
  117. }
  118. // 猫了个咪
  119. function rc(js) {
  120. if (js === 'maomi_aes.js') {
  121. var a = CryptoJS.enc.Utf8.parse("625222f9149e961d");
  122. var t = CryptoJS.enc.Utf8.parse("5efdtf6060e2o330");
  123. return {
  124. De: function (word) {
  125. word = CryptoJS.enc.Hex.parse(word)
  126. return CryptoJS.AES.decrypt(CryptoJS.enc.Base64.stringify(word), a, {
  127. iv: t,
  128. mode: CryptoJS.mode.CBC,
  129. padding: CryptoJS.pad.Pkcs7
  130. }).toString(CryptoJS.enc.Utf8)
  131. },
  132. En: function (word) {
  133. // print(a);
  134. // print(word);
  135. var Encrypted = CryptoJS.AES.encrypt(word, a, {
  136. iv: t,
  137. mode: CryptoJS.mode.CBC,
  138. padding: CryptoJS.pad.Pkcs7
  139. });
  140. return Encrypted.ciphertext.toString();
  141. }
  142. };
  143. }
  144. return {};
  145. }
  146. // 千万不要用for in 推荐 forEach (for in 会打乱顺序)
  147. //猫函数
  148. function maoss(jxurl, ref, key) {
  149. eval(getCryptoJS());
  150. try {
  151. var getVideoInfo = function (text) {
  152. return CryptoJS.AES.decrypt(text, key, { iv: iv, padding: CryptoJS.pad.Pkcs7 }).toString(CryptoJS.enc.Utf8);
  153. };
  154. var token_key = key == undefined ? 'dvyYRQlnPRCMdQSe' : key;
  155. if (ref) {
  156. var html = request(jxurl, {
  157. headers: {
  158. 'Referer': ref
  159. }
  160. });
  161. } else {
  162. var html = request(jxurl);
  163. }
  164. // print(html);
  165. if (html.indexOf('&btwaf=') != -1) {
  166. html = request(jxurl + '&btwaf' + html.match(/&btwaf(.*?)"/)[1], {
  167. headers: {
  168. 'Referer': ref
  169. }
  170. })
  171. }
  172. var token_iv = html.split('_token = "')[1].split('"')[0];
  173. var key = CryptoJS.enc.Utf8.parse(token_key);
  174. var iv = CryptoJS.enc.Utf8.parse(token_iv);
  175. // log("iv:"+iv);
  176. // log(html);
  177. // print(key);
  178. // print(iv);
  179. eval(html.match(/var config = {[\s\S]*?}/)[0] + '');
  180. // config.url = config.url.replace(/,/g,'');
  181. // print(config.url);
  182. if (!config.url.startsWith('http')) {
  183. //config.url = decodeURIComponent(AES(config.url, key, iv));
  184. config.url = CryptoJS.AES.decrypt(config.url, key, {
  185. iv: iv,
  186. padding: CryptoJS.pad.Pkcs7
  187. }).toString(CryptoJS.enc.Utf8)
  188. }
  189. return config.url;
  190. } catch (e) {
  191. return '';
  192. }
  193. }
  194. let VODS = [];// 一级或者搜索需要的数据列表
  195. let VOD = {};// 二级的单个数据
  196. /**
  197. * 重写pd方法-增加自动urljoin(没法重写,改个名继续骗)
  198. * @param html
  199. * @param parse
  200. * @param uri
  201. * @returns {*}
  202. */
  203. function pD(html, parse, uri) {
  204. let ret = pdfh(html, parse);
  205. if (typeof (uri) === 'undefined' || !uri) {
  206. uri = '';
  207. }
  208. if (DOM_CHECK_ATTR.test(parse)) {
  209. if (/http/.test(ret)) {
  210. ret = ret.substr(ret.indexOf('http'));
  211. } else {
  212. ret = urljoin(MY_URL, ret)
  213. }
  214. }
  215. // MY_URL = getItem('MY_URL',MY_URL);
  216. // console.log(`规则${RKEY}打印MY_URL:${MY_URL},uri:${uri}`);
  217. return ret
  218. }
  219. const parseTags = {
  220. jsp: {
  221. pdfh: pdfh,
  222. pdfa: pdfa,
  223. pd: pD,
  224. },
  225. json: {
  226. pdfh(html, parse) {
  227. if (!parse || !parse.trim()) {
  228. return '';
  229. }
  230. if (typeof (html) === 'string') {
  231. html = JSON.parse(html);
  232. }
  233. parse = parse.trim();
  234. if (!parse.startsWith('$.')) {
  235. parse = '$.' + parse;
  236. }
  237. parse = parse.split('||');
  238. for (let ps of parse) {
  239. let ret = cheerio.jp(ps, html);
  240. if (Array.isArray(ret)) {
  241. ret = ret[0] || '';
  242. } else {
  243. ret = ret || ''
  244. }
  245. if (ret && typeof (ret) !== 'string') {
  246. ret = ret.toString();
  247. }
  248. if (ret) {
  249. return ret
  250. }
  251. }
  252. return '';
  253. },
  254. pdfa(html, parse) {
  255. if (!parse || !parse.trim()) {
  256. return '';
  257. }
  258. if (typeof (html) === 'string') {
  259. html = JSON.parse(html);
  260. }
  261. parse = parse.trim()
  262. if (!parse.startsWith('$.')) {
  263. parse = '$.' + parse;
  264. }
  265. let ret = cheerio.jp(parse, html);
  266. if (Array.isArray(ret) && Array.isArray(ret[0]) && ret.length === 1) {
  267. return ret[0] || []
  268. }
  269. return ret || []
  270. },
  271. pd(html, parse) {
  272. let ret = parseTags.json.pdfh(html, parse);
  273. if (ret) {
  274. return urljoin(MY_URL, ret);
  275. }
  276. return ret
  277. },
  278. },
  279. jq: {
  280. pdfh: pdfh,
  281. pdfa: pdfa,
  282. pd(html, parse, uri) {
  283. return parseTags.jq.pdfh(html, parse, MY_URL);
  284. },
  285. },
  286. getParse(p0) {//非js开头的情况自动获取解析标签
  287. if (p0.startsWith('jsp:')) {
  288. return this.jsp
  289. } else if (p0.startsWith('json:')) {
  290. return this.json
  291. } else if (p0.startsWith('jq:')) {
  292. return this.jq
  293. } else {
  294. return this.jq
  295. }
  296. }
  297. };
  298. const stringify = JSON.stringify;
  299. const jsp = parseTags.jsp;
  300. /*** 后台需要实现的java方法并注入到js中 ***/
  301. /**
  302. * 读取本地文件->应用程序目录
  303. * @param filePath
  304. * @returns {string}
  305. */
  306. function readFile(filePath) {
  307. filePath = filePath || './uri.min.js';
  308. var fd = os.open(filePath);
  309. var buffer = new ArrayBuffer(1024);
  310. var len = os.read(fd, buffer, 0, 1024);
  311. console.log(len);
  312. let text = String.fromCharCode.apply(null, new Uint8Array(buffer));
  313. console.log(text);
  314. return text
  315. }
  316. /**
  317. * 处理返回的json数据
  318. * @param html
  319. * @returns {*}
  320. */
  321. function dealJson(html) {
  322. try {
  323. return html.match(/[\w|\W|\s|\S]*?(\{[\w|\W|\s|\S]*\})/).group[1];
  324. } catch (e) {
  325. }
  326. try {
  327. html = JSON.parse(html);
  328. } catch (e) { }
  329. // console.log(typeof(html));
  330. return html;
  331. }
  332. /**
  333. * 验证码识别逻辑,需要java实现(js没有bytes类型,无法调用后端的传递图片二进制获取验证码文本的接口)
  334. * @type {{api: string, classification: (function(*=): string)}}
  335. */
  336. var OcrApi = {
  337. api: OCR_API,
  338. classification: function (img) { // img是byte类型,这里不方便搞啊
  339. let code = '';
  340. try {
  341. let html = request(this.api, { data: { img: img }, headers: { 'User-Agent': PC_UA }, 'method': 'POST' });
  342. html = JSON.parse(html);
  343. code = html.url || '';
  344. } catch (e) { }
  345. return code
  346. }
  347. };
  348. /**
  349. * 验证码识别,暂未实现
  350. * @param url 验证码图片链接
  351. * @returns {string} 验证成功后的cookie
  352. */
  353. function verifyCode(url) {
  354. let cnt = 0;
  355. let host = getHome(url);
  356. let cookie = '';
  357. while (cnt < OCR_RETRY) {
  358. try {
  359. // let obj = {headers:headers,timeout:timeout};
  360. let yzm_url = `${host}/index.php/verify/index.html`;
  361. console.log(`验证码链接:${yzm_url}`);
  362. let hhtml = request(yzm_url, { withHeaders: true, toBase64: true });
  363. let json = JSON.parse(hhtml);
  364. if (!cookie) {
  365. cookie = json['set-cookie'] ? json['set-cookie'].split(';')[0] : '';
  366. }
  367. // console.log(hhtml);
  368. console.log('cookie:' + cookie);
  369. let img = json.body;
  370. // console.log(img);
  371. let code = OcrApi.classification(img);
  372. console.log(`第${cnt + 1}次验证码识别结果:${code}`);
  373. let submit_url = `${host}/index.php/ajax/verify_check?type=search&verify=${code}`;
  374. console.log(submit_url);
  375. let html = request(submit_url, { headers: { Cookie: cookie, 'User-Agent': MOBILE_UA }, 'method': 'POST' });
  376. // console.log(html);
  377. html = JSON.parse(html);
  378. if (html.msg === 'ok') {
  379. console.log(`第${cnt + 1}次验证码提交成功`);
  380. return cookie // 需要返回cookie
  381. } else if (html.msg !== 'ok' && cnt + 1 >= OCR_RETRY) {
  382. cookie = ''; // 需要清空返回cookie
  383. }
  384. } catch (e) {
  385. console.log(`第${cnt + 1}次验证码提交失败:${e.message}`);
  386. if (cnt + 1 >= OCR_RETRY) {
  387. cookie = '';
  388. }
  389. }
  390. cnt += 1
  391. }
  392. return cookie
  393. }
  394. /**
  395. * 存在数据库配置表里, key字段对应值value,没有就新增,有就更新,调用此方法会清除key对应的内存缓存
  396. * @param k 键
  397. * @param v 值
  398. */
  399. function setItem(k, v) {
  400. local.set(RKEY, k, v);
  401. console.log(`规则${RKEY}设置${k} => ${v}`)
  402. }
  403. /**
  404. * 获取数据库配置表对应的key字段的value,没有这个key就返回value默认传参.需要有缓存,第一次获取后会存在内存里
  405. * @param k 键
  406. * @param v 值
  407. * @returns {*}
  408. */
  409. function getItem(k, v) {
  410. return local.get(RKEY, k) || v;
  411. }
  412. /**
  413. * 删除数据库key对应的一条数据,并清除此key对应的内存缓存
  414. * @param k
  415. */
  416. function clearItem(k) {
  417. local.delete(RKEY, k);
  418. }
  419. /*** js自封装的方法 ***/
  420. /**
  421. * 获取链接的host(带http协议的完整链接)
  422. * @param url 任意一个正常完整的Url,自动提取根
  423. * @returns {string}
  424. */
  425. function getHome(url) {
  426. if (!url) {
  427. return ''
  428. }
  429. let tmp = url.split('//');
  430. url = tmp[0] + '//' + tmp[1].split('/')[0];
  431. try {
  432. url = decodeURIComponent(url);
  433. } catch (e) { }
  434. return url
  435. }
  436. /**
  437. * get参数编译链接,类似python params字典自动拼接
  438. * @param url 访问链接
  439. * @param obj 参数字典
  440. * @returns {*}
  441. */
  442. function buildUrl(url, obj) {
  443. obj = obj || {};
  444. if (url.indexOf('?') < 0) {
  445. url += '?'
  446. }
  447. let param_list = [];
  448. let keys = Object.keys(obj);
  449. keys.forEach(it => {
  450. param_list.push(it + '=' + obj[it])
  451. });
  452. let prs = param_list.join('&');
  453. if (keys.length > 0 && !url.endsWith('?')) {
  454. url += '&'
  455. }
  456. url += prs;
  457. return url
  458. }
  459. /**
  460. * 远程依赖执行函数
  461. * @param url 远程js地址
  462. */
  463. function require(url) {
  464. eval(request(url));
  465. }
  466. /**
  467. * 海阔网页请求函数完整封装
  468. * @param url 请求链接
  469. * @param obj 请求对象 {headers:{},method:'',timeout:5000,body:'',withHeaders:false}
  470. * @returns {string|string|DocumentFragment|*}
  471. */
  472. function request(url, obj) {
  473. if (typeof (obj) === 'undefined' || !obj || obj === {}) {
  474. if (!fetch_params || !fetch_params.headers) {
  475. let headers = {
  476. 'User-Agent': MOBILE_UA,
  477. };
  478. if (rule.headers) {
  479. Object.assign(headers, rule.headers);
  480. }
  481. fetch_params.headers = headers;
  482. }
  483. if (!fetch_params.headers.Referer) {
  484. fetch_params.headers.Referer = getHome(url)
  485. }
  486. obj = fetch_params;
  487. } else {
  488. let headers = obj.headers || {};
  489. let keys = Object.keys(headers).map(it => it.toLowerCase());
  490. if (!keys.includes('user-agent')) {
  491. headers['User-Agent'] = MOBILE_UA;
  492. } if (!keys.includes('referer')) {
  493. headers['Referer'] = getHome(url);
  494. }
  495. obj.headers = headers;
  496. }
  497. console.log(JSON.stringify(obj.headers));
  498. if (typeof (obj.headers.body) != 'undefined' && obj.headers.body && typeof (obj.headers.body) === 'string') {
  499. let data = {};
  500. obj.headers.body.split('&').forEach(it => {
  501. data[it.split('=')[0]] = it.split('=')[1]
  502. });
  503. obj.data = data;
  504. delete obj.headers.body
  505. }
  506. if (!url) {
  507. return obj.withHeaders ? '{}' : ''
  508. }
  509. if (obj.toBase64) { // 返回base64,用于请求图片
  510. obj.buffer = 2;
  511. delete obj.toBase64
  512. }
  513. console.log('request:' + url);
  514. let res = req(url, obj);
  515. let html = res.content || '';
  516. // console.log(html);
  517. if (obj.withHeaders) {
  518. let htmlWithHeaders = res.headers;
  519. htmlWithHeaders.body = html;
  520. return JSON.stringify(htmlWithHeaders);
  521. } else {
  522. return html
  523. }
  524. }
  525. fetch = request;
  526. print = function (data) {
  527. data = data || '';
  528. if (typeof (data) !== 'string') {
  529. try {
  530. data = JSON.stringify(data);
  531. } catch (e) {
  532. console.log('print:' + e.message)
  533. }
  534. }
  535. console.log(data);
  536. }
  537. log = console.log;
  538. /**
  539. * 检查宝塔验证并自动跳过获取正确源码
  540. * @param html 之前获取的html
  541. * @param url 之前的来源url
  542. * @param obj 来源obj
  543. * @returns {string|DocumentFragment|*}
  544. */
  545. function checkHtml(html, url, obj) {
  546. if (/\?btwaf=/.test(html)) {
  547. let btwaf = html.match(/btwaf(.*?)"/)[1];
  548. url = url.split('#')[0] + '?btwaf' + btwaf;
  549. html = request(url, obj);
  550. }
  551. return html
  552. }
  553. /**
  554. * 带一次宝塔验证的源码获取
  555. * @param url 请求链接
  556. * @param obj 请求参数
  557. * @returns {string|DocumentFragment}
  558. */
  559. function getCode(url, obj) {
  560. let html = request(url, obj);
  561. html = checkHtml(html, url, obj);
  562. return html
  563. }
  564. /**
  565. * 源rule专用的请求方法,自动注入cookie
  566. * @param url 请求链接
  567. * @returns {string|DocumentFragment}
  568. */
  569. function getHtml(url) {
  570. let obj = {};
  571. if (rule.headers) {
  572. obj.headers = rule.headers;
  573. }
  574. let cookie = getItem(RULE_CK, '');
  575. if (cookie) {
  576. if (obj.headers && !Object.keys(obj.headers).map(it => it.toLowerCase()).includes('cookie')) {
  577. obj.headers['Cookie'] = cookie;
  578. } else if (!obj.headers) {
  579. obj.headers = { Cookie: cookie };
  580. }
  581. }
  582. let html = getCode(url, obj);
  583. return html
  584. }
  585. /**
  586. * 首页分类解析,筛选暂未实现
  587. * @param homeObj 首页传参对象
  588. * @returns {string}
  589. */
  590. function homeParse(homeObj) {
  591. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  592. let classes = [];
  593. if (homeObj.class_name && homeObj.class_url) {
  594. let names = homeObj.class_name.split('&');
  595. let urls = homeObj.class_url.split('&');
  596. let cnt = Math.min(names.length, urls.length);
  597. for (let i = 0; i < cnt; i++) {
  598. classes.push({
  599. 'type_id': urls[i],
  600. 'type_name': names[i]
  601. });
  602. }
  603. }
  604. if (homeObj.class_parse) {
  605. let p = homeObj.class_parse.split(';');
  606. if (p.length >= 4) {
  607. try {
  608. let html = getHtml(homeObj.MY_URL);
  609. if (html) {
  610. homeHtmlCache = html;
  611. let list = pdfa(html, p[0]);
  612. if (list && list.length > 0) {
  613. list.forEach((it, idex) => {
  614. try {
  615. let name = pdfh(it, p[1]);
  616. if (homeObj.cate_exclude && (new RegExp(homeObj.cate_exclude).test(name))) {
  617. return;
  618. }
  619. let url = pdfh(it, p[2]);
  620. if (p[3]) {
  621. let exp = new RegExp(p[3]);
  622. url = url.match(exp)[1];
  623. }
  624. classes.push({
  625. 'type_id': url.trim(),
  626. 'type_name': name.trim()
  627. });
  628. } catch (e) {
  629. console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`);
  630. }
  631. });
  632. }
  633. }
  634. } catch (e) {
  635. console.log(e.message);
  636. }
  637. }
  638. }
  639. // 排除分类
  640. classes = classes.filter(it => !homeObj.cate_exclude || !(new RegExp(homeObj.cate_exclude).test(it.type_name)));
  641. let resp = {
  642. 'class': classes
  643. };
  644. if (homeObj.filter) {
  645. resp.filters = homeObj.filter;
  646. }
  647. console.log(JSON.stringify(resp));
  648. return JSON.stringify(resp);
  649. }
  650. /**
  651. * 首页推荐列表解析
  652. * @param homeVodObj
  653. * @returns {string}
  654. */
  655. function homeVodParse(homeVodObj) {
  656. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  657. let d = [];
  658. MY_URL = homeVodObj.homeUrl;
  659. // setItem('MY_URL',MY_URL);
  660. console.log(MY_URL);
  661. let p = homeVodObj.推荐;
  662. if (!p || typeof (p) !== 'string') {
  663. return '{}'
  664. }
  665. p = p.trim();
  666. if (p.startsWith('js:')) {
  667. const TYPE = 'home';
  668. var input = MY_URL;
  669. const HOST = rule.host;
  670. eval(p.replace('js:', ''));
  671. d = VODS;
  672. } else {
  673. p = p.split(';');
  674. if (!homeVodObj.double && p.length < 5) {
  675. return '{}'
  676. } else if (homeVodObj.double && p.length < 6) {
  677. return '{}'
  678. }
  679. let _ps = parseTags.getParse(p[0]);
  680. _pdfa = _ps.pdfa;
  681. _pdfh = _ps.pdfh;
  682. _pd = _ps.pd;
  683. let is_json = p[0].startsWith('json:');
  684. p[0] = p[0].replace(/^(jsp:|json:|jq:)/, '');
  685. // print(p[0]);
  686. let html = homeHtmlCache || getHtml(MY_URL);
  687. homeHtmlCache = undefined;
  688. if (is_json) {
  689. html = dealJson(html);
  690. }
  691. try {
  692. console.log('double:' + homeVodObj.double);
  693. if (homeVodObj.double) {
  694. let items = _pdfa(html, p[0]);
  695. // console.log(items.length);
  696. for (let item of items) {
  697. // console.log(p[1]);
  698. let items2 = _pdfa(item, p[1]);
  699. // console.log(items2.length);
  700. for (let item2 of items2) {
  701. try {
  702. let title = _pdfh(item2, p[2]);
  703. let img = '';
  704. try {
  705. img = _pd(item2, p[3])
  706. } catch (e) {
  707. }
  708. let desc = _pdfh(item2, p[4]);
  709. let links = [];
  710. for (let p5 of p[5].split('+')) {
  711. let link = !homeVodObj.detailUrl ? _pd(item2, p5, MY_URL) : _pdfh(item2, p5);
  712. links.push(link);
  713. }
  714. let vod = {
  715. vod_name: title,
  716. vod_pic: img,
  717. vod_remarks: desc,
  718. vod_id: links.join('$')
  719. };
  720. // print(vod);
  721. d.push(vod);
  722. } catch (e) {
  723. console.log('首页列表处理发生错误:' + e.message);
  724. }
  725. }
  726. }
  727. } else {
  728. let items = _pdfa(html, p[0]);
  729. for (let item of items) {
  730. try {
  731. let title = _pdfh(item, p[1]);
  732. let img = '';
  733. try {
  734. img = _pd(item, p[2], MY_URL);
  735. } catch (e) {
  736. }
  737. let desc = _pdfh(item, p[3]);
  738. let links = [];
  739. for (let p5 of p[4].split('+')) {
  740. let link = !homeVodObj.detailUrl ? _pd(item, p5, MY_URL) : _pdfh(item, p5);
  741. links.push(link);
  742. }
  743. let vod = {
  744. vod_name: title,
  745. vod_pic: img,
  746. vod_remarks: desc,
  747. vod_id: links.join('$')
  748. };
  749. d.push(vod);
  750. } catch (e) {
  751. }
  752. }
  753. }
  754. } catch (e) {
  755. }
  756. }
  757. // console.log(JSON.stringify(d));
  758. return JSON.stringify({
  759. list: d
  760. })
  761. }
  762. /**
  763. * 一级分类页数据解析
  764. * @param cateObj
  765. * @returns {string}
  766. */
  767. function categoryParse(cateObj) {
  768. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  769. let p = cateObj.一级;
  770. if (!p || typeof (p) !== 'string') {
  771. return '{}'
  772. }
  773. let d = [];
  774. // let url = cateObj.url.replaceAll('fyclass', cateObj.tid).replaceAll('fypage', cateObj.pg);
  775. let url = cateObj.url.replaceAll('fyclass', cateObj.tid);
  776. if (rule.filter_url) {
  777. if (!/fyfilter/.test(url)) {
  778. if (!url.endsWith('&') && !rule.filter_url.startsWith('&')) {
  779. url += '&'
  780. }
  781. url += rule.filter_url;
  782. } else {
  783. url = url.replace('fyfilter', rule.filter_url);
  784. }
  785. // console.log('filter:'+cateObj.filter);
  786. let fl = cateObj.filter ? cateObj.extend : {};
  787. let new_url;
  788. new_url = cheerio.jinja2(url, { fl: fl });
  789. // if (/object Object/.test(new_url)) {
  790. // new_url = drT.renderText(url, fl);
  791. // }
  792. url = new_url;
  793. }
  794. if (/fypage/.test(url)) {
  795. if (url.includes('(') && url.includes(')')) {
  796. let url_rep = url.match(/.*?\((.*)\)/)[1];
  797. // console.log(url_rep);
  798. let cnt_page = url_rep.replaceAll('fypage', cateObj.pg);
  799. // console.log(cnt_page);
  800. let cnt_pg = eval(cnt_page);
  801. // console.log(cnt_pg);
  802. url = url.replaceAll(url_rep, cnt_pg).replaceAll('(', '').replaceAll(')', '');
  803. } else {
  804. url = url.replaceAll('fypage', cateObj.pg);
  805. }
  806. }
  807. if (cateObj.pg === 1 && url.includes('[') && url.includes(']')) {
  808. url = url.split('[')[1].split(']')[0];
  809. }
  810. MY_URL = url;
  811. // setItem('MY_URL',MY_URL);
  812. console.log(MY_URL);
  813. p = p.trim();
  814. const MY_CATE = cateObj.tid;
  815. if (p.startsWith('js:')) {
  816. var MY_FL = cateObj.extend;
  817. const TYPE = 'cate';
  818. var input = MY_URL;
  819. const MY_PAGE = cateObj.pg;
  820. var desc = '';
  821. eval(p.trim().replace('js:', ''));
  822. d = VODS;
  823. } else {
  824. p = p.split(';');
  825. if (p.length < 5) {
  826. return '{}'
  827. }
  828. let _ps = parseTags.getParse(p[0]);
  829. _pdfa = _ps.pdfa;
  830. _pdfh = _ps.pdfh;
  831. _pd = _ps.pd;
  832. let is_json = p[0].startsWith('json:');
  833. p[0] = p[0].replace(/^(jsp:|json:|jq:)/, '');
  834. try {
  835. let html = getHtml(MY_URL);
  836. if (html) {
  837. if (is_json) {
  838. html = dealJson(html);
  839. }
  840. let list = _pdfa(html, p[0]);
  841. list.forEach(it => {
  842. let links = p[4].split('+').map(p4 => {
  843. return !rule.detailUrl ? _pd(it, p4, MY_URL) : _pdfh(it, p4);
  844. });
  845. let link = links.join('$');
  846. let vod_id = rule.detailUrl ? MY_CATE + '$' + link : link;
  847. d.push({
  848. 'vod_id': vod_id,
  849. 'vod_name': _pdfh(it, p[1]).replace(/\n|\t/g, '').trim(),
  850. 'vod_pic': _pd(it, p[2], MY_URL),
  851. 'vod_remarks': _pdfh(it, p[3]).replace(/\n|\t/g, '').trim(),
  852. });
  853. });
  854. }
  855. } catch (e) {
  856. console.log(e.message);
  857. }
  858. }
  859. // print(d);
  860. return d.length < 1 ? '{}' : JSON.stringify({
  861. 'page': parseInt(cateObj.pg),
  862. 'pagecount': 999,
  863. 'limit': 20,
  864. 'total': 999,
  865. 'list': d,
  866. });
  867. }
  868. /**
  869. * 搜索列表数据解析
  870. * @param searchObj
  871. * @returns {string}
  872. */
  873. function searchParse(searchObj) {
  874. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  875. let d = [];
  876. if (!searchObj.searchUrl) {
  877. return '{}'
  878. }
  879. let p = searchObj.搜索 === '*' && rule.一级 ? rule.一级 : searchObj.搜索;
  880. if (!p || typeof (p) !== 'string') {
  881. return '{}'
  882. }
  883. p = p.trim();
  884. let url = searchObj.searchUrl.replaceAll('**', searchObj.wd).replaceAll('fypage', searchObj.pg);
  885. MY_URL = url;
  886. console.log(MY_URL);
  887. // setItem('MY_URL',MY_URL);
  888. if (p.startsWith('js:')) {
  889. const TYPE = 'search';
  890. const MY_PAGE = searchObj.pg;
  891. const KEY = searchObj.wd;
  892. var input = MY_URL;
  893. var detailUrl = rule.detailUrl || '';
  894. eval(p.trim().replace('js:', ''));
  895. d = VODS;
  896. } else {
  897. p = p.split(';');
  898. if (p.length < 5) {
  899. return '{}'
  900. }
  901. let _ps = parseTags.getParse(p[0]);
  902. _pdfa = _ps.pdfa;
  903. _pdfh = _ps.pdfh;
  904. _pd = _ps.pd;
  905. let is_json = p[0].startsWith('json:');
  906. p[0] = p[0].replace(/^(jsp:|json:|jq:)/, '');
  907. try {
  908. let html = getHtml(MY_URL);
  909. if (html) {
  910. if (/系统安全验证|输入验证码/.test(html)) {
  911. let cookie = verifyCode(MY_URL);
  912. if (cookie) {
  913. console.log(`本次成功过验证,cookie:${cookie}`);
  914. setItem(RULE_CK, cookie);
  915. } else {
  916. console.log(`本次自动过搜索验证失败,cookie:${cookie}`);
  917. }
  918. // obj.headers['Cookie'] = cookie;
  919. html = getHtml(MY_URL);
  920. }
  921. if (!html.includes(searchObj.wd)) {
  922. console.log('搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码');
  923. console.log(html);
  924. }
  925. if (is_json) {
  926. html = dealJson(html);
  927. }
  928. let list = _pdfa(html, p[0]);
  929. list.forEach(it => {
  930. let links = p[4].split('+').map(p4 => {
  931. return !rule.detailUrl ? _pd(it, p4, MY_URL) : _pdfh(it, p4)
  932. });
  933. let link = links.join('$');
  934. let ob = {
  935. 'vod_id': link,
  936. 'vod_name': _pdfh(it, p[1]).replace(/\n|\t/g, '').trim(),
  937. 'vod_pic': _pd(it, p[2], MY_URL),
  938. 'vod_remarks': _pdfh(it, p[3]).replace(/\n|\t/g, '').trim(),
  939. };
  940. if (p.length > 5 && p[5]) {
  941. ob.vod_content = _pdfh(it, p[5]);
  942. }
  943. d.push(ob);
  944. });
  945. }
  946. } catch (e) {
  947. return '{}'
  948. }
  949. }
  950. return JSON.stringify({
  951. 'page': parseInt(searchObj.pg),
  952. 'pagecount': 10,
  953. 'limit': 20,
  954. 'total': 100,
  955. 'list': d,
  956. });
  957. }
  958. /**
  959. * 二级详情页数据解析
  960. * @param detailObj
  961. * @returns {string}
  962. */
  963. function detailParse(detailObj) {
  964. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  965. let vod = {
  966. vod_id: detailObj.orId, //"id",
  967. vod_name: "片名",
  968. vod_pic: "",
  969. type_name: "剧情",
  970. vod_year: "年份",
  971. vod_area: "地区",
  972. vod_remarks: "更新信息",
  973. vod_actor: "主演",
  974. vod_director: "导演",
  975. vod_content: "简介"
  976. };
  977. let p = detailObj.二级;
  978. let url = detailObj.url;
  979. let detailUrl = detailObj.detailUrl;
  980. let fyclass = detailObj.fyclass;
  981. let tab_exclude = detailObj.tab_exclude;
  982. let html = detailObj.html || '';
  983. MY_URL = url;
  984. console.log(MY_URL);
  985. // setItem('MY_URL',MY_URL);
  986. if (p === '*') {
  987. vod.vod_play_from = '道长在线';
  988. vod.vod_remarks = detailUrl;
  989. vod.vod_actor = '没有二级,只有一级链接直接嗅探播放';
  990. vod.vod_content = MY_URL;
  991. vod.vod_play_url = '嗅探播放$' + MY_URL;
  992. } else if (typeof (p) === 'string' && p.trim().startsWith('js:')) {
  993. const TYPE = 'detail';
  994. var input = MY_URL;
  995. eval(p.trim().replace('js:', ''));
  996. vod = VOD;
  997. console.log(JSON.stringify(vod));
  998. } else if (p && typeof (p) === 'object') {
  999. if (!html) {
  1000. html = getHtml(MY_URL);
  1001. }
  1002. let _impJQP = true;
  1003. let _ps;
  1004. if (p.is_json) {
  1005. _ps = parseTags.json;
  1006. html = dealJson(html);
  1007. _impJQP = false;
  1008. } else if (p.is_jsp) {
  1009. _ps = parseTags.jsp;
  1010. } else if (p.is_jq) {
  1011. _ps = parseTags.jq;
  1012. } else {
  1013. _ps = parseTags.jq;
  1014. }
  1015. if (_impJQP) {
  1016. let c$ = cheerio.load(html);
  1017. html = { rr: c$, ele: c$('html')[0] }
  1018. }
  1019. _pdfa = _ps.pdfa;
  1020. _pdfh = _ps.pdfh;
  1021. _pd = _ps.pd;
  1022. if (p.title) {
  1023. let p1 = p.title.split(';');
  1024. vod.vod_name = _pdfh(html, p1[0]).replace(/\n|\t/g, '').trim();
  1025. let type_name = p1.length > 1 ? _pdfh(html, p1[1]).replace(/\n|\t/g, '').replace(/ /g, '').trim() : '';
  1026. vod.type_name = type_name || vod.type_name;
  1027. }
  1028. if (p.desc) {
  1029. try {
  1030. let p1 = p.desc.split(';');
  1031. vod.vod_remarks = _pdfh(html, p1[0]).replace(/\n|\t/g, '').trim();
  1032. vod.vod_year = p1.length > 1 ? _pdfh(html, p1[1]).replace(/\n|\t/g, '').trim() : '';
  1033. vod.vod_area = p1.length > 2 ? _pdfh(html, p1[2]).replace(/\n|\t/g, '').trim() : '';
  1034. // vod.vod_actor = p1.length > 3 ? _pdfh(html, p1[3]).replaceAll('\n', ' ').trim():'';
  1035. vod.vod_actor = p1.length > 3 ? _pdfh(html, p1[3]).replace(/\n|\t/g, '').trim() : '';
  1036. vod.vod_director = p1.length > 4 ? _pdfh(html, p1[4]).replace(/\n|\t/g, '').trim() : '';
  1037. }
  1038. catch (e) {
  1039. }
  1040. }
  1041. if (p.content) {
  1042. try {
  1043. let p1 = p.content.split(';');
  1044. vod.vod_content = _pdfh(html, p1[0]).replace(/\n|\t/g, '').trim();
  1045. }
  1046. catch (e) { }
  1047. }
  1048. if (p.img) {
  1049. try {
  1050. let p1 = p.img.split(';');
  1051. vod.vod_pic = _pd(html, p1[0], MY_URL);
  1052. }
  1053. catch (e) { }
  1054. }
  1055. let vod_play_from = '$$$';
  1056. let playFrom = [];
  1057. if (p.重定向 && p.重定向.startsWith('js:')) {
  1058. html = eval(p.重定向.replace('js:', ''));
  1059. if (_impJQP) {
  1060. let c$ = cheerio.load(html);
  1061. html = { rr: c$, ele: c$('html')[0] }
  1062. }
  1063. }
  1064. // console.log(2);
  1065. if (p.tabs) {
  1066. let p_tab = p.tabs.split(';')[0];
  1067. console.log(p_tab);
  1068. let vHeader = _pdfa(html, p_tab);
  1069. console.log(vHeader.length);
  1070. for (let v of vHeader) {
  1071. let v_title = _pdfh(v, 'body&&Text');
  1072. console.log(v_title);
  1073. if (tab_exclude && (new RegExp(tab_exclude)).test(v_title)) {
  1074. continue;
  1075. }
  1076. playFrom.push(v_title);
  1077. }
  1078. console.log(JSON.stringify(playFrom));
  1079. } else {
  1080. playFrom = ['道长在线']
  1081. }
  1082. vod.vod_play_from = playFrom.join(vod_play_from);
  1083. // console.log(3);
  1084. let vod_play_url = '$$$';
  1085. let vod_tab_list = [];
  1086. if (p.lists) {
  1087. for (let i = 0; i < playFrom.length; i++) {
  1088. let tab_name = playFrom[i];
  1089. let tab_ext = p.tabs.split(';').length > 1 ? p.tabs.split(';')[1] : '';
  1090. let p1 = p.lists.replaceAll('#idv', tab_name).replaceAll('#id', i);
  1091. tab_ext = tab_ext.replaceAll('#idv', tab_name).replaceAll('#id', i);
  1092. console.log(p1);
  1093. // console.log(html);
  1094. let vodList = [];
  1095. try {
  1096. vodList = _pdfa(html, p1);
  1097. console.log('len(vodList):' + vodList.length);
  1098. } catch (e) {
  1099. // console.log(e.message);
  1100. }
  1101. let new_vod_list = [];
  1102. let tabName = tab_ext ? _pdfh(html, tab_ext) : tab_name;
  1103. console.log(tabName);
  1104. // console.log('cheerio解析Text');
  1105. vodList.forEach(it => {
  1106. // 请注意,这里要固定pdfh解析body&&Text,不需要下划线,没写错
  1107. // new_vod_list.push(pdfh(it,'body&&Text')+'$'+_pd(it,'a&&href',MY_URL));
  1108. // new_vod_list.push(cheerio.load(it).text() + '$' + _pd(it, 'a&&href', MY_URL));
  1109. new_vod_list.push(_pdfh(it, 'body&&Text') + '$' + _pd(it, 'a&&href', MY_URL));
  1110. });
  1111. let vlist = new_vod_list.join('#');
  1112. vod_tab_list.push(vlist);
  1113. }
  1114. }
  1115. vod.vod_play_url = vod_tab_list.join(vod_play_url);
  1116. }
  1117. // print(vod);
  1118. return JSON.stringify({
  1119. list: [vod]
  1120. })
  1121. }
  1122. /**
  1123. * 选集播放点击事件解析
  1124. * @param playObj
  1125. * @returns {string}
  1126. */
  1127. function playParse(playObj) {
  1128. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1129. MY_URL = playObj.url;
  1130. if (!/http/.test(MY_URL)) {
  1131. try {
  1132. MY_URL = base64Decode(MY_URL);
  1133. } catch (e) { }
  1134. }
  1135. MY_URL = decodeURIComponent(MY_URL);
  1136. var input = MY_URL;//注入给免嗅js
  1137. let common_play = {
  1138. parse: 1,
  1139. url: input
  1140. };
  1141. let lazy_play;
  1142. if (!rule.play_parse || !rule.lazy) {
  1143. lazy_play = common_play;
  1144. } else if (rule.play_parse && rule.lazy && typeof (rule.lazy) === 'string') {
  1145. try {
  1146. let lazy_code = rule.lazy.replace('js:', '').trim();
  1147. print('开始执行js免嗅=>' + lazy_code);
  1148. eval(lazy_code);
  1149. lazy_play = typeof (input) === 'object' ? input : {
  1150. parse: 1,
  1151. jx: 1,
  1152. url: input
  1153. };
  1154. } catch (e) {
  1155. print('js免嗅错误:' + e.message);
  1156. lazy_play = common_play;
  1157. }
  1158. } else {
  1159. lazy_play = common_play;
  1160. }
  1161. console.log(JSON.stringify(lazy_play));
  1162. return JSON.stringify(lazy_play);
  1163. }
  1164. /**
  1165. * js源预处理特定返回对象中的函数
  1166. * @param ext
  1167. */
  1168. function init(ext) {
  1169. console.log('init');
  1170. try {
  1171. // make shared jsContext happy
  1172. if (typeof (globalThis.mubanJs) === 'undefined') {
  1173. let mubanJs = request('https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js', { 'User-Agent': MOBILE_UA });
  1174. mubanJs = mubanJs.replace('export default', '(function() {return muban;}()) // export default');
  1175. globalThis.mubanJs = mubanJs;
  1176. }
  1177. let muban = eval(globalThis.mubanJs);
  1178. if (typeof ext == 'object') {
  1179. rule = ext;
  1180. if (rule.template) {
  1181. rule = Object.assign(muban[rule.template], rule);
  1182. }
  1183. } else if (typeof ext == 'string') {
  1184. if (ext.startsWith('http')) {
  1185. let js = request(ext, { 'method': 'GET' });
  1186. if (js) {
  1187. eval(js.replace('var rule', 'rule'));
  1188. }
  1189. }
  1190. } else {
  1191. eval(ext.replace('var rule', 'rule'));
  1192. }
  1193. /** 处理一下 rule规则关键字段没传递的情况 **/
  1194. let rule_cate_excludes = (rule.cate_exclude || '').split('|').filter(it => it.trim());
  1195. let rule_tab_excludes = (rule.tab_exclude || '').split('|').filter(it => it.trim());
  1196. rule_cate_excludes = rule_cate_excludes.concat(CATE_EXCLUDE.split('|').filter(it => it.trim()));
  1197. rule_tab_excludes = rule_tab_excludes.concat(TAB_EXCLUDE.split('|').filter(it => it.trim()));
  1198. rule.cate_exclude = rule_cate_excludes.join('|');
  1199. rule.tab_exclude = rule_tab_excludes.join('|');
  1200. rule.host = (rule.host || '').rstrip('/');
  1201. rule.url = rule.url || '';
  1202. rule.double = rule.double || false;
  1203. rule.homeUrl = rule.homeUrl || '';
  1204. rule.detailUrl = rule.detailUrl || '';
  1205. rule.searchUrl = rule.searchUrl || '';
  1206. rule.homeUrl = rule.host && rule.homeUrl ? urljoin(rule.host, rule.homeUrl) : (rule.homeUrl || rule.host);
  1207. rule.detailUrl = rule.host && rule.detailUrl ? urljoin(rule.host, rule.detailUrl) : rule.detailUrl;
  1208. if (rule.url.includes('[') && rule.url.includes(']')) {
  1209. let u1 = rule.url.split('[')[0]
  1210. let u2 = rule.url.split('[')[1].split(']')[0]
  1211. rule.url = rule.host && rule.url ? urljoin(rule.host, u1) + '[' + urljoin(rule.host, u2) + ']' : rule.url;
  1212. } else {
  1213. rule.url = rule.host && rule.url ? urljoin(rule.host, rule.url) : rule.url;
  1214. }
  1215. rule.searchUrl = rule.host && rule.searchUrl ? urljoin(rule.host, rule.searchUrl) : rule.searchUrl;
  1216. rule.timeout = rule.timeout || 5000;
  1217. rule.encoding = rule.编码 || rule.encoding || 'utf-8';
  1218. if (rule.headers && typeof (rule.headers) === 'object') {
  1219. try {
  1220. let header_keys = Object.keys(rule.headers);
  1221. for (let k of header_keys) {
  1222. if (k.toLowerCase() === 'user-agent') {
  1223. let v = rule.headers[k];
  1224. console.log(v);
  1225. if (['MOBILE_UA', 'PC_UA', 'UC_UA', 'IOS_UA', 'UA'].includes(v)) {
  1226. rule.headers[k] = eval(v);
  1227. }
  1228. }
  1229. }
  1230. } catch (e) {
  1231. console.log('处理headers发生错误:' + e.message);
  1232. }
  1233. }
  1234. // print(rule.headers);
  1235. rule_fetch_params = { 'headers': rule.headers || false, 'timeout': rule.timeout, 'encoding': rule.encoding };
  1236. oheaders = rule.headers || {};
  1237. RKEY = typeof (key) !== 'undefined' && key ? key : 'drpy_' + (rule.title || rule.host);
  1238. init_test();
  1239. } catch (e) {
  1240. console.log('init_test发生错误:' + e.message);
  1241. }
  1242. }
  1243. let homeHtmlCache = undefined;
  1244. /**
  1245. * js源获取首页分类和筛选特定返回对象中的函数
  1246. * @param filter 筛选条件字典对象
  1247. * @returns {string}
  1248. */
  1249. function home(filter) {
  1250. console.log("home");
  1251. let homeObj = {
  1252. filter: rule.filter || false,
  1253. MY_URL: rule.homeUrl,
  1254. class_name: rule.class_name || '',
  1255. class_url: rule.class_url || '',
  1256. class_parse: rule.class_parse || '',
  1257. cate_exclude: rule.cate_exclude,
  1258. };
  1259. return homeParse(homeObj);
  1260. }
  1261. /**
  1262. * js源获取首页推荐数据列表特定返回对象中的函数
  1263. * @param params
  1264. * @returns {string}
  1265. */
  1266. function homeVod(params) {
  1267. let homeVodObj = {
  1268. 推荐: rule.推荐,
  1269. double: rule.double,
  1270. homeUrl: rule.homeUrl,
  1271. detailUrl: rule.detailUrl
  1272. };
  1273. return homeVodParse(homeVodObj)
  1274. // return "{}";
  1275. }
  1276. /**
  1277. * js源获取分类页一级数据列表特定返回对象中的函数
  1278. * @param tid 分类id
  1279. * @param pg 页数
  1280. * @param filter 当前选中的筛选条件
  1281. * @param extend 扩展
  1282. * @returns {string}
  1283. */
  1284. function category(tid, pg, filter, extend) {
  1285. let cateObj = {
  1286. url: rule.url,
  1287. 一级: rule.一级,
  1288. tid: tid,
  1289. pg: parseInt(pg),
  1290. filter: filter,
  1291. extend: extend
  1292. };
  1293. // console.log(JSON.stringify(extend));
  1294. return categoryParse(cateObj)
  1295. }
  1296. /**
  1297. * js源获取二级详情页数据特定返回对象中的函数
  1298. * @param vod_url 一级列表中的vod_id或者是带分类的自拼接 vod_id 如 fyclass$vod_id
  1299. * @returns {string}
  1300. */
  1301. function detail(vod_url) {
  1302. let orId = vod_url;
  1303. let fyclass = '';
  1304. if (vod_url.indexOf('$') > -1) {
  1305. let tmp = vod_url.split('$');
  1306. fyclass = tmp[0];
  1307. vod_url = tmp[1];
  1308. }
  1309. let detailUrl = vod_url;
  1310. let url;
  1311. if (!detailUrl.startsWith('http') && !detailUrl.includes('/')) {
  1312. url = rule.detailUrl.replaceAll('fyid', detailUrl).replaceAll('fyclass', fyclass);
  1313. } else if (detailUrl.includes('/')) {
  1314. url = urljoin(rule.homeUrl, detailUrl);
  1315. } else {
  1316. url = detailUrl
  1317. }
  1318. let detailObj = {
  1319. orId: orId,
  1320. url: url,
  1321. 二级: rule.二级,
  1322. detailUrl: detailUrl,
  1323. fyclass: fyclass,
  1324. tab_exclude: rule.tab_exclude,
  1325. }
  1326. return detailParse(detailObj)
  1327. }
  1328. /**
  1329. * js源选集按钮播放点击事件特定返回对象中的函数
  1330. * @param flag 线路名
  1331. * @param id 播放按钮的链接
  1332. * @param flags 全局配置的flags是否需要解析的标识列表
  1333. * @returns {string}
  1334. */
  1335. function play(flag, id, flags) {
  1336. let playObj = {
  1337. url: id,
  1338. flag: flag,
  1339. flags: flags
  1340. }
  1341. return playParse(playObj);
  1342. }
  1343. /**
  1344. * js源搜索返回的数据列表特定返回对象中的函数
  1345. * @param wd 搜索关键字
  1346. * @param quick 是否来自快速搜索
  1347. * @returns {string}
  1348. */
  1349. function search(wd, quick) {
  1350. let searchObj = {
  1351. searchUrl: rule.searchUrl,
  1352. 搜索: rule.搜索,
  1353. wd: wd,
  1354. //pg: pg,
  1355. pg: 1,
  1356. quick: quick,
  1357. };
  1358. // console.log(JSON.stringify(searchObj));
  1359. return searchParse(searchObj)
  1360. }
  1361. function DRPY() {//导出函数
  1362. return {
  1363. init: init,
  1364. home: home,
  1365. homeVod: homeVod,
  1366. category: category,
  1367. detail: detail,
  1368. play: play,
  1369. search: search,
  1370. }
  1371. }
  1372. let pd = pD;
  1373. // 导出函数对象
  1374. __JS_SPIDER__ = {
  1375. init: init,
  1376. home: home,
  1377. homeVod: homeVod,
  1378. category: category,
  1379. detail: detail,
  1380. play: play,
  1381. search: search,
  1382. DRPY: DRPY
  1383. }