drpy2.js 72 KB

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