From cd9b48dbec0de7af63a2f792b2ea2144aecdfe76 Mon Sep 17 00:00:00 2001 From: hjdhnx Date: Fri, 30 Sep 2022 16:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- txt/pluto/drT.js | 16 ++-- txt/pluto/drpy.js | 159 ++++++++++++++------------------------ txt/pluto/template-web.js | 3 - 3 files changed, 65 insertions(+), 113 deletions(-) delete mode 100644 txt/pluto/template-web.js diff --git a/txt/pluto/drT.js b/txt/pluto/drT.js index f05905e..8d085fb 100644 --- a/txt/pluto/drT.js +++ b/txt/pluto/drT.js @@ -153,23 +153,23 @@ //.replace(/(\s|;|\}|^|\{)out\+=''\+/g,'$1out+='); if (needhtmlencode) { - console.log('需要编码'); - console.log(c.doNotSkipEncoded); + // console.log('需要编码'); + // console.log(c.doNotSkipEncoded); if (!c.selfcontained && _globals && !_globals._encodeHTML) _globals._encodeHTML = drT.encodeHTMLSource(c.doNotSkipEncoded); str = "var encodeHTML = typeof _encodeHTML !== 'undefined' ? _encodeHTML : (" + drT.encodeHTMLSource.toString() + "(" + (c.doNotSkipEncoded || '') + "));" + str; - console.log(str); + // console.log(str); }else{ - console.log('不需要编码'); + // console.log('不需要编码'); } - console.log(c.varname); - console.log(str); + // console.log(c.varname); + // console.log(str); try { return new Function(c.varname, str); } catch (e) { /* istanbul ignore else */ - console.log(e.message); + // console.log(e.message); if (typeof console !== "undefined") console.log("Could not create a template function: " + str); throw e; } @@ -185,5 +185,5 @@ } dict = dict||{}; return drT.compile(tmpl)(dict); - } + }; }()); \ No newline at end of file diff --git a/txt/pluto/drpy.js b/txt/pluto/drpy.js index b1a1063..366fe3d 100644 --- a/txt/pluto/drpy.js +++ b/txt/pluto/drpy.js @@ -1,101 +1,22 @@ import ch from './cheerio.min.js'; -// import Uri from './uri.min.js'; -// var URI = require('urijs'); +// import 'http://192.168.10.99:5705/txt/pluto/drT.js'; // import 模板 from 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js' // var rule = Object.assign(模板.首图2,{ // host: 'https://www.zbkk.net', // }); -// import template from 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/txt/pluto/template-web.js' -// import 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/txt/pluto/template-web.js' const key = 'drpy_zbk'; -function myTem(Tem, data) { - // 检索需要填充的地方 - var reg = /{{(\w+)}}/; - var res = reg.exec(Tem) // 返回伪数组 第一个为{{name}} 第二个为 name,没有返回 null, - while (res) { - // 替换,如果有多个同名填充位,都会被填充 - Tem = Tem.replace(res[0], data[res[1]]) - // 再次检索 - res = reg.exec(Tem) - } - return Tem -} - -var TemplateEngine = function(html, options) { - - var re = /]+\)?%>/g, reExp = /(^( )?(if|for|else|switch|case|break|{|}))(.*)?/g, code = 'var r=[];\n', cursor = 0; - - var add = function(line, js) { - - js? (code += line.match(reExp) ? line + '\n' : 'r.push(' + line + ');\n') : - - (code += line != '' ? 'r.push("' + line.replace(/"/g, '\\"') + '");\n' : ''); - - return add; - - } - - while(match = re.exec(html)) { - console.log(match) - add(html.slice(cursor, match.index))(match[1], true); - - cursor = match.index + match[0].length; - - } - - add(html.substr(cursor, html.length - cursor)); - - code += 'return r.join("");'; - - return new Function(code.replace(/[\r\t\n]/g, '')).apply(options); - -} function init_test(){ - // eval(request('https://gitcode.net/qq_32394351/dr_py/-/raw/master/txt/pluto/template-web.js')); - // eval(request('http://192.168.10.99:5705/txt/pluto/template-web.js')); - // eval(request('http://192.168.10.99:5705/txt/pluto/doT.js')); - eval(request('http://192.168.10.99:5705/txt/pluto/drT.js')); - // var ahtml = template.render('hi, <%=value%>.', {value: 'aui'}); - // console.log(ahtml); - console.log(typeof(drT)) - // drT.templateSettings.varname = 'fl'; - // drT.templateSettings.interpolate = /\{\{([\s\S]+?)\}\}/g; - // var ahtml = drT.compile('hi, {{fl.value}}哈哈.{{fl.value}}')({value: 'aui'}); - // console.log(ahtml); - // ahtml = drT.compile('hi, {{fl}}哈哈.{{fl}}')({sort: 1,cate:'movie'}); - // console.log(ahtml); - // - console.log(drT.renderText('hi, {{fl}}哈哈.{{fl}}',{sort: 1,cate:'movie'},'fl')) + console.log(JSON.stringify(rule)); + // console.log(request('https://www.baidu.com',{withHeaders:true})); + console.log(request('https://www.baidu.com/favicon.ico',{toBase64:true})); + console.log("init_test"); + require('http://192.168.10.99:5705/txt/pluto/drT.js'); + console.log(typeof(drT)); + console.log(drT.renderText('{{fl.cate}},hi, {{fl}}哈哈.{{fl}}',{sort: 1,cate:'movie'},'fl')); } -// 二进制数据流 -// let d = req('https://www.baidu.com/favicon.ico', { -// buffer: 1 -// }); -// // header -// console.log(JSON.stringify(d.headers)); -// // 图片 -// let array = []; -// for(var i in d.content){ -// array.push(d.content[i]); -// } -// console.log(array.length); -// let outbuf = new Uint8Array(array); -// console.log(outbuf.byteLength); - - -// base64 -let d = req('https://www.baidu.com/favicon.ico', { - buffer: 2 -}); -// header -console.log(JSON.stringify(d.headers)); -// 图片 base64 -console.log(d.content); - - let rule = { title: '真不卡', host: 'https://www.zbkk.net', @@ -107,8 +28,8 @@ let rule = { // play_parse:true, // lazy:'', class_parse: 'body&&.stui-header__menu .dropdown li:gt(0):lt(5);a&&Text;a&&href;.*/(.*?).html', - 一级: 'body&&.stui-vodlist li;a&&title;a&&data-original;.pic-text&&Text;a&&href', - 推荐:'body&&ul.stui-vodlist.clearfix;body&&li;a&&title;.lazyload&&data-original;.pic-text&&Text;a&&href', + 一级: '.stui-vodlist li;a&&title;a&&data-original;.pic-text&&Text;a&&href', + 推荐:'ul.stui-vodlist.clearfix;body&&li;a&&title;.lazyload&&data-original;.pic-text&&Text;a&&href', 二级:{"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"}, double:true, // 推荐内容是否双层定位 //搜索:'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', @@ -120,13 +41,14 @@ let rule = { /****上面才是pluto的drpy源,支持import外部模板来继承修改 * 已知问题记录: - * 1.pdfa没法正确获取非body开头的直接定位列表,比如 推荐 body&&ul.stui-vodlist.clearfix 和 ul.stui-vodlist.clearfix 获取出来的列表不一样,建议自动补body - * 2.pd函数有问题,没法正确的urljoin来源链接,比如分类页获取到数据href为/zbkdetail/63174.html应该自动与rule.url拼接后才返回给二级完整链接 + * 自动补body逻辑可能有Bug,二级选集列表现在不正常了会报错 + * 1.pdfa没法正确获取非body开头的直接定位列表,比如 推荐 body&&ul.stui-vodlist.clearfix 和 ul.stui-vodlist.clearfix 获取出来的列表不一样,建议自动补body(已解决) + * 2. pd函数有问题,没法正确的urljoin来源链接,比如分类页获取到数据href为/zbkdetail/63174.html应该自动与rule.url拼接后才返回给二级完整链接 (已解决) * .stui-pannel_hd h3 这个pdfa都没法识别? * pdf 系列不支持eq定位? * 解析播放问题,parse返回的1怎么下面不出解析选项 ?? 不过可以通免 - * urljoin问题,求求了这个函数很重要,还要pd函数内部需要自动urljoin - * 请求重复问题,调试日志一个console总是打印两次?? + * urljoin问题,求求了这个函数很重要,还要pd函数内部需要自动urljoin (已解决) + * 请求重复问题,调试日志一个console总是打印两次??(待解决) * 筛选功能暂未实现,搜索验证码暂未实现 * quickjs发生一次崩溃后除非重启软件,否则该源后续操作点击二级都没有数据 * setItem系列存在问题,用的公用变量实现没法持久化,需要一个数据库存储持久化,下次进来也能获取储存的cookie @@ -139,7 +61,6 @@ let rule = { * ***/ - /*** 以下是内置变量和解析方法 **/ 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'; 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'; @@ -155,8 +76,13 @@ const OCR_API = 'http://dm.mudery.com:10000';//ocr在线识别接口 var MY_URL; // 全局注入变量,pd函数需要 /** 处理一下 rule规则关键字段没传递的情况 **/ -rule.cate_exclude = (rule.cate_exclude||'')+CATE_EXCLUDE; -rule.tab_exclude = (rule.tab_exclude||'')+TAB_EXCLUDE; +let rule_cate_excludes = (rule.cate_exclude||'').split('|').filter(it=>it.trim()); +let rule_tab_excludes = (rule.tab_exclude||'').split('|').filter(it=>it.trim()); +rule_cate_excludes = rule_cate_excludes.concat(CATE_EXCLUDE.split('|').filter(it=>it.trim())); +rule_tab_excludes = rule_tab_excludes.concat(TAB_EXCLUDE.split('|').filter(it=>it.trim())); + +rule.cate_exclude = rule_cate_excludes.join('\n'); +rule.tab_exclude = rule_tab_excludes.join('\n'); rule.host = rule.host||''; rule.url = rule.url||''; rule.homeUrl = rule.homeUrl||''; @@ -258,9 +184,9 @@ function clearItem(k){ * @returns {*} */ function urljoin(fromPath, nowPath) { + fromPath = fromPath||''; + nowPath = nowPath||''; return joinUrl(fromPath, nowPath); - // fromPath = fromPath||''; - // nowPath = nowPath||''; // try { // // import Uri from './uri.min.js'; // // var Uri = require('./uri.min.js'); @@ -297,7 +223,7 @@ function pD(html,parse,uri){ uri = ''; } // MY_URL = getItem('MY_URL',MY_URL); - console.log(`规则${KEY}打印MY_URL:${MY_URL},uri:${uri}`); + // console.log(`规则${KEY}打印MY_URL:${MY_URL},uri:${uri}`); return urljoin(MY_URL,ret) } @@ -309,6 +235,9 @@ function pD(html,parse,uri){ * @returns {string} */ function getHome(url){ + if(!url){ + return '' + } let tmp = url.split('//'); url = tmp[0] + '//' + tmp[1].split('/')[0]; return url @@ -338,6 +267,14 @@ function buildUrl(url,obj){ return url } +/** + * 远程依赖执行函数 + * @param url 远程js地址 + */ +function require(url){ + eval(request(url)); +} + /** * 海阔网页请求函数完整封装 * @param url 请求链接 @@ -362,7 +299,8 @@ function request(url,obj){ } obj.headers = headers; } - if(obj.headers.body&&typeof (obj.headers.body)==='string'){ + console.log(JSON.stringify(obj.headers)); + if(typeof(obj.headers.body)!='undefined'&&obj.headers.body&&typeof (obj.headers.body)==='string'){ let data = {}; obj.headers.body.split('&').forEach(it=>{ data[it.split('=')[0]] = it.split('=')[1] @@ -370,9 +308,22 @@ function request(url,obj){ obj.data = data; delete obj.headers.body } + if(!url){ + return obj.withHeaders?'{}':'' + } + if(obj.toBase64){ // 返回base64,用于请求图片 + obj.buffer = 2; + delete obj.toBase64 + } let res = req(url, obj); let html = res.content||''; - return html + if(obj.withHeaders){ + let htmlWithHeaders = res.headers; + htmlWithHeaders.body = html; + return JSON.stringify(htmlWithHeaders); + }else{ + return html + } } /** @@ -865,7 +816,11 @@ function playParse(playObj){ */ function init(ext) { console.log("init"); - init_test(); + try { + init_test(); + }catch (e) { + console.log('init_test发生错误:'+e.message); + } } /** diff --git a/txt/pluto/template-web.js b/txt/pluto/template-web.js deleted file mode 100644 index 7c400e3..0000000 --- a/txt/pluto/template-web.js +++ /dev/null @@ -1,3 +0,0 @@ -/*! art-template@4.13.2 for browser | https://github.com/aui/art-template */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.template=t():e.template=t()}("undefined"!=typeof self?self:this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var i=n[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}var n={};return t.m=e,t.c=n,t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e["default"]}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t,n){"use strict";var r=n(6),i=n(2),o=n(22),s=function(e,t){t.onerror(e,t);var n=function(){return"{Template Error}"};return n.mappings=[],n.sourcesContent=[],n},a=function u(e){var t=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};"string"!=typeof e?t=e:t.source=e,t=i.$extend(t),e=t.source,!0===t.debug&&(t.cache=!1,t.minimize=!1,t.compileDebug=!0),t.compileDebug&&(t.minimize=!1),t.filename&&(t.filename=t.resolveFilename(t.filename,t));var n=t.filename,a=t.cache,c=t.caches;if(a&&n){var l=c.get(n);if(l)return l}if(!e)try{e=t.loader(n,t),t.source=e}catch(m){var f=new o({name:"CompileError",path:n,message:"template not found: "+m.message,stack:m.stack});if(t.bail)throw f;return s(f,t)}var p=void 0,h=new r(t);try{p=h.build()}catch(f){if(f=new o(f),t.bail)throw f;return s(f,t)}var d=function(e,n){try{return p(e,n)}catch(f){if(!t.compileDebug)return t.cache=!1,t.compileDebug=!0,u(t)(e,n);if(f=new o(f),t.bail)throw f;return s(f,t)()}};return d.mappings=p.mappings,d.sourcesContent=p.sourcesContent,d.toString=function(){return p.toString()},a&&n&&c.set(n,d),d};a.Compiler=r,e.exports=a},function(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t["default"]=/((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyu]{1,5}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g,t.matchToToken=function(e){var t={type:"invalid",value:e[0]};return e[1]?(t.type="string",t.closed=!(!e[3]&&!e[4])):e[5]?t.type="comment":e[6]?(t.type="comment",t.closed=!!e[7]):e[8]?t.type="regex":e[9]?t.type="number":e[10]?t.type="name":e[11]?t.type="punctuator":e[12]&&(t.type="whitespace"),t}},function(e,t,n){"use strict";function r(){this.$extend=function(e){return e=e||{},o(e,e instanceof r?e:this)}}var i=n(10),o=n(12),s=n(13),a=n(14),u=n(15),c=n(16),l=n(17),f=n(18),p=n(19),h=n(21),d="undefined"==typeof window,m={source:null,filename:null,rules:[f,l],escape:!0,debug:!!d&&"production"!==process.env.NODE_ENV,bail:!0,cache:!0,minimize:!0,compileDebug:!1,resolveFilename:h,include:s,htmlMinifier:p,htmlMinifierOptions:{collapseWhitespace:!0,minifyCSS:!0,minifyJS:!0,ignoreCustomFragments:[]},onerror:a,loader:c,caches:u,root:"/",extname:".art",ignore:[],imports:i};r.prototype=m,e.exports=new r},function(e,t){},function(e,t,n){"use strict";var r=n(5),i=n(0),o=n(23),s=function(e,t){return t instanceof Object?r({filename:e},t):i({filename:e,source:t})};s.render=r,s.compile=i,s.defaults=o,e.exports=s},function(e,t,n){"use strict";var r=n(0),i=function(e,t,n){return r(e,n)(t)};e.exports=i},function(e,t,n){"use strict";function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t|\([\w\W]*?\))\s*{[\s;]*$)/,"$1})"],[/(^[\w\W]*?\([\w\W]*?\)\s*{[\s;]*$)/,"$1}"]],n=0;n2&&arguments[2]!==undefined?arguments[2]:{},o=[new i("string",e)],s=0;sd&&(p=new i("string",v.slice(d,h.index),p),m.push(p)),p=new i("expression",h[0],p),h[0]=r(p),p.script=a.use.apply(n,h),m.push(p),d=h.index+h[0].length;d]/;o.$escape=function(e){return r(n(e))},o.$each=function(e,t){if(Array.isArray(e))for(var n=0,r=e.length;n {{"+n+"}}")};switch("#"===t&&h("#value","@value"),p){case"set":i="var "+u.join("").trim();break;case"if":i="if("+u.join("").trim()+"){";break;case"else":var d=u.indexOf("if");~d?(u.splice(0,d+1),i="}else if("+u.join("").trim()+"){"):i="}else{";break;case"/if":i="}";break;case"each":l=r._split(a),l.shift(),"as"===l[1]&&(h("each object as value index","each object value index"),l.splice(1,1));i="$each("+(l[0]||"$data")+",function("+(l[1]||"$value")+","+(l[2]||"$index")+"){";break;case"/each":i="})";break;case"block":l=r._split(a),l.shift(),i="block("+l.join(",").trim()+",function(){";break;case"/block":i="})";break;case"echo":p="print",h("echo value","value");case"print":case"include":case"extend":if(0!==u.join("").trim().indexOf("(")){l=r._split(a),l.shift(),i=p+"("+l.join(",")+")";break}default:if(~u.indexOf("|")){var m=a.reduce(function(e,t){var n=t.value,r=t.type;return"|"===n?e.push([]):"whitespace"!==r&&"comment"!==r&&(e.length||e.push([]),":"===n&&1===e[e.length-1].length?h("value | filter: argv","value | filter argv"):e[e.length-1].push(t)),e},[]).map(function(e){return r._split(e)});i=m.reduce(function(e,t){var n=t.shift();return t.unshift(e),"$imports."+n+"("+t.join(",")+")"},m.shift().join(" ").trim())}f=f||"escape"}return c.code=i,c.output=f,c},_split:function(e){e=e.filter(function(e){var t=e.type;return"whitespace"!==t&&"comment"!==t});for(var t=0,n=e.shift(),r=/\]|\)/,i=[[n]];t/,use:function(e,t,n,r){return n={"-":"raw","=":"escape","":!1,"==":"raw","=#":"raw"}[n],t&&(r="/*"+r+"*/",n=!1),{code:r,output:n}}};e.exports=r},function(e,t,n){"use strict";function r(e){if(Array.isArray(e)){for(var t=0,n=Array(e.length);t> ":" ")+n+"| "+e}).join("\n");return(r||"anonymous")+":"+i+":"+o+"\n"+f+"\n\n"+t+": "+a+(s?"\n generated: "+s:"")}var a=function(e){function t(e){r(this,t);var n=i(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e.message));return n.name="TemplateError",n.message=s(e),Error.captureStackTrace&&Error.captureStackTrace(n,n.constructor),n}return o(t,e),t}(Error);e.exports=a},function(e,t,n){"use strict";e.exports=n(2)}])}); \ No newline at end of file -- GitLab