drpy模板.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941
  1. import ch from './cheerio.min.js';
  2. // import Uri from './uri.min.js';
  3. // var URI = require('urijs');
  4. // import 模板 from 'https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/js/模板.js'
  5. // var rule = Object.assign(模板.首图2,{
  6. // host: 'https://www.zbkk.net',
  7. // });
  8. import template from 'https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/txt/pluto/template-web.js'
  9. var ahtml = template.render('hi, <%=value%>.', {value: 'aui'});
  10. console.log(ahtml);
  11. const key = 'drpy_zbk';
  12. // 二进制数据流
  13. // let d = req('https://www.baidu.com/favicon.ico', {
  14. // buffer: 1
  15. // });
  16. // // header
  17. // console.log(JSON.stringify(d.headers));
  18. // // 图片
  19. // let array = [];
  20. // for(var i in d.content){
  21. // array.push(d.content[i]);
  22. // }
  23. // console.log(array.length);
  24. // let outbuf = new Uint8Array(array);
  25. // console.log(outbuf.byteLength);
  26. // base64
  27. let d = req('https://www.baidu.com/favicon.ico', {
  28. buffer: 2
  29. });
  30. // header
  31. console.log(JSON.stringify(d.headers));
  32. // 图片 base64
  33. console.log(d.content);
  34. let rule = {
  35. title: '真不卡',
  36. host: 'https://www.zbkk.net',
  37. url: '/vodshow/fyclass--------fypage---.html',
  38. searchUrl:'/vodsearch/**----------fypage---.html',
  39. // headers: {
  40. // 'User-Agent': MOBILE_UA
  41. // },
  42. // play_parse:true,
  43. // lazy:'',
  44. class_parse: 'body&&.stui-header__menu .dropdown li:gt(0):lt(5);a&&Text;a&&href;.*/(.*?).html',
  45. 一级: 'body&&.stui-vodlist li;a&&title;a&&data-original;.pic-text&&Text;a&&href',
  46. 推荐:'body&&ul.stui-vodlist.clearfix;body&&li;a&&title;.lazyload&&data-original;.pic-text&&Text;a&&href',
  47. 二级:{"title":".stui-content__detail .title&&Text;.stui-content__detail p:eq(-2)&&Text","img":".stui-content__thumb .lazyload&&data-original","desc":".stui-content__detail p:eq(0)&&Text;.stui-content__detail p:eq(1)&&Text;.stui-content__detail p:eq(2)&&Text","content":".detail&&Text","tabs":"body&&h3.title","lists":".stui-content__playlist,#id&&li"},
  48. double:true, // 推荐内容是否双层定位
  49. //搜索:'ul.stui-vodlist__media:eq(0) li,ul.stui-vodlist:eq(0) li,#searchList li;a&&title;.lazyload&&data-original;.text-muted&&Text;a&&href;.text-muted:eq(-1)&&Text',
  50. 搜索:'body&&ul.stui-vodlist__media&&li;a&&title;.lazyload&&data-original;.text-muted&&Text;a&&href;.text-muted:eq(-1)&&Text',
  51. // cate_exclude: '首页|留言|APP|下载|资讯|新闻|动态',
  52. // tab_exclude: '猜你|喜欢|APP|下载|剧情',
  53. }
  54. /****上面才是pluto的drpy源,支持import外部模板来继承修改
  55. * 已知问题记录:
  56. * 1.pdfa没法正确获取非body开头的直接定位列表,比如 推荐 body&&ul.stui-vodlist.clearfix 和 ul.stui-vodlist.clearfix 获取出来的列表不一样,建议自动补body
  57. * 2.pd函数有问题,没法正确的urljoin来源链接,比如分类页获取到数据href为/zbkdetail/63174.html应该自动与rule.url拼接后才返回给二级完整链接
  58. * .stui-pannel_hd h3 这个pdfa都没法识别?
  59. * pdf 系列不支持eq定位?
  60. * 解析播放问题,parse返回的1怎么下面不出解析选项 ?? 不过可以通免
  61. * urljoin问题,求求了这个函数很重要,还要pd函数内部需要自动urljoin
  62. * 请求重复问题,调试日志一个console总是打印两次??
  63. * 筛选功能暂未实现,搜索验证码暂未实现
  64. * quickjs发生一次崩溃后除非重启软件,否则该源后续操作点击二级都没有数据
  65. * setItem系列存在问题,用的公用变量实现没法持久化,需要一个数据库存储持久化,下次进来也能获取储存的cookie
  66. * 电脑看日志调试
  67. adb connect 192.168.10.192
  68. adb devices -l
  69. adb logcat -c
  70. adb logcat | grep -i QuickJS
  71. * ***/
  72. /*** 以下是内置变量和解析方法 **/
  73. 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';
  74. 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';
  75. const UA = 'Mozilla/5.0';
  76. 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';
  77. 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';
  78. const RULE_CK = 'cookie'; // 源cookie的key值
  79. const KEY = typeof(key)!=='undefined'&&key?key:'drpy_'+rule.title; // 源的唯一标识
  80. const CATE_EXCLUDE = '首页|留言|APP|下载|资讯|新闻|动态';
  81. const TAB_EXCLUDE = '猜你|喜欢|APP|下载|剧情|热播';
  82. const OCR_RETRY = 3;//ocr验证重试次数
  83. const OCR_API = 'http://dm.mudery.com:10000';//ocr在线识别接口
  84. var MY_URL; // 全局注入变量,pd函数需要
  85. /** 处理一下 rule规则关键字段没传递的情况 **/
  86. rule.cate_exclude = (rule.cate_exclude||'')+CATE_EXCLUDE;
  87. rule.tab_exclude = (rule.tab_exclude||'')+TAB_EXCLUDE;
  88. rule.host = rule.host||'';
  89. rule.url = rule.url||'';
  90. rule.homeUrl = rule.homeUrl||'';
  91. rule.searchUrl = rule.searchUrl||'';
  92. /*** 后台需要实现的java方法并注入到js中 ***/
  93. /**
  94. * 读取本地文件->应用程序目录
  95. * @param filePath
  96. * @returns {string}
  97. */
  98. function readFile(filePath){
  99. filePath = filePath||'./uri.min.js';
  100. var fd = os.open(filePath);
  101. var buffer = new ArrayBuffer(1024);
  102. var len = os.read(fd, buffer, 0, 1024);
  103. console.log(len);
  104. let text = String.fromCharCode.apply(null, new Uint8Array(buffer));
  105. console.log(text);
  106. return text
  107. }
  108. /**
  109. * 验证码识别逻辑,需要java实现(js没有bytes类型,无法调用后端的传递图片二进制获取验证码文本的接口)
  110. * @type {{api: string, classification: (function(*=): string)}}
  111. */
  112. var OcrApi={
  113. api:OCR_API,
  114. classification:function (img){ // img是byte类型,这里不方便搞啊
  115. let code = '';
  116. try {
  117. code = request(this.api,{data:img,headers:{'user-agent':PC_UA},'method':'POST'});
  118. }catch (e) {}
  119. return code
  120. }
  121. };
  122. /**
  123. * 验证码识别,暂未实现
  124. * @param url 验证码图片链接
  125. * @returns {string} 验证成功后的cookie
  126. */
  127. function verifyCode(url){
  128. let cnt = 0;
  129. let host = getHome(url);
  130. let cookie = '';
  131. while (cnt < OCR_RETRY){
  132. try{
  133. // let obj = {headers:headers,timeout:timeout};
  134. let img = request(`${host}/index.php/verify/index.html`);
  135. let code = OcrApi.classification(img);
  136. console.log(`第${cnt+1}次验证码识别结果:${code}`);
  137. let html = request(`${host}/index.php/ajax/verify_check?type=search&verify=${code}`,{'method':'POST'});
  138. html = JSON.parse(html);
  139. if(html.msg === 'ok'){
  140. cookie = '';
  141. return cookie // 需要返回cookie
  142. }
  143. }catch (e) {
  144. console.log(`第${cnt+1}次验证码提交失败`)
  145. }
  146. cnt+=1
  147. }
  148. return cookie
  149. }
  150. /**
  151. * 存在数据库配置表里, key字段对应值value,没有就新增,有就更新,调用此方法会清除key对应的内存缓存
  152. * @param k 键
  153. * @param v 值
  154. */
  155. function setItem(k,v){
  156. local.set(KEY,k,v);
  157. console.log(`规则${KEY}设置${k} => ${v}`)
  158. }
  159. /**
  160. * 获取数据库配置表对应的key字段的value,没有这个key就返回value默认传参.需要有缓存,第一次获取后会存在内存里
  161. * @param k 键
  162. * @param v 值
  163. * @returns {*}
  164. */
  165. function getItem(k,v){
  166. return local.get(KEY,k) || v;
  167. }
  168. /**
  169. * 删除数据库key对应的一条数据,并清除此key对应的内存缓存
  170. * @param k
  171. */
  172. function clearItem(k){
  173. local.delete(KEY,k);
  174. }
  175. /**
  176. * url拼接(暂未实现)
  177. * @param fromPath 初始当前页面url
  178. * @param nowPath 相对当前页面url
  179. * @returns {*}
  180. */
  181. function urljoin(fromPath, nowPath) {
  182. return joinUrl(fromPath, nowPath);
  183. // fromPath = fromPath||'';
  184. // nowPath = nowPath||'';
  185. // try {
  186. // // import Uri from './uri.min.js';
  187. // // var Uri = require('./uri.min.js');
  188. // // eval(request('https://cdn.bootcdn.net/ajax/libs/URI.js/1.19.11/URI.min.js'));
  189. // // let new_uri = URI(nowPath, fromPath);
  190. // let new_uri = Uri(nowPath, fromPath);
  191. // new_uri = new_uri.toString();
  192. // // console.log(new_uri);
  193. // // return fromPath + nowPath
  194. // return new_uri
  195. // }
  196. // catch (e) {
  197. // console.log('urljoin发生错误:'+e.message);
  198. // if(nowPath.startsWith('http')){
  199. // return nowPath
  200. // }if(nowPath.startsWith('/')){
  201. // return getHome(fromPath)+nowPath
  202. // }
  203. // return fromPath+nowPath
  204. // }
  205. }
  206. /**
  207. * 重写pd方法-增加自动urljoin(没法重写,改个名继续骗)
  208. * @param html
  209. * @param parse
  210. * @param uri
  211. * @returns {*}
  212. */
  213. function pD(html,parse,uri){
  214. let ret = pdfh(html,parse);
  215. if(typeof(uri)==='undefined'||!uri){
  216. uri = '';
  217. }
  218. // MY_URL = getItem('MY_URL',MY_URL);
  219. console.log(`规则${KEY}打印MY_URL:${MY_URL},uri:${uri}`);
  220. return urljoin(MY_URL,ret)
  221. }
  222. /*** js自封装的方法 ***/
  223. /**
  224. * 获取链接的host(带http协议的完整链接)
  225. * @param url 任意一个正常完整的Url,自动提取根
  226. * @returns {string}
  227. */
  228. function getHome(url){
  229. let tmp = url.split('//');
  230. url = tmp[0] + '//' + tmp[1].split('/')[0];
  231. return url
  232. }
  233. /**
  234. * get参数编译链接,类似python params字典自动拼接
  235. * @param url 访问链接
  236. * @param obj 参数字典
  237. * @returns {*}
  238. */
  239. function buildUrl(url,obj){
  240. obj = obj||{};
  241. if(url.indexOf('?')<0){
  242. url += '?'
  243. }
  244. let param_list = [];
  245. let keys = Object.keys(obj);
  246. keys.forEach(it=>{
  247. param_list.push(it+'='+obj[it])
  248. });
  249. let prs = param_list.join('&');
  250. if(keys.length > 0 && !url.endsWith('?')){
  251. url += '&'
  252. }
  253. url+=prs;
  254. return url
  255. }
  256. /**
  257. * 海阔网页请求函数完整封装
  258. * @param url 请求链接
  259. * @param obj 请求对象 {headers:{},method:'',timeout:5000,body:'',withHeaders:false}
  260. * @returns {string|string|DocumentFragment|*}
  261. */
  262. function request(url,obj){
  263. if(typeof(obj)==='undefined'||!obj||obj==={}){
  264. obj = {
  265. headers:{
  266. 'User-Agent':MOBILE_UA,
  267. 'Referer':getHome(url),
  268. }
  269. }
  270. }else{
  271. let headers = obj.headers||{};
  272. let keys = Object.keys(headers).map(it=>it.toLowerCase());
  273. if(!keys.includes('user-agent')){
  274. headers['User-Agent'] = MOBILE_UA;
  275. }if(!keys.includes('referer')){
  276. headers['Referer'] = getHome(url);
  277. }
  278. obj.headers = headers;
  279. }
  280. if(obj.headers.body&&typeof (obj.headers.body)==='string'){
  281. let data = {};
  282. obj.headers.body.split('&').forEach(it=>{
  283. data[it.split('=')[0]] = it.split('=')[1]
  284. });
  285. obj.data = data;
  286. delete obj.headers.body
  287. }
  288. let res = req(url, obj);
  289. let html = res.content||'';
  290. return html
  291. }
  292. /**
  293. * 检查宝塔验证并自动跳过获取正确源码
  294. * @param html 之前获取的html
  295. * @param url 之前的来源url
  296. * @param obj 来源obj
  297. * @returns {string|DocumentFragment|*}
  298. */
  299. function checkHtml(html,url,obj){
  300. if(/\?btwaf=/.test(html)){
  301. let btwaf = html.match(/btwaf(.*?)"/)[1];
  302. url = url.split('#')[0]+'?btwaf'+btwaf;
  303. html = request(url,obj);
  304. }
  305. return html
  306. }
  307. /**
  308. * 带一次宝塔验证的源码获取
  309. * @param url 请求链接
  310. * @param obj 请求参数
  311. * @returns {string|DocumentFragment}
  312. */
  313. function getCode(url,obj){
  314. let html = request(url,obj);
  315. html = checkHtml(html,url,obj);
  316. return html
  317. }
  318. /**
  319. * 源rule专用的请求方法,自动注入cookie
  320. * @param url 请求链接
  321. * @returns {string|DocumentFragment}
  322. */
  323. function getHtml(url){
  324. let obj = {};
  325. if(rule.headers){
  326. obj.headers = rule.headers;
  327. }
  328. let cookie = getItem(RULE_CK,'');
  329. if(cookie){
  330. if(obj.headers && ! Object.keys(obj.headers).map(it=>it.toLowerCase()).includes('cookie')){
  331. obj.headers['Cookie'] = cookie;
  332. }else if(!obj.headers){
  333. obj.headers = {Cookie:cookie};
  334. }
  335. }
  336. let html = getCode(url,obj);
  337. return html
  338. }
  339. /**
  340. * 首页分类解析,筛选暂未实现
  341. * @param homeObj 首页传参对象
  342. * @returns {string}
  343. */
  344. function homeParse(homeObj) {
  345. let classes = [];
  346. if (homeObj.class_name && homeObj.class_url) {
  347. let names = homeObj.class_name.split('&');
  348. let urls = homeObj.class_url.split('&');
  349. let cnt = Math.min(names.length, urls.length);
  350. for (let i = 0; i < cnt; i++) {
  351. classes.push({
  352. 'type_id': urls[i],
  353. 'type_name': names[i]
  354. });
  355. }
  356. }
  357. if (homeObj.class_parse) {
  358. let p = homeObj.class_parse.split(';');
  359. if (p.length >= 4) {
  360. try {
  361. let html = getHtml(homeObj.MY_URL);
  362. if (html) {
  363. let list = pdfa(html, p[0]);
  364. if (list && list.length > 0) {
  365. list.forEach(it => {
  366. try {
  367. let name = pdfh(it, p[1]);
  368. if (homeObj.cate_exclude && (new RegExp(homeObj.cate_exclude).test(name))) {
  369. return;
  370. }
  371. let url = pdfh(it, p[2]);
  372. if (p[3]) {
  373. let exp = new RegExp(p[3]);
  374. url = url.match(exp)[1];
  375. }
  376. classes.push({
  377. 'type_id': url,
  378. 'type_name': name
  379. });
  380. } catch (e) {
  381. console.log(e.message);
  382. }
  383. });
  384. }
  385. }
  386. } catch (e) {
  387. console.log(e.message);
  388. }
  389. }
  390. }
  391. return JSON.stringify({
  392. 'class': classes
  393. });
  394. }
  395. /**
  396. * 首页推荐列表解析
  397. * @param homeVodObj
  398. * @returns {string}
  399. */
  400. function homeVodParse(homeVodObj){
  401. let p = homeVodObj.推荐 ? homeVodObj.推荐.split(';') : [];
  402. if (!homeVodObj.double && p.length < 5) {
  403. return '{}'
  404. }else if (homeVodObj.double && p.length < 6) {
  405. return '{}'
  406. }
  407. let d = [];
  408. MY_URL = homeVodObj.homeUrl;
  409. // setItem('MY_URL',MY_URL);
  410. console.log(MY_URL);
  411. let html = getHtml(MY_URL);
  412. try {
  413. console.log('double:'+homeVodObj.double);
  414. if(homeVodObj.double){
  415. p[0] = p[0].trim().startsWith('json:')?p[0].replace('json:',''):p[0];
  416. console.log(p[0]);
  417. let items = pdfa(html, p[0]);
  418. console.log(items.length);
  419. for(let item of items){
  420. console.log(p[1]);
  421. let items2 = pdfa(item,p[1]);
  422. console.log(items2.length);
  423. for(let item2 of items2){
  424. try {
  425. let title = pdfh(item2, p[2]);
  426. let img = '';
  427. try{
  428. img = pD(item2, p[3])
  429. }catch (e) {}
  430. let desc = pdfh(item2, p[4]);
  431. let links = [];
  432. for(let p5 of p[5].split('+')){
  433. let link = !homeVodObj.detailUrl?pD(item2, p5,MY_URL):pdfh(item2, p5);
  434. links.push(link);
  435. }
  436. let vod = {
  437. vod_name:title,
  438. vod_pic:img,
  439. vod_remarks:desc,
  440. vod_id:links.join('$')
  441. };
  442. d.push(vod);
  443. }catch (e) {
  444. }
  445. }
  446. }
  447. }
  448. else{
  449. p[0] = p[0].trim().startsWith('json:')?p[0].replace('json:',''):p[0];
  450. let items = pdfa(html, p[0]);
  451. for(let item of items){
  452. try {
  453. let title = pdfh(item, p[1]);
  454. let img = '';
  455. try {
  456. img = pD(item, p[2],MY_URL);
  457. }catch (e) {
  458. }
  459. let desc = pdfh(item, p[3]);
  460. let links = [];
  461. for(let p5 of p[4].split('+')){
  462. let link = !homeVodObj.detailUrl?pD(item, p5,MY_URL):pdfh(item, p5);
  463. links.push(link);
  464. }
  465. let vod = {
  466. vod_name:title,
  467. vod_pic:img,
  468. vod_remarks:desc,
  469. vod_id:links.join('$')
  470. };
  471. d.push(vod);
  472. }catch (e) {
  473. }
  474. }
  475. }
  476. }catch (e) {
  477. }
  478. // console.log(JSON.stringify(d));
  479. return JSON.stringify({
  480. list:d
  481. })
  482. }
  483. /**
  484. * 一级分类页数据解析
  485. * @param cateObj
  486. * @returns {string}
  487. */
  488. function categoryParse(cateObj) {
  489. let p = cateObj.一级 ? cateObj.一级.split(';') : [];
  490. if (p.length < 5) {
  491. return '{}'
  492. }
  493. let d = [];
  494. let url = cateObj.url.replaceAll('fyclass', cateObj.tid).replaceAll('fypage', cateObj.pg);
  495. MY_URL = url;
  496. // setItem('MY_URL',MY_URL);
  497. console.log(MY_URL);
  498. try {
  499. let html = getHtml(MY_URL);
  500. if (html) {
  501. let list = pdfa(html, p[0]);
  502. list.forEach(it => {
  503. d.push({
  504. 'vod_id': pD(it, p[4],MY_URL),
  505. 'vod_name': pdfh(it, p[1]),
  506. 'vod_pic': pD(it, p[2],MY_URL),
  507. 'vod_remarks': pdfh(it, p[3]),
  508. });
  509. });
  510. // console.log(JSON.stringify(d));
  511. return JSON.stringify({
  512. 'page': parseInt(cateObj.pg),
  513. 'pagecount': 999,
  514. 'limit': 20,
  515. 'total': 999,
  516. 'list': d,
  517. });
  518. }
  519. } catch (e) {
  520. console.log(e.message);
  521. }
  522. return '{}'
  523. }
  524. /**
  525. * 搜索列表数据解析
  526. * @param searchObj
  527. * @returns {string}
  528. */
  529. function searchParse(searchObj) {
  530. let p = searchObj.搜索 ? searchObj.搜索.split(';') : [];
  531. if (p.length < 5) {
  532. return '{}'
  533. }
  534. let d = [];
  535. let url = searchObj.searchUrl.replaceAll('**', searchObj.wd).replaceAll('fypage', searchObj.pg);
  536. MY_URL = url;
  537. // setItem('MY_URL',MY_URL);
  538. console.log(MY_URL);
  539. try {
  540. let html = getHtml(MY_URL);
  541. if (html) {
  542. if(/系统安全验证|输入验证码/.test(html)){
  543. let cookie = verifyCode(MY_URL);
  544. if(cookie){
  545. console.log(`本次成功过验证,cookie:${cookie}`);
  546. setItem(RULE_CK,cookie);
  547. }else{
  548. console.log(`本次自动过搜索验证失败,cookie:${cookie}`);
  549. }
  550. // obj.headers['Cookie'] = cookie;
  551. html = getHtml(MY_URL);
  552. }
  553. if(!html.includes(searchObj.wd)){
  554. console.log('搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码');
  555. console.log(html);
  556. }
  557. let list = pdfa(html, p[0]);
  558. list.forEach(it => {
  559. let ob = {
  560. 'vod_id': pD(it, p[4],MY_URL),
  561. 'vod_name': pdfh(it, p[1]),
  562. 'vod_pic': pD(it, p[2],MY_URL),
  563. 'vod_remarks': pdfh(it, p[3]),
  564. };
  565. if (p.length > 5 && p[5]) {
  566. ob.vod_content = pdfh(it, p[5]);
  567. }
  568. d.push(ob);
  569. });
  570. return JSON.stringify({
  571. 'page': parseInt(searchObj.pg),
  572. 'pagecount': 10,
  573. 'limit': 20,
  574. 'total': 100,
  575. 'list': d,
  576. });
  577. }
  578. } catch (e) {
  579. }
  580. return '{}'
  581. }
  582. /**
  583. * 二级详情页数据解析
  584. * @param detailObj
  585. * @returns {string}
  586. */
  587. function detailParse(detailObj){
  588. let vod = {
  589. vod_id: "id",
  590. vod_name: "片名",
  591. vod_pic: "",
  592. type_name: "剧情",
  593. vod_year: "年份",
  594. vod_area: "地区",
  595. vod_remarks: "更新信息",
  596. vod_actor: "主演",
  597. vod_director: "导演",
  598. vod_content: "简介"
  599. };
  600. let p = detailObj.二级;
  601. let url = detailObj.url;
  602. let detailUrl = detailObj.detailUrl;
  603. let fyclass = detailObj.fyclass;
  604. let tab_exclude = detailObj.tab_exclude;
  605. let html = detailObj.html||'';
  606. MY_URL = url;
  607. // setItem('MY_URL',MY_URL);
  608. // console.log(MY_URL);
  609. if(p==='*'){
  610. vod.vod_play_from = '道长在线';
  611. vod.vod_remarks = detailUrl;
  612. vod.vod_actor = '没有二级,只有一级链接直接嗅探播放';
  613. vod.vod_content = MY_URL;
  614. vod.vod_play_url = '嗅探播放$' + MY_URL;
  615. }else if(p&&typeof(p)==='object'){
  616. if(!html){
  617. html = getHtml(MY_URL);
  618. }
  619. if(p.title){
  620. let p1 = p.title.split(';');
  621. vod.vod_name = pdfh(html, p1[0]).replaceAll('\n', ' ').trim();
  622. let type_name = p1.length > 1 ? pdfh(html, p1[1]).replaceAll('\n', ' ').trim():'';
  623. vod.type_name = type_name||vod.type_name;
  624. }
  625. if(p.desc){
  626. try{
  627. let p1 = p.desc.split(';');
  628. vod.vod_remarks = pdfh(html, p1[0]).replaceAll('\n', ' ').trim();
  629. vod.vod_year = p1.length > 1 ? pdfh(html, p1[1]).replaceAll('\n', ' ').trim():'';
  630. vod.vod_area = p1.length > 2 ? pdfh(html, p1[2]).replaceAll('\n', ' ').trim():'';
  631. vod.vod_actor = p1.length > 3 ? pdfh(html, p1[3]).replaceAll('\n', ' ').trim():'';
  632. vod.vod_director = p1.length > 4 ? pdfh(html, p1[4]).replaceAll('\n', ' ').trim():'';
  633. }
  634. catch (e) {
  635. }
  636. }
  637. if(p.content){
  638. try{
  639. let p1 = p.content.split(';');
  640. vod.vod_content = pdfh(html, p1[0]).replaceAll('\n', ' ').trim();
  641. }
  642. catch (e) {}
  643. }
  644. if(p.img){
  645. try{
  646. let p1 = p.img.split(';');
  647. vod.vod_pic = pD(html, p1[0],MY_URL);
  648. }
  649. catch (e) {}
  650. }
  651. let vod_play_from = '$$$';
  652. let playFrom = [];
  653. if(p.重定向&&p.重定向.startsWith('js:')){
  654. html = eval(p.重定向.replace('js:',''));
  655. }
  656. // console.log(2);
  657. if(p.tabs){
  658. let p_tab = p.tabs.split(';')[0];
  659. console.log(p_tab);
  660. let vHeader = pdfa(html, p_tab);
  661. console.log(vHeader.length);
  662. for(let v of vHeader){
  663. let v_title = pdfh(v,'body&&Text');
  664. console.log(v_title);
  665. if(tab_exclude&& (new RegExp(tab_exclude)).test(v_title)){
  666. continue;
  667. }
  668. playFrom.push(v_title);
  669. }
  670. console.log(JSON.stringify(playFrom));
  671. }else{
  672. playFrom = ['道长在线']
  673. }
  674. vod.vod_play_from = playFrom.join(vod_play_from);
  675. // console.log(3);
  676. let vod_play_url = '$$$';
  677. let vod_tab_list = [];
  678. if(p.lists){
  679. for(let i=0;i<playFrom.length;i++){
  680. let tab_name = playFrom[i];
  681. let tab_ext = p.tabs.split(';').length > 1 ? p.tabs.split(';')[1] : '';
  682. let p1 = p.lists.replaceAll('#idv', tab_name).replaceAll('#id', i);
  683. tab_ext = tab_ext.replaceAll('#idv', tab_name).replaceAll('#id', i);
  684. console.log(p1);
  685. console.log(645);
  686. console.log(html);
  687. let vodList = [];
  688. try {
  689. vodList = pdfa(html, p1)
  690. }catch (e) {
  691. console.log(e.message)
  692. }
  693. console.log(647);
  694. console.log('len(vodList):'+vodList.length);
  695. let new_vod_list = [];
  696. let tabName = tab_ext?pdfh(html, tab_ext):tab_name;
  697. vodList.forEach(it=>{
  698. new_vod_list.push(tabName+'$'+pD(it,'a&&href',MY_URL));
  699. });
  700. let vlist = new_vod_list.join('#');
  701. vod_tab_list.push(vlist);
  702. }
  703. }
  704. vod.vod_play_url = vod_tab_list.join(vod_play_url);
  705. }
  706. // console.log(JSON.stringify(vod));
  707. return JSON.stringify({
  708. list: [vod]
  709. })
  710. }
  711. /**
  712. * 选集播放点击事件解析
  713. * @param playObj
  714. * @returns {string}
  715. */
  716. function playParse(playObj){
  717. MY_URL = playObj.url;
  718. var input = MY_URL;
  719. let common_play = {
  720. parse:1,
  721. url:MY_URL
  722. };
  723. let lazy_play;
  724. if(!rule.play_parse||!rule.lazy){
  725. lazy_play = common_play;
  726. }else if(rule.play_parse&&rule.lazy&&typeof(rule.lazy)==='string'){
  727. try {
  728. eval(rule.lazy.replace('js:').trim());
  729. lazy_play = typeof(input) === 'object'?input:{
  730. parse:1,
  731. jx:1,
  732. url:input
  733. };
  734. }catch (e) {
  735. lazy_play = common_play;
  736. }
  737. }else{
  738. lazy_play = common_play;
  739. }
  740. console.log(JSON.stringify(lazy_play));
  741. return JSON.stringify(lazy_play);
  742. }
  743. /**
  744. * js源预处理特定返回对象中的函数
  745. * @param ext
  746. */
  747. function init(ext) {
  748. console.log("init");
  749. }
  750. /**
  751. * js源获取首页分类和筛选特定返回对象中的函数
  752. * @param filter 筛选条件字典对象
  753. * @returns {string}
  754. */
  755. function home(filter) {
  756. console.log("home");
  757. let homeObj = {
  758. MY_URL: rule.host,
  759. class_name: rule.class_name || '',
  760. class_url: rule.class_url || '',
  761. class_parse: rule.class_parse || '',
  762. cate_exclude: rule.cate_exclude,
  763. };
  764. return homeParse(homeObj);
  765. }
  766. /**
  767. * js源获取首页推荐数据列表特定返回对象中的函数
  768. * @param params
  769. * @returns {string}
  770. */
  771. function homeVod(params) {
  772. let homeUrl = rule.host&&rule.homeUrl?urljoin(rule.host,rule.homeUrl):(rule.homeUrl||rule.host);
  773. let detailUrl = rule.host&&rule.detailUrl?urljoin(rule.host,rule.detailUrl):rule.detailUrl;
  774. let homeVodObj = {
  775. 推荐:rule.推荐,
  776. double:rule.double,
  777. homeUrl:homeUrl,
  778. detailUrl:detailUrl
  779. };
  780. return homeVodParse(homeVodObj)
  781. // return "{}";
  782. }
  783. /**
  784. * js源获取分类页一级数据列表特定返回对象中的函数
  785. * @param tid 分类id
  786. * @param pg 页数
  787. * @param filter 当前选中的筛选条件
  788. * @param extend 扩展
  789. * @returns {string}
  790. */
  791. function category(tid, pg, filter, extend) {
  792. let cateObj = {
  793. url: urljoin(rule.host, rule.url),
  794. 一级: rule.一级,
  795. tid: tid,
  796. pg: pg,
  797. filter: filter,
  798. extend: extend
  799. };
  800. return categoryParse(cateObj)
  801. }
  802. /**
  803. * js源获取二级详情页数据特定返回对象中的函数
  804. * @param vod_url 一级列表中的vod_id或者是带分类的自拼接 vod_id 如 fyclass$vod_id
  805. * @returns {string}
  806. */
  807. function detail(vod_url) {
  808. let fyclass = '';
  809. if(vod_url.indexOf('$')>-1){
  810. let tmp = vod_url.split('$');
  811. fyclass = tmp[0];
  812. vod_url = tmp[1];
  813. }
  814. let detailUrl = vod_url;
  815. let url;
  816. rule.homeUrl = urljoin(rule.host,rule.homeUrl);
  817. rule.detailUrl = urljoin(rule.host,rule.detailUrl);
  818. if(!detailUrl.startsWith('http')&&!detailUrl.includes('/')){
  819. url = rule.detailUrl.replaceAll('fyid', detailUrl).replaceAll('fyclass',fyclass);
  820. }else if(detailUrl.includes('/')){
  821. url = urljoin(rule.homeUrl,detailUrl);
  822. }else{
  823. url = detailUrl
  824. }
  825. let detailObj = {
  826. url:url,
  827. 二级:rule.二级,
  828. detailUrl:detailUrl,
  829. fyclass:fyclass,
  830. tab_exclude:rule.tab_exclude,
  831. }
  832. return detailParse(detailObj)
  833. }
  834. /**
  835. * js源选集按钮播放点击事件特定返回对象中的函数
  836. * @param flag 线路名
  837. * @param id 播放按钮的链接
  838. * @param flags 全局配置的flags是否需要解析的标识列表
  839. * @returns {string}
  840. */
  841. function play(flag, id, flags) {
  842. let playObj = {
  843. url:id,
  844. flag:flag,
  845. flags:flags
  846. }
  847. return playParse(playObj);
  848. }
  849. /**
  850. * js源搜索返回的数据列表特定返回对象中的函数
  851. * @param wd 搜索关键字
  852. * @param quick 是否来自快速搜索
  853. * @returns {string}
  854. */
  855. function search(wd, quick) {
  856. let searchObj = {
  857. searchUrl: urljoin(rule.host, rule.searchUrl),
  858. 搜索: rule.搜索,
  859. wd: wd,
  860. //pg: pg,
  861. pg: 1,
  862. quick: quick,
  863. };
  864. return searchParse(searchObj)
  865. }
  866. // 导出函数对象
  867. export default {
  868. init: init,
  869. home: home,
  870. homeVod: homeVod,
  871. category: category,
  872. detail: detail,
  873. play: play,
  874. search: search
  875. }