drpy.min.js 77 KB

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