drpy2.min.js 84 KB

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