drpy2.js 71 KB

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