You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2110 lines
70 KiB

  1. import cheerio from "cheerio.min.js";
  2. import "crypto-js.js";
  3. import 模板 from "模板.js";
  4. import {
  5. gbkTool
  6. }
  7. from "gbk.js";
  8. function init_test() {
  9. console.log("init_test_start");
  10. console.log("当前版本号:" + VERSION);
  11. console.log(RKEY);
  12. console.log(JSON.stringify(rule));
  13. console.log("init_test_end")
  14. }
  15. function pre() {
  16. if (typeof rule.预处理 === "string" && rule.预处理 && rule.预处理.trim()) {
  17. let code = rule.预处理.trim();
  18. console.log("执行预处理代码:" + code);
  19. if (code.startsWith("js:")) {
  20. code = code.replace("js:", "")
  21. }
  22. try {
  23. eval(code)
  24. } catch (e) {
  25. console.log("预处理执行失败:" + e.message)
  26. }
  27. }
  28. }
  29. let rule = {};
  30. let vercode = typeof pdfl === "function" ? "drpy2.1" : "drpy2";
  31. const VERSION = vercode + " 3.9.49beta38 202400414";
  32. 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";
  33. 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";
  34. const UA = "Mozilla/5.0";
  35. 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";
  36. 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";
  37. const RULE_CK = "cookie";
  38. const CATE_EXCLUDE = "首页|留言|APP|下载|资讯|新闻|动态";
  39. const TAB_EXCLUDE = "猜你|喜欢|下载|剧情|热播";
  40. const OCR_RETRY = 3;
  41. const OCR_API = "http://drpy.nokia.press:8028/ocr/drpy/text";
  42. if (typeof MY_URL === "undefined") {
  43. var MY_URL
  44. }
  45. var HOST;
  46. var RKEY;
  47. var fetch;
  48. var print;
  49. var log;
  50. var rule_fetch_params;
  51. var fetch_params;
  52. var oheaders;
  53. var _pdfh;
  54. var _pdfa;
  55. var _pd;
  56. const DOM_CHECK_ATTR = /(url|src|href|-original|-src|-play|-url|style)$/;
  57. const SPECIAL_URL = /^(ftp|magnet|thunder|ws):/;
  58. const NOADD_INDEX = /:eq|:lt|:gt|:first|:last|^body$|^#/;
  59. const URLJOIN_ATTR = /(url|src|href|-original|-src|-play|-url|style)$/;
  60. const SELECT_REGEX = /:eq|:lt|:gt|#/g;
  61. const SELECT_REGEX_A = /:eq|:lt|:gt/g;
  62. if (typeof Object.assign != "function") {
  63. Object.assign = function() {
  64. var target = arguments[0];
  65. for (var i = 1; i < arguments.length; i++) {
  66. var source = arguments[i];
  67. for (var key in source) {
  68. if (Object.prototype.hasOwnProperty.call(source, key)) {
  69. target[key] = source[key]
  70. }
  71. }
  72. }
  73. return target
  74. }
  75. }
  76. if (!String.prototype.includes) {
  77. String.prototype.includes = function(search, start) {
  78. if (typeof start !== "number") {
  79. start = 0
  80. }
  81. if (start + search.length > this.length) {
  82. return false
  83. } else {
  84. return this.indexOf(search, start) !== -1
  85. }
  86. }
  87. }
  88. if (!Array.prototype.includes) {
  89. Object.defineProperty(Array.prototype, "includes", {
  90. value: function(searchElement, fromIndex) {
  91. if (this == null) {
  92. throw new TypeError('"this" is null or not defined')
  93. }
  94. var o = Object(this);
  95. var len = o.length >>> 0;
  96. if (len === 0) {
  97. return false
  98. }
  99. var n = fromIndex | 0;
  100. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
  101. while (k < len) {
  102. if (o[k] === searchElement) {
  103. return true
  104. }
  105. k++
  106. }
  107. return false
  108. }
  109. })
  110. }
  111. if (typeof String.prototype.startsWith != "function") {
  112. String.prototype.startsWith = function(prefix) {
  113. return this.slice(0, prefix.length) === prefix
  114. }
  115. }
  116. if (typeof String.prototype.endsWith != "function") {
  117. String.prototype.endsWith = function(suffix) {
  118. return this.indexOf(suffix, this.length - suffix.length) !== -1
  119. }
  120. }
  121. Object.prototype.myValues = function(obj) {
  122. if (obj == null) {
  123. throw new TypeError("Cannot convert undefined or null to object")
  124. }
  125. var res = [];
  126. for (var k in obj) {
  127. if (obj.hasOwnProperty(k)) {
  128. res.push(obj[k])
  129. }
  130. }
  131. return res
  132. };
  133. if (typeof Object.prototype.values != "function") {
  134. Object.prototype.values = function(obj) {
  135. if (obj == null) {
  136. throw new TypeError("Cannot convert undefined or null to object")
  137. }
  138. var res = [];
  139. for (var k in obj) {
  140. if (obj.hasOwnProperty(k)) {
  141. res.push(obj[k])
  142. }
  143. }
  144. return res
  145. }
  146. }
  147. if (typeof Array.prototype.join != "function") {
  148. Array.prototype.join = function(emoji) {
  149. emoji = emoji || "";
  150. let self = this;
  151. let str = "";
  152. let i = 0;
  153. if (!Array.isArray(self)) {
  154. throw String(self) + "is not Array"
  155. }
  156. if (self.length === 0) {
  157. return ""
  158. }
  159. if (self.length === 1) {
  160. return String(self[0])
  161. }
  162. i = 1;
  163. str = this[0];
  164. for (; i < self.length; i++) {
  165. str += String(emoji) + String(self[i])
  166. }
  167. return str
  168. }
  169. }
  170. String.prototype.rstrip = function(chars) {
  171. let regex = new RegExp(chars + "$");
  172. return this.replace(regex, "")
  173. };
  174. Array.prototype.append = Array.prototype.push;
  175. String.prototype.strip = String.prototype.trim;
  176. function 是否正版(vipUrl) {
  177. let flag = new RegExp("qq.com|iqiyi.com|youku.com|mgtv.com|bilibili.com|sohu.com|ixigua.com|pptv.com|miguvideo.com|le.com|1905.com|fun.tv");
  178. return flag.test(vipUrl)
  179. }
  180. function urlDeal(vipUrl) {
  181. if (!vipUrl) {
  182. return ""
  183. }
  184. if (!是否正版(vipUrl)) {
  185. return vipUrl
  186. }
  187. if (!/miguvideo/.test(vipUrl)) {
  188. vipUrl = vipUrl.split("#")[0].split("?")[0]
  189. }
  190. return vipUrl
  191. }
  192. function setResult(d) {
  193. if (!Array.isArray(d)) {
  194. return []
  195. }
  196. VODS = [];
  197. d.forEach(function(it) {
  198. let obj = {
  199. vod_id: it.url || "",
  200. vod_name: it.title || "",
  201. vod_remarks: it.desc || "",
  202. vod_content: it.content || "",
  203. vod_pic: it.pic_url || it.img || ""
  204. };
  205. let keys = Object.keys(it);
  206. if (keys.includes("tname")) {
  207. obj.type_name = it.tname || ""
  208. }
  209. if (keys.includes("tid")) {
  210. obj.type_id = it.tid || ""
  211. }
  212. if (keys.includes("year")) {
  213. obj.vod_year = it.year || ""
  214. }
  215. if (keys.includes("actor")) {
  216. obj.vod_actor = it.actor || ""
  217. }
  218. if (keys.includes("director")) {
  219. obj.vod_director = it.director || ""
  220. }
  221. if (keys.includes("area")) {
  222. obj.vod_area = it.area || ""
  223. }
  224. VODS.push(obj)
  225. });
  226. return VODS
  227. }
  228. function setResult2(res) {
  229. VODS = res.list || [];
  230. return VODS
  231. }
  232. function setHomeResult(res) {
  233. if (!res || typeof res !== "object") {
  234. return []
  235. }
  236. return setResult(res.list)
  237. }
  238. function rc(js) {
  239. if (js === "maomi_aes.js") {
  240. var a = CryptoJS.enc.Utf8.parse("625222f9149e961d");
  241. var t = CryptoJS.enc.Utf8.parse("5efdtf6060e2o330");
  242. return {
  243. De: function(word) {
  244. word = CryptoJS.enc.Hex.parse(word);
  245. return CryptoJS.AES.decrypt(CryptoJS.enc.Base64.stringify(word), a, {
  246. iv: t,
  247. mode: CryptoJS.mode.CBC,
  248. padding: CryptoJS.pad.Pkcs7
  249. })
  250. .toString(CryptoJS.enc.Utf8)
  251. },
  252. En: function(word) {
  253. var Encrypted = CryptoJS.AES.encrypt(word, a, {
  254. iv: t,
  255. mode: CryptoJS.mode.CBC,
  256. padding: CryptoJS.pad.Pkcs7
  257. });
  258. return Encrypted.ciphertext.toString()
  259. }
  260. }
  261. }
  262. return {}
  263. }
  264. function maoss(jxurl, ref, key) {
  265. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  266. eval(getCryptoJS());
  267. try {
  268. var getVideoInfo = function(text) {
  269. return CryptoJS.AES.decrypt(text, key, {
  270. iv: iv,
  271. padding: CryptoJS.pad.Pkcs7
  272. })
  273. .toString(CryptoJS.enc.Utf8)
  274. };
  275. var token_key = key == undefined ? "dvyYRQlnPRCMdQSe" : key;
  276. if (ref) {
  277. var html = request(jxurl, {
  278. headers: {
  279. Referer: ref
  280. }
  281. })
  282. } else {
  283. var html = request(jxurl)
  284. }
  285. if (html.indexOf("&btwaf=") != -1) {
  286. html = request(jxurl + "&btwaf" + html.match(/&btwaf(.*?)"/)[1], {
  287. headers: {
  288. Referer: ref
  289. }
  290. })
  291. }
  292. var token_iv = html.split('_token = "')[1].split('"')[0];
  293. var key = CryptoJS.enc.Utf8.parse(token_key);
  294. var iv = CryptoJS.enc.Utf8.parse(token_iv);
  295. eval(html.match(/var config = {[\s\S]*?}/)[0] + "");
  296. if (!config.url.startsWith("http")) {
  297. config.url = CryptoJS.AES.decrypt(config.url, key, {
  298. iv: iv,
  299. padding: CryptoJS.pad.Pkcs7
  300. })
  301. .toString(CryptoJS.enc.Utf8)
  302. }
  303. return config.url
  304. } catch (e) {
  305. return ""
  306. }
  307. }
  308. function urlencode(str) {
  309. str = (str + "")
  310. .toString();
  311. return encodeURIComponent(str)
  312. .replace(/!/g, "%21")
  313. .replace(/'/g, "%27")
  314. .replace(/\(/g, "%28")
  315. .replace(/\)/g, "%29")
  316. .replace(/\*/g, "%2A")
  317. .replace(/%20/g, "+")
  318. }
  319. function base64Encode(text) {
  320. return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text))
  321. }
  322. function base64Decode(text) {
  323. return CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(text))
  324. }
  325. function md5(text) {
  326. return CryptoJS.MD5(text)
  327. .toString()
  328. }
  329. function encodeStr(input, encoding) {
  330. encoding = encoding || "gbk";
  331. if (encoding.startsWith("gb")) {
  332. const strTool = gbkTool();
  333. input = strTool.encode(input)
  334. }
  335. return input
  336. }
  337. function decodeStr(input, encoding) {
  338. encoding = encoding || "gbk";
  339. if (encoding.startsWith("gb")) {
  340. const strTool = gbkTool();
  341. input = strTool.decode(input)
  342. }
  343. return input
  344. }
  345. function getCryptoJS() {
  346. return 'console.log("CryptoJS已装载");'
  347. }
  348. const RSA = {
  349. encode: function(data, key, option) {
  350. if (typeof rsaEncrypt === "function") {
  351. if (!option || typeof option !== "object") {
  352. return rsaEncrypt(data, key)
  353. } else {
  354. return rsaEncrypt(data, key, option)
  355. }
  356. } else {
  357. return false
  358. }
  359. },
  360. decode: function(data, key, option) {
  361. if (typeof rsaDecrypt === "function") {
  362. if (!option || typeof option !== "object") {
  363. return rsaDecrypt(data, key)
  364. } else {
  365. return rsaDecrypt(data, key, option)
  366. }
  367. } else {
  368. return false
  369. }
  370. }
  371. };
  372. function getProxyUrl() {
  373. if (typeof getProxy === "function") {
  374. return getProxy(true)
  375. } else {
  376. return "http://127.0.0.1:9978/proxy?do=js"
  377. }
  378. }
  379. function forceOrder(lists, key, option) {
  380. let start = Math.floor(lists.length / 2);
  381. let end = Math.min(lists.length - 1, start + 1);
  382. if (start >= end) {
  383. return lists
  384. }
  385. let first = lists[start];
  386. let second = lists[end];
  387. if (key) {
  388. try {
  389. first = first[key];
  390. second = second[key]
  391. } catch (e) {}
  392. }
  393. if (option && typeof option === "function") {
  394. try {
  395. first = option(first);
  396. second = option(second)
  397. } catch (e) {}
  398. }
  399. first += "";
  400. second += "";
  401. if (first.match(/(\d+)/) && second.match(/(\d+)/)) {
  402. let num1 = Number(first.match(/(\d+)/)[1]);
  403. let num2 = Number(second.match(/(\d+)/)[1]);
  404. if (num1 > num2) {
  405. lists.reverse()
  406. }
  407. }
  408. return lists
  409. }
  410. let VODS = [];
  411. let VOD = {};
  412. let TABS = [];
  413. let LISTS = [];
  414. globalThis.encodeUrl = urlencode;
  415. globalThis.urlencode = urlencode;
  416. function urljoin(fromPath, nowPath) {
  417. fromPath = fromPath || "";
  418. nowPath = nowPath || "";
  419. return joinUrl(fromPath, nowPath)
  420. }
  421. var urljoin2 = urljoin;
  422. const defaultParser = {
  423. pdfh: pdfh,
  424. pdfa: pdfa,
  425. pd: pd
  426. };
  427. function pdfh2(html, parse) {
  428. let html2 = html;
  429. try {
  430. if (typeof html !== "string") {
  431. html2 = html.rr(html.ele)
  432. .toString()
  433. }
  434. } catch (e) {
  435. print("html对象转文本发生了错误:" + e.message)
  436. }
  437. let result = defaultParser.pdfh(html2, parse);
  438. let option = parse.includes("&&") ? parse.split("&&")
  439. .slice(-1)[0] : parse.split(" ")
  440. .slice(-1)[0];
  441. if (/style/.test(option.toLowerCase()) && /url\(/.test(result)) {
  442. try {
  443. result = result.match(/url\((.*?)\)/)[1];
  444. result = result.replace(/^['|"](.*)['|"]$/, "$1")
  445. } catch (e) {}
  446. }
  447. return result
  448. }
  449. function pdfa2(html, parse) {
  450. let html2 = html;
  451. try {
  452. if (typeof html !== "string") {
  453. html2 = html.rr(html.ele)
  454. .toString()
  455. }
  456. } catch (e) {
  457. print("html对象转文本发生了错误:" + e.message)
  458. }
  459. return defaultParser.pdfa(html2, parse)
  460. }
  461. function pd2(html, parse, uri) {
  462. let ret = pdfh2(html, parse);
  463. if (typeof uri === "undefined" || !uri) {
  464. uri = ""
  465. }
  466. if (DOM_CHECK_ATTR.test(parse) && !SPECIAL_URL.test(ret)) {
  467. if (/http/.test(ret)) {
  468. ret = ret.substr(ret.indexOf("http"))
  469. } else {
  470. ret = urljoin(MY_URL, ret)
  471. }
  472. }
  473. return ret
  474. }
  475. const parseTags = {
  476. jsp: {
  477. pdfh: pdfh2,
  478. pdfa: pdfa2,
  479. pd: pd2
  480. },
  481. json: {
  482. pdfh(html, parse) {
  483. if (!parse || !parse.trim()) {
  484. return ""
  485. }
  486. if (typeof html === "string") {
  487. html = JSON.parse(html)
  488. }
  489. parse = parse.trim();
  490. if (!parse.startsWith("$.")) {
  491. parse = "$." + parse
  492. }
  493. parse = parse.split("||");
  494. for (let ps of parse) {
  495. let ret = cheerio.jp(ps, html);
  496. if (Array.isArray(ret)) {
  497. ret = ret[0] || ""
  498. } else {
  499. ret = ret || ""
  500. }
  501. if (ret && typeof ret !== "string") {
  502. ret = ret.toString()
  503. }
  504. if (ret) {
  505. return ret
  506. }
  507. }
  508. return ""
  509. }, pdfa(html, parse) {
  510. if (!parse || !parse.trim()) {
  511. return ""
  512. }
  513. if (typeof html === "string") {
  514. html = JSON.parse(html)
  515. }
  516. parse = parse.trim();
  517. if (!parse.startsWith("$.")) {
  518. parse = "$." + parse
  519. }
  520. let ret = cheerio.jp(parse, html);
  521. if (Array.isArray(ret) && Array.isArray(ret[0]) && ret.length === 1) {
  522. return ret[0] || []
  523. }
  524. return ret || []
  525. }, pd(html, parse) {
  526. let ret = parseTags.json.pdfh(html, parse);
  527. if (ret) {
  528. return urljoin(MY_URL, ret)
  529. }
  530. return ret
  531. }
  532. },
  533. jq: {
  534. pdfh(html, parse) {
  535. if (!html || !parse || !parse.trim()) {
  536. return ""
  537. }
  538. parse = parse.trim();
  539. let result = defaultParser.pdfh(html, parse);
  540. return result
  541. }, pdfa(html, parse) {
  542. if (!html || !parse || !parse.trim()) {
  543. return []
  544. }
  545. parse = parse.trim();
  546. let result = defaultParser.pdfa(html, parse);
  547. print(`pdfa解析${parse}=>${result.length}`);
  548. return result
  549. }, pd(html, parse, base_url) {
  550. if (!html || !parse || !parse.trim()) {
  551. return ""
  552. }
  553. parse = parse.trim();
  554. base_url = base_url || MY_URL;
  555. return defaultParser.pd(html, parse, base_url)
  556. }
  557. },
  558. getParse(p0) {
  559. if (p0.startsWith("jsp:")) {
  560. return this.jsp
  561. } else if (p0.startsWith("json:")) {
  562. return this.json
  563. } else if (p0.startsWith("jq:")) {
  564. return this.jq
  565. } else {
  566. return this.jq
  567. }
  568. }
  569. };
  570. const stringify = JSON.stringify;
  571. const jsp = parseTags.jsp;
  572. const jq = parseTags.jq;
  573. function readFile(filePath) {
  574. filePath = filePath || "./uri.min.js";
  575. var fd = os.open(filePath);
  576. var buffer = new ArrayBuffer(1024);
  577. var len = os.read(fd, buffer, 0, 1024);
  578. console.log(len);
  579. let text = String.fromCharCode.apply(null, new Uint8Array(buffer));
  580. console.log(text);
  581. return text
  582. }
  583. function dealJson(html) {
  584. try {
  585. html = html.trim();
  586. if (!(html.startsWith("{") && html.endsWith("}") || html.startsWith("[") && html.endsWith("]"))) {
  587. html = "{" + html.match(/.*?\{(.*)\}/m)[1] + "}"
  588. }
  589. } catch (e) {}
  590. try {
  591. html = JSON.parse(html)
  592. } catch (e) {}
  593. return html
  594. }
  595. var OcrApi = {
  596. api: OCR_API,
  597. classification: function(img) {
  598. let code = "";
  599. try {
  600. log("通过drpy_ocr验证码接口过验证...");
  601. let html = request(OCR_API, {
  602. data: {
  603. img: img
  604. },
  605. headers: {
  606. "User-Agent": PC_UA
  607. },
  608. method: "POST"
  609. }, true);
  610. code = html || ""
  611. } catch (e) {
  612. log(`OCR识别验证码发生错误:${e.message}`)
  613. }
  614. return code
  615. }
  616. };
  617. function verifyCode(url) {
  618. let cnt = 0;
  619. let host = getHome(url);
  620. let cookie = "";
  621. while (cnt < OCR_RETRY) {
  622. try {
  623. let yzm_url = `${host}/index.php/verify/index.html`;
  624. console.log(`验证码链接:${yzm_url}`);
  625. let hhtml = request(yzm_url, {
  626. withHeaders: true,
  627. toBase64: true
  628. }, true);
  629. let json = JSON.parse(hhtml);
  630. if (!cookie) {
  631. let setCk = Object.keys(json)
  632. .find(it => it.toLowerCase() === "set-cookie");
  633. cookie = setCk ? json[setCk].split(";")[0] : ""
  634. }
  635. console.log("cookie:" + cookie);
  636. let img = json.body;
  637. let code = OcrApi.classification(img);
  638. console.log(`${cnt+1}次验证码识别结果:${code}`);
  639. let submit_url = `${host}/index.php/ajax/verify_check?type=search&verify=${code}`;
  640. console.log(submit_url);
  641. let html = request(submit_url, {
  642. headers: {
  643. Cookie: cookie,
  644. "User-Agent": MOBILE_UA
  645. },
  646. method: "POST"
  647. });
  648. html = JSON.parse(html);
  649. if (html.msg === "ok") {
  650. console.log(`${cnt+1}次验证码提交成功`);
  651. return cookie
  652. } else if (html.msg !== "ok" && cnt + 1 >= OCR_RETRY) {
  653. cookie = ""
  654. }
  655. } catch (e) {
  656. console.log(`${cnt+1}次验证码提交失败:${e.message}`);
  657. if (cnt + 1 >= OCR_RETRY) {
  658. cookie = ""
  659. }
  660. }
  661. cnt += 1
  662. }
  663. return cookie
  664. }
  665. function setItem(k, v) {
  666. local.set(RKEY, k, v);
  667. console.log(`规则${RKEY}设置${k} => ${v}`)
  668. }
  669. function getItem(k, v) {
  670. return local.get(RKEY, k) || v
  671. }
  672. function clearItem(k) {
  673. local.delete(RKEY, k)
  674. }
  675. function getHome(url) {
  676. if (!url) {
  677. return ""
  678. }
  679. let tmp = url.split("//");
  680. url = tmp[0] + "//" + tmp[1].split("/")[0];
  681. try {
  682. url = decodeURIComponent(url)
  683. } catch (e) {}
  684. return url
  685. }
  686. function buildUrl(url, obj) {
  687. obj = obj || {};
  688. if (url.indexOf("?") < 0) {
  689. url += "?"
  690. }
  691. let param_list = [];
  692. let keys = Object.keys(obj);
  693. keys.forEach(it => {
  694. param_list.push(it + "=" + obj[it])
  695. });
  696. let prs = param_list.join("&");
  697. if (keys.length > 0 && !url.endsWith("?")) {
  698. url += "&"
  699. }
  700. url += prs;
  701. return url
  702. }
  703. function require(url) {
  704. eval(request(url))
  705. }
  706. function request(url, obj, ocr_flag) {
  707. ocr_flag = ocr_flag || false;
  708. if (typeof obj === "undefined" || !obj || obj === {}) {
  709. if (!fetch_params || !fetch_params.headers) {
  710. let headers = {
  711. "User-Agent": MOBILE_UA
  712. };
  713. if (rule.headers) {
  714. Object.assign(headers, rule.headers)
  715. }
  716. if (!fetch_params) {
  717. fetch_params = {}
  718. }
  719. fetch_params.headers = headers
  720. }
  721. if (!fetch_params.headers.Referer) {
  722. fetch_params.headers.Referer = getHome(url)
  723. }
  724. obj = fetch_params
  725. } else {
  726. let headers = obj.headers || {};
  727. let keys = Object.keys(headers)
  728. .map(it => it.toLowerCase());
  729. if (!keys.includes("user-agent")) {
  730. headers["User-Agent"] = MOBILE_UA
  731. }
  732. if (!keys.includes("referer")) {
  733. headers["Referer"] = getHome(url)
  734. }
  735. obj.headers = headers
  736. }
  737. if (rule.encoding && rule.encoding !== "utf-8" && !ocr_flag) {
  738. if (!obj.headers.hasOwnProperty("Content-Type") && !obj.headers.hasOwnProperty("content-type")) {
  739. obj.headers["Content-Type"] = "text/html; charset=" + rule.encoding
  740. }
  741. }
  742. if (typeof obj.body != "undefined" && obj.body && typeof obj.body === "string") {
  743. if (!obj.headers.hasOwnProperty("Content-Type") && !obj.headers.hasOwnProperty("content-type")) {
  744. obj.headers["Content-Type"] = "application/x-www-form-urlencoded; charset=" + rule.encoding
  745. }
  746. } else if (typeof obj.body != "undefined" && obj.body && typeof obj.body === "object") {
  747. obj.data = obj.body;
  748. delete obj.body
  749. }
  750. if (!url) {
  751. return obj.withHeaders ? "{}" : ""
  752. }
  753. if (obj.toBase64) {
  754. obj.buffer = 2;
  755. delete obj.toBase64
  756. }
  757. if (obj.redirect === false) {
  758. obj.redirect = 0
  759. }
  760. console.log(JSON.stringify(obj.headers));
  761. console.log("request:" + url + `|method:${obj.method||"GET"}|body:${obj.body||""}`);
  762. let res = req(url, obj);
  763. let html = res.content || "";
  764. if (obj.withHeaders) {
  765. let htmlWithHeaders = res.headers;
  766. htmlWithHeaders.body = html;
  767. return JSON.stringify(htmlWithHeaders)
  768. } else {
  769. return html
  770. }
  771. }
  772. function post(url, obj) {
  773. obj.method = "POST";
  774. return request(url, obj)
  775. }
  776. fetch = request;
  777. print = function(data) {
  778. data = data || "";
  779. if (typeof data == "object" && Object.keys(data)
  780. .length > 0) {
  781. try {
  782. data = JSON.stringify(data);
  783. console.log(data)
  784. } catch (e) {
  785. console.log(typeof data + ":" + data.length);
  786. return
  787. }
  788. } else if (typeof data == "object" && Object.keys(data)
  789. .length < 1) {
  790. console.log("null object")
  791. } else {
  792. console.log(data)
  793. }
  794. };
  795. log = print;
  796. function checkHtml(html, url, obj) {
  797. if (/\?btwaf=/.test(html)) {
  798. let btwaf = html.match(/btwaf(.*?)"/)[1];
  799. url = url.split("#")[0] + "?btwaf" + btwaf;
  800. print("宝塔验证访问链接:" + url);
  801. html = request(url, obj)
  802. }
  803. return html
  804. }
  805. function getCode(url, obj) {
  806. let html = request(url, obj);
  807. html = checkHtml(html, url, obj);
  808. return html
  809. }
  810. function getHtml(url) {
  811. let obj = {};
  812. if (rule.headers) {
  813. obj.headers = rule.headers
  814. }
  815. let cookie = getItem(RULE_CK, "");
  816. if (cookie) {
  817. if (obj.headers && !Object.keys(obj.headers)
  818. .map(it => it.toLowerCase())
  819. .includes("cookie")) {
  820. log("历史无cookie,新增过验证后的cookie");
  821. obj.headers["Cookie"] = cookie
  822. } else if (obj.headers && obj.headers.cookie && obj.headers.cookie !== cookie) {
  823. obj.headers["Cookie"] = cookie;
  824. log("历史有小写过期的cookie,更新过验证后的cookie")
  825. } else if (obj.headers && obj.headers.Cookie && obj.headers.Cookie !== cookie) {
  826. obj.headers["Cookie"] = cookie;
  827. log("历史有大写过期的cookie,更新过验证后的cookie")
  828. } else if (!obj.headers) {
  829. obj.headers = {
  830. Cookie: cookie
  831. };
  832. log("历史无headers,更新过验证后的含cookie的headers")
  833. }
  834. }
  835. let html = getCode(url, obj);
  836. return html
  837. }
  838. function homeParse(homeObj) {
  839. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  840. let classes = [];
  841. if (homeObj.class_name && homeObj.class_url) {
  842. let names = homeObj.class_name.split("&");
  843. let urls = homeObj.class_url.split("&");
  844. let cnt = Math.min(names.length, urls.length);
  845. for (let i = 0; i < cnt; i++) {
  846. classes.push({
  847. type_id: urls[i],
  848. type_name: names[i]
  849. })
  850. }
  851. }
  852. if (homeObj.class_parse) {
  853. let p = homeObj.class_parse.split(";");
  854. let _ps = parseTags.getParse(p[0]);
  855. _pdfa = _ps.pdfa;
  856. _pdfh = _ps.pdfh;
  857. _pd = _ps.pd;
  858. MY_URL = rule.url;
  859. if (p.length >= 3) {
  860. try {
  861. let html = getHtml(homeObj.MY_URL);
  862. if (html) {
  863. homeHtmlCache = html;
  864. let list = _pdfa(html, p[0]);
  865. if (list && list.length > 0) {
  866. list.forEach((it, idex) => {
  867. try {
  868. let name = _pdfh(it, p[1]);
  869. if (homeObj.cate_exclude && new RegExp(homeObj.cate_exclude)
  870. .test(name)) {
  871. return
  872. }
  873. let url = _pd(it, p[2]);
  874. if (p.length > 3 && p[3]) {
  875. let exp = new RegExp(p[3]);
  876. url = url.match(exp)[1]
  877. }
  878. classes.push({
  879. type_id: url.trim(),
  880. type_name: name.trim()
  881. })
  882. } catch (e) {
  883. console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`)
  884. }
  885. })
  886. }
  887. }
  888. } catch (e) {
  889. console.log(e.message)
  890. }
  891. }
  892. }
  893. classes = classes.filter(it => !homeObj.cate_exclude || !new RegExp(homeObj.cate_exclude)
  894. .test(it.type_name));
  895. let resp = {
  896. class: classes
  897. };
  898. if (homeObj.filter) {
  899. resp.filters = homeObj.filter
  900. }
  901. console.log(JSON.stringify(resp));
  902. return JSON.stringify(resp)
  903. }
  904. function getPP(p, pn, pp, ppn) {
  905. try {
  906. let ps = p[pn] === "*" && pp.length > ppn ? pp[ppn] : p[pn];
  907. return ps
  908. } catch (e) {
  909. return ""
  910. }
  911. }
  912. function homeVodParse(homeVodObj) {
  913. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  914. let d = [];
  915. MY_URL = homeVodObj.homeUrl;
  916. console.log(MY_URL);
  917. let t1 = (new Date)
  918. .getTime();
  919. let p = homeVodObj.推荐;
  920. print("p:" + p);
  921. if (p === "*" && rule.一级) {
  922. p = rule.一级;
  923. homeVodObj.double = false
  924. }
  925. if (!p || typeof p !== "string") {
  926. return "{}"
  927. }
  928. p = p.trim();
  929. let pp = rule.一级.split(";");
  930. if (p.startsWith("js:")) {
  931. const TYPE = "home";
  932. var input = MY_URL;
  933. HOST = rule.host;
  934. eval(p.replace("js:", ""));
  935. d = VODS
  936. } else {
  937. p = p.split(";");
  938. if (!homeVodObj.double && p.length < 5) {
  939. return "{}"
  940. } else if (homeVodObj.double && p.length < 6) {
  941. return "{}"
  942. }
  943. let p0 = getPP(p, 0, pp, 0);
  944. let _ps = parseTags.getParse(p0);
  945. _pdfa = _ps.pdfa;
  946. _pdfh = _ps.pdfh;
  947. _pd = _ps.pd;
  948. let is_json = p0.startsWith("json:");
  949. p0 = p0.replace(/^(jsp:|json:|jq:)/, "");
  950. let html = homeHtmlCache || getHtml(MY_URL);
  951. homeHtmlCache = undefined;
  952. if (is_json) {
  953. html = dealJson(html)
  954. }
  955. try {
  956. console.log("double:" + homeVodObj.double);
  957. if (homeVodObj.double) {
  958. let items = _pdfa(html, p0);
  959. let p1 = getPP(p, 1, pp, 0);
  960. let p2 = getPP(p, 2, pp, 1);
  961. let p3 = getPP(p, 3, pp, 2);
  962. let p4 = getPP(p, 4, pp, 3);
  963. let p5 = getPP(p, 5, pp, 4);
  964. let p6 = getPP(p, 6, pp, 5);
  965. for (let item of items) {
  966. let items2 = _pdfa(item, p1);
  967. for (let item2 of items2) {
  968. try {
  969. let title = _pdfh(item2, p2);
  970. let img = "";
  971. try {
  972. img = _pd(item2, p3)
  973. } catch (e) {}
  974. let desc = "";
  975. try {
  976. desc = _pdfh(item2, p4)
  977. } catch (e) {}
  978. let links = [];
  979. for (let _p5 of p5.split("+")) {
  980. let link = !homeVodObj.detailUrl ? _pd(item2, _p5, MY_URL) : _pdfh(item2, _p5);
  981. links.push(link)
  982. }
  983. let content;
  984. if (p.length > 6 && p[6]) {
  985. content = _pdfh(item2, p6)
  986. } else {
  987. content = ""
  988. }
  989. let vid = links.join("$");
  990. if (rule.二级 === "*") {
  991. vid = vid + "@@" + title + "@@" + img
  992. }
  993. let vod = {
  994. vod_name: title,
  995. vod_pic: img,
  996. vod_remarks: desc,
  997. vod_content: content,
  998. vod_id: vid
  999. };
  1000. d.push(vod)
  1001. } catch (e) {
  1002. console.log("首页列表双层定位处理发生错误:" + e.message)
  1003. }
  1004. }
  1005. }
  1006. } else {
  1007. let items = _pdfa(html, p0);
  1008. let p1 = getPP(p, 1, pp, 1);
  1009. let p2 = getPP(p, 2, pp, 2);
  1010. let p3 = getPP(p, 3, pp, 3);
  1011. let p4 = getPP(p, 4, pp, 4);
  1012. let p5 = getPP(p, 5, pp, 5);
  1013. for (let item of items) {
  1014. try {
  1015. let title = _pdfh(item, p1);
  1016. let img = "";
  1017. try {
  1018. img = _pd(item, p2, MY_URL)
  1019. } catch (e) {}
  1020. let desc = "";
  1021. try {
  1022. desc = _pdfh(item, p3)
  1023. } catch (e) {}
  1024. let links = [];
  1025. for (let _p5 of p4.split("+")) {
  1026. let link = !homeVodObj.detailUrl ? _pd(item, _p5, MY_URL) : _pdfh(item, _p5);
  1027. links.push(link)
  1028. }
  1029. let content;
  1030. if (p.length > 5 && p[5]) {
  1031. content = _pdfh(item, p5)
  1032. } else {
  1033. content = ""
  1034. }
  1035. let vid = links.join("$");
  1036. if (rule.二级 === "*") {
  1037. vid = vid + "@@" + title + "@@" + img
  1038. }
  1039. let vod = {
  1040. vod_name: title,
  1041. vod_pic: img,
  1042. vod_remarks: desc,
  1043. vod_content: content,
  1044. vod_id: vid
  1045. };
  1046. d.push(vod)
  1047. } catch (e) {
  1048. console.log("首页列表单层定位处理发生错误:" + e.message)
  1049. }
  1050. }
  1051. }
  1052. } catch (e) {}
  1053. }
  1054. let t2 = (new Date)
  1055. .getTime();
  1056. console.log("加载首页推荐耗时:" + (t2 - t1) + "毫秒");
  1057. if (rule.图片替换 && rule.图片替换.includes("=>")) {
  1058. let replace_from = rule.图片替换.split("=>")[0];
  1059. let replace_to = rule.图片替换.split("=>")[1];
  1060. d.forEach(it => {
  1061. if (it.vod_pic && it.vod_pic.startsWith("http")) {
  1062. it.vod_pic = it.vod_pic.replace(replace_from, replace_to)
  1063. }
  1064. })
  1065. }
  1066. if (rule.图片来源) {
  1067. d.forEach(it => {
  1068. if (it.vod_pic && it.vod_pic.startsWith("http")) {
  1069. it.vod_pic = it.vod_pic + rule.图片来源
  1070. }
  1071. })
  1072. }
  1073. if (d.length > 0) {
  1074. print(d.slice(0, 2))
  1075. }
  1076. return JSON.stringify({
  1077. list: d
  1078. })
  1079. }
  1080. function categoryParse(cateObj) {
  1081. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1082. let p = cateObj.一级;
  1083. if (!p || typeof p !== "string") {
  1084. return "{}"
  1085. }
  1086. let d = [];
  1087. let url = cateObj.url.replaceAll("fyclass", cateObj.tid);
  1088. if (cateObj.pg === 1 && url.includes("[") && url.includes("]")) {
  1089. url = url.split("[")[1].split("]")[0]
  1090. } else if (cateObj.pg > 1 && url.includes("[") && url.includes("]")) {
  1091. url = url.split("[")[0]
  1092. }
  1093. if (rule.filter_url) {
  1094. if (!/fyfilter/.test(url)) {
  1095. if (!url.endsWith("&") && !rule.filter_url.startsWith("&")) {
  1096. url += "&"
  1097. }
  1098. url += rule.filter_url
  1099. } else {
  1100. url = url.replace("fyfilter", rule.filter_url)
  1101. }
  1102. let fl = cateObj.filter ? cateObj.extend : {};
  1103. if (rule.filter_def && typeof rule.filter_def === "object") {
  1104. try {
  1105. if (Object.keys(rule.filter_def)
  1106. .length > 0 && rule.filter_def.hasOwnProperty(cateObj.tid)) {
  1107. let self_fl_def = rule.filter_def[cateObj.tid];
  1108. if (self_fl_def && typeof self_fl_def === "object") {
  1109. let fl_def = JSON.parse(JSON.stringify(self_fl_def));
  1110. fl = Object.assign(fl_def, fl)
  1111. }
  1112. }
  1113. } catch (e) {
  1114. print("合并不同分类对应的默认筛选出错:" + e.message)
  1115. }
  1116. }
  1117. let new_url;
  1118. new_url = cheerio.jinja2(url, {
  1119. fl: fl
  1120. });
  1121. url = new_url
  1122. }
  1123. if (/fypage/.test(url)) {
  1124. if (url.includes("(") && url.includes(")")) {
  1125. let url_rep = url.match(/.*?\((.*)\)/)[1];
  1126. let cnt_page = url_rep.replaceAll("fypage", cateObj.pg);
  1127. let cnt_pg = eval(cnt_page);
  1128. url = url.replaceAll(url_rep, cnt_pg)
  1129. .replaceAll("(", "")
  1130. .replaceAll(")", "")
  1131. } else {
  1132. url = url.replaceAll("fypage", cateObj.pg)
  1133. }
  1134. }
  1135. MY_URL = url;
  1136. console.log(MY_URL);
  1137. p = p.trim();
  1138. const MY_CATE = cateObj.tid;
  1139. if (p.startsWith("js:")) {
  1140. var MY_FL = cateObj.extend;
  1141. const TYPE = "cate";
  1142. var input = MY_URL;
  1143. const MY_PAGE = cateObj.pg;
  1144. var desc = "";
  1145. eval(p.trim()
  1146. .replace("js:", ""));
  1147. d = VODS
  1148. } else {
  1149. p = p.split(";");
  1150. if (p.length < 5) {
  1151. return "{}"
  1152. }
  1153. let _ps = parseTags.getParse(p[0]);
  1154. _pdfa = _ps.pdfa;
  1155. _pdfh = _ps.pdfh;
  1156. _pd = _ps.pd;
  1157. let is_json = p[0].startsWith("json:");
  1158. p[0] = p[0].replace(/^(jsp:|json:|jq:)/, "");
  1159. try {
  1160. let html = getHtml(MY_URL);
  1161. if (html) {
  1162. if (is_json) {
  1163. html = dealJson(html)
  1164. }
  1165. let list = _pdfa(html, p[0]);
  1166. list.forEach(it => {
  1167. let links = p[4].split("+")
  1168. .map(p4 => {
  1169. return !rule.detailUrl ? _pd(it, p4, MY_URL) : _pdfh(it, p4)
  1170. });
  1171. let link = links.join("$");
  1172. let vod_id = rule.detailUrl ? MY_CATE + "$" + link : link;
  1173. let vod_name = _pdfh(it, p[1])
  1174. .replace(/\n|\t/g, "")
  1175. .trim();
  1176. let vod_pic = _pd(it, p[2], MY_URL);
  1177. if (rule.二级 === "*") {
  1178. vod_id = vod_id + "@@" + vod_name + "@@" + vod_pic
  1179. }
  1180. d.push({
  1181. vod_id: vod_id,
  1182. vod_name: vod_name,
  1183. vod_pic: vod_pic,
  1184. vod_remarks: _pdfh(it, p[3])
  1185. .replace(/\n|\t/g, "")
  1186. .trim()
  1187. })
  1188. })
  1189. }
  1190. } catch (e) {
  1191. console.log(e.message)
  1192. }
  1193. }
  1194. if (rule.图片替换 && rule.图片替换.includes("=>")) {
  1195. let replace_from = rule.图片替换.split("=>")[0];
  1196. let replace_to = rule.图片替换.split("=>")[1];
  1197. d.forEach(it => {
  1198. if (it.vod_pic && it.vod_pic.startsWith("http")) {
  1199. it.vod_pic = it.vod_pic.replace(replace_from, replace_to)
  1200. }
  1201. })
  1202. }
  1203. if (rule.图片来源) {
  1204. d.forEach(it => {
  1205. if (it.vod_pic && it.vod_pic.startsWith("http")) {
  1206. it.vod_pic = it.vod_pic + rule.图片来源
  1207. }
  1208. })
  1209. }
  1210. if (d.length > 0) {
  1211. print(d.slice(0, 2))
  1212. }
  1213. let pagecount = 0;
  1214. if (rule.pagecount && typeof rule.pagecount === "object" && rule.pagecount.hasOwnProperty(MY_CATE)) {
  1215. print(`MY_CATE:${MY_CATE},pagecount:${JSON.stringify(rule.pagecount)}`);
  1216. pagecount = parseInt(rule.pagecount[MY_CATE])
  1217. }
  1218. let nodata = {
  1219. list: [{
  1220. vod_name: "无数据,防无限请求",
  1221. vod_id: "no_data",
  1222. vod_remarks: "不要点,会崩的",
  1223. vod_pic: "https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/404.jpg"
  1224. }],
  1225. total: 1,
  1226. pagecount: 1,
  1227. page: 1,
  1228. limit: 1
  1229. };
  1230. let vod = d.length < 1 ? JSON.stringify(nodata) : JSON.stringify({
  1231. page: parseInt(cateObj.pg),
  1232. pagecount: pagecount || 999,
  1233. limit: 20,
  1234. total: 999,
  1235. list: d
  1236. });
  1237. return vod
  1238. }
  1239. function searchParse(searchObj) {
  1240. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1241. let d = [];
  1242. if (!searchObj.searchUrl) {
  1243. return "{}"
  1244. }
  1245. let p = searchObj.搜索 === "*" && rule.一级 ? rule.一级 : searchObj.搜索;
  1246. if (!p || typeof p !== "string") {
  1247. return "{}"
  1248. }
  1249. p = p.trim();
  1250. let pp = rule.一级.split(";");
  1251. let url = searchObj.searchUrl.replaceAll("**", searchObj.wd);
  1252. if (searchObj.pg === 1 && url.includes("[") && url.includes("]") && !url.includes("#")) {
  1253. url = url.split("[")[1].split("]")[0]
  1254. } else if (searchObj.pg > 1 && url.includes("[") && url.includes("]") && !url.includes("#")) {
  1255. url = url.split("[")[0]
  1256. }
  1257. if (/fypage/.test(url)) {
  1258. if (url.includes("(") && url.includes(")")) {
  1259. let url_rep = url.match(/.*?\((.*)\)/)[1];
  1260. let cnt_page = url_rep.replaceAll("fypage", searchObj.pg);
  1261. let cnt_pg = eval(cnt_page);
  1262. url = url.replaceAll(url_rep, cnt_pg)
  1263. .replaceAll("(", "")
  1264. .replaceAll(")", "")
  1265. } else {
  1266. url = url.replaceAll("fypage", searchObj.pg)
  1267. }
  1268. }
  1269. MY_URL = url;
  1270. console.log(MY_URL);
  1271. if (p.startsWith("js:")) {
  1272. const TYPE = "search";
  1273. const MY_PAGE = searchObj.pg;
  1274. const KEY = searchObj.wd;
  1275. var input = MY_URL;
  1276. var detailUrl = rule.detailUrl || "";
  1277. eval(p.trim()
  1278. .replace("js:", ""));
  1279. d = VODS
  1280. } else {
  1281. p = p.split(";");
  1282. if (p.length < 5) {
  1283. return "{}"
  1284. }
  1285. let p0 = getPP(p, 0, pp, 0);
  1286. let _ps = parseTags.getParse(p0);
  1287. _pdfa = _ps.pdfa;
  1288. _pdfh = _ps.pdfh;
  1289. _pd = _ps.pd;
  1290. let is_json = p0.startsWith("json:");
  1291. p0 = p0.replace(/^(jsp:|json:|jq:)/, "");
  1292. try {
  1293. let req_method = MY_URL.split(";")
  1294. .length > 1 ? MY_URL.split(";")[1].toLowerCase() : "get";
  1295. let html;
  1296. if (req_method === "post") {
  1297. let rurls = MY_URL.split(";")[0].split("#");
  1298. let rurl = rurls[0];
  1299. let params = rurls.length > 1 ? rurls[1] : "";
  1300. print(`post=》rurl:${rurl},params:${params}`);
  1301. let _fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1302. let postData = {
  1303. body: params
  1304. };
  1305. Object.assign(_fetch_params, postData);
  1306. html = post(rurl, _fetch_params)
  1307. } else if (req_method === "postjson") {
  1308. let rurls = MY_URL.split(";")[0].split("#");
  1309. let rurl = rurls[0];
  1310. let params = rurls.length > 1 ? rurls[1] : "";
  1311. print(`postjson-》rurl:${rurl},params:${params}`);
  1312. try {
  1313. params = JSON.parse(params)
  1314. } catch (e) {
  1315. params = "{}"
  1316. }
  1317. let _fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1318. let postData = {
  1319. body: params
  1320. };
  1321. Object.assign(_fetch_params, postData);
  1322. html = post(rurl, _fetch_params)
  1323. } else {
  1324. html = getHtml(MY_URL)
  1325. }
  1326. if (html) {
  1327. if (/系统安全验证|输入验证码/.test(html)) {
  1328. let cookie = verifyCode(MY_URL);
  1329. if (cookie) {
  1330. console.log(`本次成功过验证,cookie:${cookie}`);
  1331. setItem(RULE_CK, cookie)
  1332. } else {
  1333. console.log(`本次自动过搜索验证失败,cookie:${cookie}`)
  1334. }
  1335. html = getHtml(MY_URL)
  1336. }
  1337. if (!html.includes(searchObj.wd)) {
  1338. console.log("搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码");
  1339. console.log(html)
  1340. }
  1341. if (is_json) {
  1342. html = dealJson(html)
  1343. }
  1344. let list = _pdfa(html, p0);
  1345. let p1 = getPP(p, 1, pp, 1);
  1346. let p2 = getPP(p, 2, pp, 2);
  1347. let p3 = getPP(p, 3, pp, 3);
  1348. let p4 = getPP(p, 4, pp, 4);
  1349. let p5 = getPP(p, 5, pp, 5);
  1350. list.forEach(it => {
  1351. let links = p4.split("+")
  1352. .map(_p4 => {
  1353. return !rule.detailUrl ? _pd(it, _p4, MY_URL) : _pdfh(it, _p4)
  1354. });
  1355. let link = links.join("$");
  1356. let content;
  1357. if (p.length > 5 && p[5]) {
  1358. content = _pdfh(it, p5)
  1359. } else {
  1360. content = ""
  1361. }
  1362. let vod_id = link;
  1363. let vod_name = _pdfh(it, p1)
  1364. .replace(/\n|\t/g, "")
  1365. .trim();
  1366. let vod_pic = _pd(it, p2, MY_URL);
  1367. if (rule.二级 === "*") {
  1368. vod_id = vod_id + "@@" + vod_name + "@@" + vod_pic
  1369. }
  1370. let ob = {
  1371. vod_id: vod_id,
  1372. vod_name: vod_name,
  1373. vod_pic: vod_pic,
  1374. vod_remarks: _pdfh(it, p3)
  1375. .replace(/\n|\t/g, "")
  1376. .trim(),
  1377. vod_content: content.replace(/\n|\t/g, "")
  1378. .trim()
  1379. };
  1380. d.push(ob)
  1381. })
  1382. }
  1383. } catch (e) {
  1384. print("搜索发生错误:" + e.message);
  1385. return "{}"
  1386. }
  1387. }
  1388. if (rule.图片替换 && rule.图片替换.includes("=>")) {
  1389. let replace_from = rule.图片替换.split("=>")[0];
  1390. let replace_to = rule.图片替换.split("=>")[1];
  1391. d.forEach(it => {
  1392. if (it.vod_pic && it.vod_pic.startsWith("http")) {
  1393. it.vod_pic = it.vod_pic.replace(replace_from, replace_to)
  1394. }
  1395. })
  1396. }
  1397. if (rule.图片来源) {
  1398. d.forEach(it => {
  1399. if (it.vod_pic && it.vod_pic.startsWith("http")) {
  1400. it.vod_pic = it.vod_pic + rule.图片来源
  1401. }
  1402. })
  1403. }
  1404. return JSON.stringify({
  1405. page: parseInt(searchObj.pg),
  1406. pagecount: 10,
  1407. limit: 20,
  1408. total: 100,
  1409. list: d
  1410. })
  1411. }
  1412. function detailParse(detailObj) {
  1413. let t1 = (new Date)
  1414. .getTime();
  1415. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1416. let orId = detailObj.orId;
  1417. let vod_name = "片名";
  1418. let vod_pic = "";
  1419. let vod_id = orId;
  1420. if (rule.二级 === "*") {
  1421. let extra = orId.split("@@");
  1422. vod_name = extra.length > 1 ? extra[1] : vod_name;
  1423. vod_pic = extra.length > 2 ? extra[2] : vod_pic
  1424. }
  1425. let vod = {
  1426. vod_id: vod_id,
  1427. vod_name: vod_name,
  1428. vod_pic: vod_pic,
  1429. type_name: "类型",
  1430. vod_year: "年份",
  1431. vod_area: "地区",
  1432. vod_remarks: "更新信息",
  1433. vod_actor: "主演",
  1434. vod_director: "导演",
  1435. vod_content: "简介"
  1436. };
  1437. let p = detailObj.二级;
  1438. let url = detailObj.url;
  1439. let detailUrl = detailObj.detailUrl;
  1440. let fyclass = detailObj.fyclass;
  1441. let tab_exclude = detailObj.tab_exclude;
  1442. let html = detailObj.html || "";
  1443. MY_URL = url;
  1444. if (detailObj.二级访问前) {
  1445. try {
  1446. print(`尝试在二级访问前执行代码:${detailObj.二级访问前}`);
  1447. eval(detailObj.二级访问前.trim()
  1448. .replace("js:", ""))
  1449. } catch (e) {
  1450. print(`二级访问前执行代码出现错误:${e.message}`)
  1451. }
  1452. }
  1453. if (p === "*") {
  1454. vod.vod_play_from = "道长在线";
  1455. vod.vod_remarks = detailUrl;
  1456. vod.vod_actor = "没有二级,只有一级链接直接嗅探播放";
  1457. vod.vod_content = MY_URL;
  1458. vod.vod_play_url = "嗅探播放$" + MY_URL.split("@@")[0]
  1459. } else if (typeof p === "string" && p.trim()
  1460. .startsWith("js:")) {
  1461. const TYPE = "detail";
  1462. var input = MY_URL;
  1463. var play_url = "";
  1464. eval(p.trim()
  1465. .replace("js:", ""));
  1466. vod = VOD;
  1467. console.log(JSON.stringify(vod))
  1468. } else if (p && typeof p === "object") {
  1469. let tt1 = (new Date)
  1470. .getTime();
  1471. if (!html) {
  1472. html = getHtml(MY_URL)
  1473. }
  1474. print(`二级${MY_URL}仅获取源码耗时:${(new Date).getTime()-tt1}毫秒`);
  1475. let _ps;
  1476. if (p.is_json) {
  1477. print("二级是json");
  1478. _ps = parseTags.json;
  1479. html = dealJson(html)
  1480. } else if (p.is_jsp) {
  1481. print("二级是jsp");
  1482. _ps = parseTags.jsp
  1483. } else if (p.is_jq) {
  1484. print("二级是jq");
  1485. _ps = parseTags.jq
  1486. } else {
  1487. print("二级默认jq");
  1488. _ps = parseTags.jq
  1489. }
  1490. let tt2 = (new Date)
  1491. .getTime();
  1492. print(`二级${MY_URL}获取并装载源码耗时:${tt2-tt1}毫秒`);
  1493. _pdfa = _ps.pdfa;
  1494. _pdfh = _ps.pdfh;
  1495. _pd = _ps.pd;
  1496. if (p.title) {
  1497. let p1 = p.title.split(";");
  1498. vod.vod_name = _pdfh(html, p1[0])
  1499. .replace(/\n|\t/g, "")
  1500. .trim();
  1501. let type_name = p1.length > 1 ? _pdfh(html, p1[1])
  1502. .replace(/\n|\t/g, "")
  1503. .replace(/ /g, "")
  1504. .trim() : "";
  1505. vod.type_name = type_name || vod.type_name
  1506. }
  1507. if (p.desc) {
  1508. try {
  1509. let p1 = p.desc.split(";");
  1510. vod.vod_remarks = _pdfh(html, p1[0])
  1511. .replace(/\n|\t/g, "")
  1512. .trim();
  1513. vod.vod_year = p1.length > 1 ? _pdfh(html, p1[1])
  1514. .replace(/\n|\t/g, "")
  1515. .trim() : "";
  1516. vod.vod_area = p1.length > 2 ? _pdfh(html, p1[2])
  1517. .replace(/\n|\t/g, "")
  1518. .trim() : "";
  1519. vod.vod_actor = p1.length > 3 ? _pdfh(html, p1[3])
  1520. .replace(/\n|\t/g, "")
  1521. .trim() : "";
  1522. vod.vod_director = p1.length > 4 ? _pdfh(html, p1[4])
  1523. .replace(/\n|\t/g, "")
  1524. .trim() : ""
  1525. } catch (e) {}
  1526. }
  1527. if (p.content) {
  1528. try {
  1529. let p1 = p.content.split(";");
  1530. vod.vod_content = _pdfh(html, p1[0])
  1531. .replace(/\n|\t/g, "")
  1532. .trim()
  1533. } catch (e) {}
  1534. }
  1535. if (p.img) {
  1536. try {
  1537. let p1 = p.img.split(";");
  1538. vod.vod_pic = _pd(html, p1[0], MY_URL)
  1539. } catch (e) {}
  1540. }
  1541. let vod_play_from = "$$$";
  1542. let playFrom = [];
  1543. if (p.重定向 && p.重定向.startsWith("js:")) {
  1544. print("开始执行重定向代码:" + p.重定向);
  1545. html = eval(p.重定向.replace("js:", ""))
  1546. }
  1547. if (p.tabs) {
  1548. if (p.tabs.startsWith("js:")) {
  1549. print("开始执行tabs代码:" + p.tabs);
  1550. var input = MY_URL;
  1551. eval(p.tabs.replace("js:", ""));
  1552. playFrom = TABS
  1553. } else {
  1554. let p_tab = p.tabs.split(";")[0];
  1555. let vHeader = _pdfa(html, p_tab);
  1556. console.log(vHeader.length);
  1557. let tab_text = p.tab_text || "body&&Text";
  1558. let new_map = {};
  1559. for (let v of vHeader) {
  1560. let v_title = _pdfh(v, tab_text)
  1561. .trim();
  1562. console.log(v_title);
  1563. if (tab_exclude && new RegExp(tab_exclude)
  1564. .test(v_title)) {
  1565. continue
  1566. }
  1567. if (!new_map.hasOwnProperty(v_title)) {
  1568. new_map[v_title] = 1
  1569. } else {
  1570. new_map[v_title] += 1
  1571. }
  1572. if (new_map[v_title] > 1) {
  1573. v_title += Number(new_map[v_title] - 1)
  1574. }
  1575. playFrom.push(v_title)
  1576. }
  1577. }
  1578. console.log(JSON.stringify(playFrom))
  1579. } else {
  1580. playFrom = ["道长在线"]
  1581. }
  1582. vod.vod_play_from = playFrom.join(vod_play_from);
  1583. let vod_play_url = "$$$";
  1584. let vod_tab_list = [];
  1585. if (p.lists) {
  1586. if (p.lists.startsWith("js:")) {
  1587. print("开始执行lists代码:" + p.lists);
  1588. try {
  1589. var input = MY_URL;
  1590. var play_url = "";
  1591. eval(p.lists.replace("js:", ""));
  1592. for (let i in LISTS) {
  1593. if (LISTS.hasOwnProperty(i)) {
  1594. try {
  1595. LISTS[i] = LISTS[i].map(it => it.split("$")
  1596. .slice(0, 2)
  1597. .join("$"))
  1598. } catch (e) {
  1599. print("格式化LISTS发生错误:" + e.message)
  1600. }
  1601. }
  1602. }
  1603. vod_play_url = LISTS.map(it => it.join("#"))
  1604. .join(vod_play_url)
  1605. } catch (e) {
  1606. print("js执行lists: 发生错误:" + e.message)
  1607. }
  1608. } else {
  1609. let list_text = p.list_text || "body&&Text";
  1610. let list_url = p.list_url || "a&&href";
  1611. let is_tab_js = p.tabs.trim()
  1612. .startsWith("js:");
  1613. for (let i = 0; i < playFrom.length; i++) {
  1614. let tab_name = playFrom[i];
  1615. let tab_ext = p.tabs.split(";")
  1616. .length > 1 && !is_tab_js ? p.tabs.split(";")[1] : "";
  1617. let p1 = p.lists.replaceAll("#idv", tab_name)
  1618. .replaceAll("#id", i);
  1619. tab_ext = tab_ext.replaceAll("#idv", tab_name)
  1620. .replaceAll("#id", i);
  1621. let tabName = tab_ext ? _pdfh(html, tab_ext) : tab_name;
  1622. console.log(tabName);
  1623. let new_vod_list = [];
  1624. let tt1 = (new Date)
  1625. .getTime();
  1626. if (typeof pdfl === "function") {
  1627. new_vod_list = pdfl(html, p1, list_text, list_url, MY_URL)
  1628. } else {
  1629. let vodList = [];
  1630. try {
  1631. vodList = _pdfa(html, p1);
  1632. console.log("len(vodList):" + vodList.length)
  1633. } catch (e) {}
  1634. for (let i = 0; i < vodList.length; i++) {
  1635. let it = vodList[i];
  1636. new_vod_list.push(_pdfh(it, list_text)
  1637. .trim() + "$" + _pd(it, list_url, MY_URL))
  1638. }
  1639. }
  1640. if (new_vod_list.length > 0) {
  1641. new_vod_list = forceOrder(new_vod_list, "", x => x.split("$")[0]);
  1642. console.log(`drpy影响性能代码共计列表数循环次数:${new_vod_list.length},耗时:${(new Date).getTime()-tt1}毫秒`)
  1643. }
  1644. let vlist = new_vod_list.join("#");
  1645. vod_tab_list.push(vlist)
  1646. }
  1647. vod_play_url = vod_tab_list.join(vod_play_url)
  1648. }
  1649. }
  1650. vod.vod_play_url = vod_play_url
  1651. }
  1652. if (rule.图片替换 && rule.图片替换.includes("=>")) {
  1653. let replace_from = rule.图片替换.split("=>")[0];
  1654. let replace_to = rule.图片替换.split("=>")[1];
  1655. vod.vod_pic = vod.vod_pic.replace(replace_from, replace_to)
  1656. }
  1657. if (rule.图片来源 && vod.vod_pic && vod.vod_pic.startsWith("http")) {
  1658. vod.vod_pic = vod.vod_pic + rule.图片来源
  1659. }
  1660. if (!vod.vod_id || vod_id.includes("$") && vod.vod_id !== vod_id) {
  1661. vod.vod_id = vod_id
  1662. }
  1663. let t2 = (new Date)
  1664. .getTime();
  1665. console.log(`加载二级界面${MY_URL}耗时:${t2-t1}毫秒`);
  1666. vod = vodDeal(vod);
  1667. return JSON.stringify({
  1668. list: [vod]
  1669. })
  1670. }
  1671. function get_tab_index(vod) {
  1672. let obj = {};
  1673. vod.vod_play_from.split("$$$")
  1674. .forEach((it, index) => {
  1675. obj[it] = index
  1676. });
  1677. return obj
  1678. }
  1679. function vodDeal(vod) {
  1680. let vod_play_from = vod.vod_play_from.split("$$$");
  1681. let vod_play_url = vod.vod_play_url.split("$$$");
  1682. let tab_removed_list = vod_play_from;
  1683. let tab_ordered_list = vod_play_from;
  1684. let tab_renamed_list = vod_play_from;
  1685. let tab_list = vod_play_from;
  1686. let play_ordered_list = vod_play_url;
  1687. if (rule.tab_remove && rule.tab_remove.length > 0 || rule.tab_order && rule.tab_order.length > 0) {
  1688. let tab_index_dict = get_tab_index(vod);
  1689. if (rule.tab_remove && rule.tab_remove.length > 0) {
  1690. tab_removed_list = vod_play_from.filter(it => !rule.tab_remove.includes(it));
  1691. tab_list = tab_removed_list
  1692. }
  1693. if (rule.tab_order && rule.tab_order.length > 0) {
  1694. let tab_order = rule.tab_order;
  1695. tab_ordered_list = tab_removed_list.sort((a, b) => {
  1696. return (tab_order.indexOf(a) === -1 ? 9999 : tab_order.indexOf(a)) - (tab_order.indexOf(b) === -1 ? 9999 : tab_order.indexOf(b))
  1697. });
  1698. tab_list = tab_ordered_list
  1699. }
  1700. play_ordered_list = tab_list.map(it => vod_play_url[tab_index_dict[it]])
  1701. }
  1702. if (rule.tab_rename && typeof rule.tab_rename === "object" & Object.keys(rule.tab_rename)
  1703. .length > 0) {
  1704. tab_renamed_list = tab_list.map(it => rule.tab_rename[it] || it);
  1705. tab_list = tab_renamed_list
  1706. }
  1707. vod.vod_play_from = tab_list.join("$$$");
  1708. vod.vod_play_url = play_ordered_list.join("$$$");
  1709. return vod
  1710. }
  1711. function tellIsJx(url) {
  1712. try {
  1713. let is_vip = !/\.(m3u8|mp4|m4a)$/.test(url.split("?")[0]) && 是否正版(url);
  1714. return is_vip ? 1 : 0
  1715. } catch (e) {
  1716. return 1
  1717. }
  1718. }
  1719. function playParse(playObj) {
  1720. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1721. MY_URL = playObj.url;
  1722. var MY_FLAG = playObj.flag;
  1723. if (!/http/.test(MY_URL)) {
  1724. try {
  1725. MY_URL = base64Decode(MY_URL)
  1726. } catch (e) {}
  1727. }
  1728. MY_URL = decodeURIComponent(MY_URL);
  1729. var input = MY_URL;
  1730. var flag = MY_FLAG;
  1731. let common_play = {
  1732. parse: 1,
  1733. url: input,
  1734. flag: flag,
  1735. jx: tellIsJx(input)
  1736. };
  1737. let lazy_play;
  1738. if (!rule.play_parse || !rule.lazy) {
  1739. lazy_play = common_play
  1740. } else if (rule.play_parse && rule.lazy && typeof rule.lazy === "string") {
  1741. try {
  1742. let lazy_code = rule.lazy.replace("js:", "")
  1743. .trim();
  1744. print("开始执行js免嗅=>" + lazy_code);
  1745. eval(lazy_code);
  1746. lazy_play = typeof input === "object" ? input : {
  1747. parse: 1,
  1748. jx: tellIsJx(input),
  1749. url: input
  1750. }
  1751. } catch (e) {
  1752. print("js免嗅错误:" + e.message);
  1753. lazy_play = common_play
  1754. }
  1755. } else {
  1756. lazy_play = common_play
  1757. }
  1758. if (Array.isArray(rule.play_json) && rule.play_json.length > 0) {
  1759. let web_url = lazy_play.url;
  1760. for (let pjson of rule.play_json) {
  1761. if (pjson.re && (pjson.re === "*" || web_url.match(new RegExp(pjson.re)))) {
  1762. if (pjson.json && typeof pjson.json === "object") {
  1763. let base_json = pjson.json;
  1764. lazy_play = Object.assign(lazy_play, base_json);
  1765. break
  1766. }
  1767. }
  1768. }
  1769. } else if (rule.play_json && !Array.isArray(rule.play_json)) {
  1770. let base_json = {
  1771. jx: 1,
  1772. parse: 1
  1773. };
  1774. lazy_play = Object.assign(lazy_play, base_json)
  1775. } else if (!rule.play_json) {
  1776. let base_json = {
  1777. jx: 0,
  1778. parse: 1
  1779. };
  1780. lazy_play = Object.assign(lazy_play, base_json)
  1781. }
  1782. console.log(JSON.stringify(lazy_play));
  1783. return JSON.stringify(lazy_play)
  1784. }
  1785. function proxyParse(proxyObj) {
  1786. var input = proxyObj.params;
  1787. if (proxyObj.proxy_rule) {
  1788. log("准备执行本地代理规则:\n" + proxyObj.proxy_rule);
  1789. try {
  1790. eval(proxyObj.proxy_rule);
  1791. if (input && input !== proxyObj.params && Array.isArray(input) && input.length === 3) {
  1792. return input
  1793. } else {
  1794. return [404, "text/plain", "Not Found"]
  1795. }
  1796. } catch (e) {
  1797. return [500, "text/plain", "代理规则错误:" + e.message]
  1798. }
  1799. } else {
  1800. return [404, "text/plain", "Not Found"]
  1801. }
  1802. }
  1803. function isVideoParse(isVideoObj) {
  1804. var input = isVideoObj.url;
  1805. if (!isVideoObj.t) {
  1806. let re_matcher = new RegExp(isVideoObj.isVideo, "i");
  1807. return re_matcher.test(input)
  1808. } else {
  1809. try {
  1810. eval(isVideoObj.isVideo);
  1811. if (typeof input === "boolean") {
  1812. return input
  1813. } else {
  1814. return false
  1815. }
  1816. } catch (e) {
  1817. log("执行嗅探规则发生错误:" + e.message);
  1818. return false
  1819. }
  1820. }
  1821. }
  1822. function init(ext) {
  1823. console.log("init");
  1824. try {
  1825. let muban = 模板.getMubans();
  1826. if (typeof ext == "object") {
  1827. rule = ext
  1828. } else if (typeof ext == "string") {
  1829. if (ext.startsWith("http")) {
  1830. let js = request(ext, {
  1831. method: "GET"
  1832. });
  1833. if (js) {
  1834. eval(js.replace("var rule", "rule"))
  1835. }
  1836. } else {
  1837. eval(ext.replace("var rule", "rule"))
  1838. }
  1839. }
  1840. if (rule.模板 && muban.hasOwnProperty(rule.模板)) {
  1841. print("继承模板:" + rule.模板);
  1842. rule = Object.assign(muban[rule.模板], rule)
  1843. }
  1844. let rule_cate_excludes = (rule.cate_exclude || "")
  1845. .split("|")
  1846. .filter(it => it.trim());
  1847. let rule_tab_excludes = (rule.tab_exclude || "")
  1848. .split("|")
  1849. .filter(it => it.trim());
  1850. rule_cate_excludes = rule_cate_excludes.concat(CATE_EXCLUDE.split("|")
  1851. .filter(it => it.trim()));
  1852. rule_tab_excludes = rule_tab_excludes.concat(TAB_EXCLUDE.split("|")
  1853. .filter(it => it.trim()));
  1854. rule.cate_exclude = rule_cate_excludes.join("|");
  1855. rule.tab_exclude = rule_tab_excludes.join("|");
  1856. rule.host = (rule.host || "")
  1857. .rstrip("/");
  1858. HOST = rule.host;
  1859. if (rule.hostJs) {
  1860. console.log(`检测到hostJs,准备执行...`);
  1861. try {
  1862. eval(rule.hostJs);
  1863. rule.host = HOST.rstrip("/")
  1864. } catch (e) {
  1865. console.log(`执行${rule.hostJs}获取host发生错误:` + e.message)
  1866. }
  1867. }
  1868. rule.url = rule.url || "";
  1869. rule.double = rule.double || false;
  1870. rule.homeUrl = rule.homeUrl || "";
  1871. rule.detailUrl = rule.detailUrl || "";
  1872. rule.searchUrl = rule.searchUrl || "";
  1873. rule.homeUrl = rule.host && rule.homeUrl ? urljoin(rule.host, rule.homeUrl) : rule.homeUrl || rule.host;
  1874. rule.detailUrl = rule.host && rule.detailUrl ? urljoin(rule.host, rule.detailUrl) : rule.detailUrl;
  1875. rule.二级访问前 = rule.二级访问前 || "";
  1876. if (rule.url.includes("[") && rule.url.includes("]")) {
  1877. let u1 = rule.url.split("[")[0];
  1878. let u2 = rule.url.split("[")[1].split("]")[0];
  1879. rule.url = rule.host && rule.url ? urljoin(rule.host, u1) + "[" + urljoin(rule.host, u2) + "]" : rule.url
  1880. } else {
  1881. rule.url = rule.host && rule.url ? urljoin(rule.host, rule.url) : rule.url
  1882. }
  1883. if (rule.searchUrl.includes("[") && rule.searchUrl.includes("]") && !rule.searchUrl.includes("#")) {
  1884. let u1 = rule.searchUrl.split("[")[0];
  1885. let u2 = rule.searchUrl.split("[")[1].split("]")[0];
  1886. rule.searchUrl = rule.host && rule.searchUrl ? urljoin(rule.host, u1) + "[" + urljoin(rule.host, u2) + "]" : rule.searchUrl
  1887. } else {
  1888. rule.searchUrl = rule.host && rule.searchUrl ? urljoin(rule.host, rule.searchUrl) : rule.searchUrl
  1889. }
  1890. rule.timeout = rule.timeout || 5e3;
  1891. rule.encoding = rule.编码 || rule.encoding || "utf-8";
  1892. rule.search_encoding = rule.搜索编码 || rule.search_encoding || "";
  1893. rule.图片来源 = rule.图片来源 || "";
  1894. rule.图片替换 = rule.图片替换 || "";
  1895. rule.play_json = rule.hasOwnProperty("play_json") ? rule.play_json : [];
  1896. rule.pagecount = rule.hasOwnProperty("pagecount") ? rule.pagecount : {};
  1897. rule.proxy_rule = rule.hasOwnProperty("proxy_rule") ? rule.proxy_rule : "";
  1898. rule.sniffer = rule.hasOwnProperty("sniffer") ? rule.sniffer : "";
  1899. rule.sniffer = !! (rule.sniffer && rule.sniffer !== "0" && rule.sniffer !== "false");
  1900. rule.isVideo = rule.hasOwnProperty("isVideo") ? rule.isVideo : "";
  1901. rule.tab_remove = rule.hasOwnProperty("tab_remove") ? rule.tab_remove : [];
  1902. rule.tab_order = rule.hasOwnProperty("tab_order") ? rule.tab_order : [];
  1903. rule.tab_rename = rule.hasOwnProperty("tab_rename") ? rule.tab_rename : {};
  1904. if (rule.headers && typeof rule.headers === "object") {
  1905. try {
  1906. let header_keys = Object.keys(rule.headers);
  1907. for (let k of header_keys) {
  1908. if (k.toLowerCase() === "user-agent") {
  1909. let v = rule.headers[k];
  1910. console.log(v);
  1911. if (["MOBILE_UA", "PC_UA", "UC_UA", "IOS_UA", "UA"].includes(v)) {
  1912. rule.headers[k] = eval(v)
  1913. }
  1914. } else if (k.toLowerCase() === "cookie") {
  1915. let v = rule.headers[k];
  1916. if (v && v.startsWith("http")) {
  1917. console.log(v);
  1918. try {
  1919. v = fetch(v);
  1920. console.log(v);
  1921. rule.headers[k] = v
  1922. } catch (e) {
  1923. console.log(`${v}获取cookie发生错误:` + e.message)
  1924. }
  1925. }
  1926. }
  1927. }
  1928. } catch (e) {
  1929. console.log("处理headers发生错误:" + e.message)
  1930. }
  1931. }
  1932. rule_fetch_params = {
  1933. headers: rule.headers || false,
  1934. timeout: rule.timeout,
  1935. encoding: rule.encoding
  1936. };
  1937. oheaders = rule.headers || {};
  1938. RKEY = typeof key !== "undefined" && key ? key : "drpy_" + (rule.title || rule.host);
  1939. pre();
  1940. init_test()
  1941. } catch (e) {
  1942. console.log("init_test发生错误:" + e.message)
  1943. }
  1944. }
  1945. let homeHtmlCache = undefined;
  1946. function home(filter) {
  1947. console.log("home");
  1948. let homeObj = {
  1949. filter: rule.filter || false,
  1950. MY_URL: rule.homeUrl,
  1951. class_name: rule.class_name || "",
  1952. class_url: rule.class_url || "",
  1953. class_parse: rule.class_parse || "",
  1954. cate_exclude: rule.cate_exclude
  1955. };
  1956. return homeParse(homeObj)
  1957. }
  1958. function homeVod(params) {
  1959. console.log("homeVod");
  1960. let homeVodObj = {
  1961. "推荐": rule.推荐,
  1962. double: rule.double,
  1963. homeUrl: rule.homeUrl,
  1964. detailUrl: rule.detailUrl
  1965. };
  1966. return homeVodParse(homeVodObj)
  1967. }
  1968. function category(tid, pg, filter, extend) {
  1969. let cateObj = {
  1970. url: rule.url,
  1971. "一级": rule.一级,
  1972. tid: tid,
  1973. pg: parseInt(pg),
  1974. filter: filter,
  1975. extend: extend
  1976. };
  1977. return categoryParse(cateObj)
  1978. }
  1979. function detail(vod_url) {
  1980. let orId = vod_url;
  1981. let fyclass = "";
  1982. log("orId:" + orId);
  1983. if (vod_url.indexOf("$") > -1) {
  1984. let tmp = vod_url.split("$");
  1985. fyclass = tmp[0];
  1986. vod_url = tmp[1]
  1987. }
  1988. let detailUrl = vod_url.split("@@")[0];
  1989. let url;
  1990. if (!detailUrl.startsWith("http") && !detailUrl.includes("/")) {
  1991. url = rule.detailUrl.replaceAll("fyid", detailUrl)
  1992. .replaceAll("fyclass", fyclass)
  1993. } else if (detailUrl.includes("/")) {
  1994. url = urljoin(rule.homeUrl, detailUrl)
  1995. } else {
  1996. url = detailUrl
  1997. }
  1998. let detailObj = {
  1999. orId: orId,
  2000. url: url,
  2001. "二级": rule.二级,
  2002. "二级访问前": rule.二级访问前,
  2003. detailUrl: detailUrl,
  2004. fyclass: fyclass,
  2005. tab_exclude: rule.tab_exclude
  2006. };
  2007. return detailParse(detailObj)
  2008. }
  2009. function play(flag, id, flags) {
  2010. let playObj = {
  2011. url: id,
  2012. flag: flag,
  2013. flags: flags
  2014. };
  2015. return playParse(playObj)
  2016. }
  2017. function search(wd, quick, pg) {
  2018. if (rule.search_encoding) {
  2019. if (rule.search_encoding.toLowerCase() !== "utf-8") {
  2020. wd = encodeStr(wd, rule.search_encoding)
  2021. }
  2022. } else if (rule.encoding && rule.encoding.toLowerCase() !== "utf-8") {
  2023. wd = encodeStr(wd, rule.encoding)
  2024. }
  2025. let searchObj = {
  2026. searchUrl: rule.searchUrl,
  2027. "搜索": rule.搜索,
  2028. wd: wd,
  2029. pg: pg || 1,
  2030. quick: quick
  2031. };
  2032. return searchParse(searchObj)
  2033. }
  2034. function proxy(params) {
  2035. if (rule.proxy_rule && rule.proxy_rule.trim()) {
  2036. rule.proxy_rule = rule.proxy_rule.trim()
  2037. }
  2038. if (rule.proxy_rule.startsWith("js:")) {
  2039. rule.proxy_rule = rule.proxy_rule.replace("js:", "")
  2040. }
  2041. let proxyObj = {
  2042. params: params,
  2043. proxy_rule: rule.proxy_rule
  2044. };
  2045. return proxyParse(proxyObj)
  2046. }
  2047. function sniffer() {
  2048. let enable_sniffer = rule.sniffer || false;
  2049. if (enable_sniffer) {
  2050. log("开始执行辅助嗅探代理规则...")
  2051. }
  2052. return enable_sniffer
  2053. }
  2054. function isVideo(url) {
  2055. let t = 0;
  2056. let is_video;
  2057. if (rule.isVideo && rule.isVideo.trim()) {
  2058. is_video = rule.isVideo.trim()
  2059. }
  2060. if (is_video.startsWith("js:")) {
  2061. is_video = is_video.replace("js:", "");
  2062. t = 1
  2063. }
  2064. let isVideoObj = {
  2065. url: url,
  2066. isVideo: is_video,
  2067. t: t
  2068. };
  2069. let result = isVideoParse(isVideoObj);
  2070. if (result) {
  2071. log("成功执行辅助嗅探规则并检测到视频地址:\n" + rule.isVideo)
  2072. }
  2073. return result
  2074. }
  2075. function DRPY() {
  2076. return {
  2077. init: init,
  2078. home: home,
  2079. homeVod: homeVod,
  2080. category: category,
  2081. detail: detail,
  2082. play: play,
  2083. search: search,
  2084. proxy: proxy,
  2085. sniffer: sniffer,
  2086. isVideo: isVideo
  2087. }
  2088. }
  2089. export
  2090. default {
  2091. init: init,
  2092. home: home,
  2093. homeVod: homeVod,
  2094. category: category,
  2095. detail: detail,
  2096. play: play,
  2097. search: search,
  2098. proxy: proxy,
  2099. sniffer: sniffer,
  2100. isVideo: isVideo,
  2101. DRPY: DRPY
  2102. };