drpy.js 70 KB

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