drpy2.js 74 KB

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