drpy2-2838.js 69 KB

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