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.

1923 lines
66 KiB

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