drpy.js 80 KB

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