importcheeriofrom"https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/cheerio.min.js";import"https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/crypto-js.js";import"https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/drT.js";importmubanfrom"https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js";functioninit_test(){console.log("init_test_start");console.log(RKEY);console.log(JSON.stringify(rule));console.log("init_test_end")}letrule={};constMOBILE_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";constPC_UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36";constUA="Mozilla/5.0";constUC_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";constIOS_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";constRULE_CK="cookie";constCATE_EXCLUDE="首页|留言|APP|下载|资讯|新闻|动态";constTAB_EXCLUDE="猜你|喜欢|APP|下载|剧情|热播";constOCR_RETRY=3;constOCR_API="http://cms.nokia.press/parse/ocr";if(typeofMY_URL==="undefined"){varMY_URL}varRKEY;varfetch;varprint;varlog;varrule_fetch_params;varfetch_params;varoheaders;var_pdfh;var_pdfa;var_pd;constDOM_CHECK_ATTR=/(url|src|href|data-original|data-src)$/;constSELECT_REGEX=/:eq|:lt|:gt|#/g;constSELECT_REGEX_A=/:eq|:lt|:gt/g;if(typeofObject.assign!="function"){Object.assign=function(){vartarget=arguments[0];for(vari=1;i<arguments.length;i++){varsource=arguments[i];for(varkeyinsource){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}returntarget}}if(!String.prototype.includes){String.prototype.includes=function(search,start){if(typeofstart!=="number"){start=0}if(start+search.length>this.length){returnfalse}else{returnthis.indexOf(search,start)!==-1}}}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function(searchElement,fromIndex){if(this==null){thrownewTypeError('"this" is null or not defined')}varo=Object(this);varlen=o.length>>>0;if(len===0){returnfalse}varn=fromIndex|0;vark=Math.max(n>=0?n:len-Math.abs(n),0);while(k<len){if(o[k]===searchElement){returntrue}k++}returnfalse}})}if(typeofString.prototype.startsWith!="function"){String.prototype.startsWith=function(prefix){returnthis.slice(0,prefix.length)===prefix}}if(typeofString.prototype.endsWith!="function"){String.prototype.endsWith=function(suffix){returnthis.indexOf(suffix,this.length-suffix.length)!==-1}}Object.prototype.myValues=function(obj){if(obj==null){thrownewTypeError("Cannot convert undefined or null to object")}varres=[];for(varkinobj){if(obj.hasOwnProperty(k)){res.push(obj[k])}}returnres};if(typeofObject.prototype.values!="function"){Object.prototype.values=function(obj){if(obj==null){thrownewTypeError("Cannot convert undefined or null to object")}varres=[];for(varkinobj){if(obj.hasOwnProperty(k)){res.push(obj[k])}}returnres}}if(typeofArray.prototype.join!="function"){Array.prototype.join=function(emoji){emoji=emoji||"";letself=this;letstr="";leti=0;if(!Array.isArray(self)){throwString(self)+"is not Array"}if(self.length===0){return""}if(self.length===1){returnString(self[0])}i=1;str=this[0];for(;i<self.length;i++){str+=String(emoji)+String(self[i])}returnstr}}String.prototype.rstrip=function(chars){letregex=newRegExp(chars+"$");returnthis.replace(regex,"")};Array.prototype.append=Array.prototype.push;String.prototype.strip=String.prototype.trim;function是否正版(vipUrl){letflag=newRegExp("qq.com|iqiyi.com|youku.com|mgtv.com|bilibili.com|sohu.com|ixigua.com|pptv.com|miguvideo.com|le.com|1905.com|fun.tv");returnflag.test(vipUrl)}functionurlDeal(vipUrl){if(!vipUrl){return""}if(!是否正版(vipUrl)){returnvipUrl}if(!/miguvideo/.test(vipUrl)){vipUrl=vipUrl.split("#")[0].split("?")[0]}returnvipUrl}functionsetResult(d){if(!Array.isArray(d)){return[]}VODS=[];d.forEach(function(it){letobj={vod_id:it.url||"",vod_name:it.title||"",vod_remarks:it.desc||"",vod_content:it.content||"",vod_pic:it.pic_url||it.img||""};letkeys=Object.keys(it);if(keys.includes("tname")){obj.type_name=it.tname||""}if(keys.includes("tid")){obj.type_id=it.tid||""}if(keys.includes("year")){obj.vod_year=it.year||""}if(keys.includes("actor")){obj.vod_actor=it.actor||""}if(keys.includes("director")){obj.vod_director=it.director||""}if(keys.includes("area")){obj.vod_area=it.area||""}VODS.push(obj)});returnVODS}functionsetResult2(res){VODS=res.list||[];returnVODS}functionsetHomeResult(res){if(!res||typeofres!=="object"){return[]}returnsetResult(res.list)}functionmaoss(jxurl,ref,key){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));eval(getCryptoJS());try{vargetVideoInfo=function(text){returnCryptoJS.AES.decrypt(text,key,{iv:iv,padding:CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8)};vartoken_key=key==undefined?"dvyYRQlnPRCMdQSe":key;if(ref){varhtml=request(jxurl,{headers:{Referer:ref}})}else{varhtml=request(jxurl)}if(html.indexOf("&btwaf=")!=-1){html=request(jxurl+"&btwaf"+html.match(/&btwaf(.*?)"/)[1],{headers:{Referer:ref}})}vartoken_iv=html.split('_token = "')[1].split('"')[0];varkey=CryptoJS.enc.Utf8.parse(token_key);variv=CryptoJS.enc.Utf8.parse(token_iv);eval(html.match(/var config = {[\s\S]*?}/)[0]+"");if(!config.url.startsWith("http")){config.url=CryptoJS.AES.decrypt(config.url,key,{iv:iv,padding:CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8)}returnconfig.url}catch(e){return""}}functionurlencode(str){str=(str+"").toString();returnencodeURIComponent(str).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A").replace(/%20/g,"+")}functionbase64Encode(text){returnCryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text))}functionbase64Decode(text){returnCryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(text))}functionmd5(text){returnCryptoJS.MD5(text).toString()}functiongetCryptoJS(){return'console.log("CryptoJS已装载");'}globalThis.VODS=[];globalThis.VOD={};globalThis.encodeUrl=urlencode;globalThis.urlencode=urlencode;functionurljoin(fromPath,nowPath){fromPath=fromPath||"";nowPath=nowPath||"";returnjoinUrl(fromPath,nowPath)}varurljoin2=urljoin;functionpD(html,parse,uri){letret=pdfh(html,parse);if(typeofuri==="undefined"||!uri){uri=""}if(DOM_CHECK_ATTR.test(parse)){if(/http/.test(ret)){ret=ret.substr(ret.indexOf("http"))}else{ret=urljoin(MY_URL,ret)}}returnret}constparseTags={jsp:{pdfh:pdfh,pdfa:pdfa,pd:pD},json:{pdfh(html,parse){if(!parse||!parse.trim()){return""}if(typeofhtml==="string"){html=JSON.parse(html)}parse=parse.trim();if(!parse.startsWith("$.")){parse="$."+parse}parse=parse.split("||");for(letpsofparse){letret=cheerio.jp(ps,html);if(Array.isArray(ret)){ret=ret[0]||""}else{ret=ret||""}if(ret&&typeofret!=="string"){ret=ret.toString()}if(ret){returnret}}return""},pdfa(html,parse){if(!parse||!parse.trim()){return""}if(typeofhtml==="string"){html=JSON.parse(html)}parse=parse.trim();if(!parse.startsWith("$.")){parse="$."+parse}letret=cheerio.jp(parse,html);if(Array.isArray(ret)&&Array.isArray(ret[0])&&ret.length===1){returnret[0]||[]}returnret||[]},pd(html,parse){letret=parseTags.json.pdfh(html,parse);if(ret){returnurljoin(MY_URL,ret)}returnret}},jq:{pdfh(html,parse,base_url){if(!parse||!parse.trim()){return""}letoption=undefined;if(parse.indexOf("&&")>-1){letsp=parse.split("&&");option=sp[sp.length-1];sp.splice(sp.length-1);if(sp.length>1){for(letiinsp){if(!SELECT_REGEX.test(sp[i])){sp[i]=sp[i]+":eq(0)"}}}else{if(!SELECT_REGEX.test(sp[0])){sp[0]=sp[0]+":eq(0)"}}parse=sp.join("")}letresult="";const$=cheerio.load(html);letret=$(parse);if(option){if(option==="Text"){result=$(ret).text()}elseif(option==="Html"){result=$(ret).html()}else{result=$(ret).attr(option)}if(result&&base_url&&DOM_CHECK_ATTR.test(option)){if(/http/.test(result)){result=result.substr(result.indexOf("http"))}else{result=urljoin(base_url,result)}}}else{result=$(ret).toString()}returnresult},pdfa(html,parse){if(!parse||!parse.trim()){return[]}if(parse.indexOf("&&")>-1){letsp=parse.split("&&");for(letiinsp){if(!SELECT_REGEX_A.test(sp[i])&&i<sp.length-1){sp[i]=sp[i]+":eq(0)"}}parse=sp.join("")}const$=cheerio.load(html);letret=$(parse);letresult=[];if(ret){ret.each(function(idx,ele){result.push($(ele).toString())})}returnresult},pd(html,parse,uri){returnparseTags.jq.pdfh(html,parse,MY_URL)}},getParse(p0){if(p0.startsWith("jsp:")){returnthis.jsp}elseif(p0.startsWith("json:")){returnthis.json}elseif(p0.startsWith("jq:")){returnthis.jq}else{returnthis.jq}}};conststringify=JSON.stringify;constjsp=parseTags.jsp;constjq=parseTags.jq;functionreadFile(filePath){filePath=filePath||"./uri.min.js";varfd=os.open(filePath);varbuffer=newArrayBuffer(1024);varlen=os.read(fd,buffer,0,1024);console.log(len);lettext=String.fromCharCode.apply(null,newUint8Array(buffer));console.log(text);returntext}functiondealJson(html){try{returnhtml.match(/[\w|\W|\s|\S]*?(\{[\w|\W|\s|\S]*\})/).group[1]}catch(e){}try{html=JSON.parse(html)}catch(e){}returnhtml}varOcrApi={api:OCR_API,classification:function(img){letcode="";try{lethtml=request(this.api,{data:{img:img},headers:{"User-Agent":PC_UA},method:"POST"});html=JSON.parse(html);code=html.url||""}catch(e){}returncode}};functionverifyCode(url){letcnt=0;lethost=getHome(url);letcookie="";while(cnt<OCR_RETRY){try{letyzm_url=`${host}/index.php/verify/index.html`;console.log(`验证码链接:${yzm_url}`);lethhtml=request(yzm_url,{withHeaders:true,toBase64:true});letjson=JSON.parse(hhtml);if(!cookie){cookie=json["set-cookie"]?json["set-cookie"].split(";")[0]:""}console.log("cookie:"+cookie);letimg=json.body;letcode=OcrApi.classification(img);console.log(`第${cnt+1}次验证码识别结果:${code}`);letsubmit_url=`${host}/index.php/ajax/verify_check?type=search&verify=${code}`;console.log(submit_url);lethtml=request(submit_url,{headers:{Cookie:cookie,"User-Agent":MOBILE_UA},method:"POST"});html=JSON.parse(html);if(html.msg==="ok"){console.log(`第${cnt+1}次验证码提交成功`);returncookie}elseif(html.msg!=="ok"&&cnt+1>=OCR_RETRY){cookie=""}}catch(e){console.log(`第${cnt+1}次验证码提交失败:${e.message}`);if(cnt+1>=OCR_RETRY){cookie=""}}cnt+=1}returncookie}functionsetItem(k,v){local.set(RKEY,k,v);console.log(`规则${RKEY}设置${k} => ${v}`)}functiongetItem(k,v){returnlocal.get(RKEY,k)||v}functionclearItem(k){local.delete(RKEY,k)}functiongetHome(url){if(!url){return""}lettmp=url.split("//");url=tmp[0]+"//"+tmp[1].split("/")[0];try{url=decodeURIComponent(url)}catch(e){}returnurl}functionbuildUrl(url,obj){obj=obj||{};if(url.indexOf("?")<0){url+="?"}letparam_list=[];letkeys=Object.keys(obj);keys.forEach(it=>{param_list.push(it+"="+obj[it])});letprs=param_list.join("&");if(keys.length>0&&!url.endsWith("?")){url+="&"}url+=prs;returnurl}functionrequire(url){eval(request(url))}functionrequest(url,obj){if(typeofobj==="undefined"||!obj||obj==={}){if(!fetch_params||!fetch_params.headers){letheaders={"User-Agent":MOBILE_UA};if(rule.headers){Object.assign(headers,rule.headers)}fetch_params.headers=headers}if(!fetch_params.headers.Referer){fetch_params.headers.Referer=getHome(url)}obj=fetch_params}else{letheaders=obj.headers||{};letkeys=Object.keys(headers).map(it=>it.toLowerCase());if(!keys.includes("user-agent")){headers["User-Agent"]=MOBILE_UA}if(!keys.includes("referer")){headers["Referer"]=getHome(url)}obj.headers=headers}console.log(JSON.stringify(obj.headers));if(typeofobj.headers.body!="undefined"&&obj.headers.body&&typeofobj.headers.body==="string"){letdata={};obj.headers.body.split("&").forEach(it=>{data[it.split("=")[0]]=it.split("=")[1]});obj.data=data;deleteobj.headers.body}if(!url){returnobj.withHeaders?"{}":""}if(obj.toBase64){obj.buffer=2;deleteobj.toBase64}console.log("request:"+url);letres=req(url,obj);lethtml=res.content||"";if(obj.withHeaders){lethtmlWithHeaders=res.headers;htmlWithHeaders.body=html;returnJSON.stringify(htmlWithHeaders)}else{returnhtml}}fetch=request;print=function(data){data=data||"";if(typeofdata!=="string"){try{data=JSON.stringify(data)}catch(e){console.log("print:"+e.message)}}console.log(data)};log=print;functioncheckHtml(html,url,obj){if(/\?btwaf=/.test(html)){letbtwaf=html.match(/btwaf(.*?)"/)[1];url=url.split("#")[0]+"?btwaf"+btwaf;html=request(url,obj)}returnhtml}functiongetCode(url,obj){lethtml=request(url,obj);html=checkHtml(html,url,obj);returnhtml}functiongetHtml(url){letobj={};if(rule.headers){obj.headers=rule.headers}letcookie=getItem(RULE_CK,"");if(cookie){if(obj.headers&&!Object.keys(obj.headers).map(it=>it.toLowerCase()).includes("cookie")){obj.headers["Cookie"]=cookie}elseif(!obj.headers){obj.headers={Cookie:cookie}}}lethtml=getCode(url,obj);returnhtml}functionhomeParse(homeObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letclasses=[];if(homeObj.class_name&&homeObj.class_url){letnames=homeObj.class_name.split("&");leturls=homeObj.class_url.split("&");letcnt=Math.min(names.length,urls.length);for(leti=0;i<cnt;i++){classes.push({type_id:urls[i],type_name:names[i]})}}if(homeObj.class_parse){letp=homeObj.class_parse.split(";");if(p.length>=4){try{lethtml=getHtml(homeObj.MY_URL);if(html){letlist=pdfa(html,p[0]);if(list&&list.length>0){list.forEach((it,idex)=>{try{letname=pdfh(it,p[1]);if(homeObj.cate_exclude&&newRegExp(homeObj.cate_exclude).test(name)){return}leturl=pdfh(it,p[2]);if(p[3]){letexp=newRegExp(p[3]);url=url.match(exp)[1]}classes.push({type_id:url,type_name:name})}catch(e){console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`)}})}}}catch(e){console.log(e.message)}}}classes=classes.filter(it=>!homeObj.cate_exclude||!newRegExp(homeObj.cate_exclude).test(it.type_name));letresp={class:classes};if(homeObj.filter){resp.filters=homeObj.filter}console.log(JSON.stringify(resp));returnJSON.stringify(resp)}functionhomeVodParse(homeVodObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letd=[];MY_URL=homeVodObj.homeUrl;console.log(MY_URL);letp=homeVodObj.推荐;if(!p||typeofp!=="string"){return"{}"}p=p.trim();if(p.startsWith("js:")){constTYPE="home";varinput=MY_URL;constHOST=rule.host;eval(p.replace("js:",""));d=VODS}else{p=p.split(";");if(!homeVodObj.double&&p.length<5){return"{}"}elseif(homeVodObj.double&&p.length<6){return"{}"}let_ps=parseTags.getParse(p[0]);_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;letis_json=p[0].startsWith("json:");p[0]=p[0].replace(/^(jsp:|json:|jq:)/,"");lethtml=getHtml(MY_URL);if(is_json){html=dealJson(html)}try{console.log("double:"+homeVodObj.double);if(homeVodObj.double){letitems=_pdfa(html,p[0]);for(letitemofitems){letitems2=_pdfa(item,p[1]);for(letitem2ofitems2){try{lettitle=_pdfh(item2,p[2]);letimg="";try{img=_pd(item2,p[3])}catch(e){}letdesc=_pdfh(item2,p[4]);letlinks=[];for(letp5ofp[5].split("+")){letlink=!homeVodObj.detailUrl?_pd(item2,p5,MY_URL):_pdfh(item2,p5);links.push(link)}letvod={vod_name:title,vod_pic:img,vod_remarks:desc,vod_id:links.join("$")};d.push(vod)}catch(e){console.log("首页列表处理发生错误:"+e.message)}}}}else{letitems=_pdfa(html,p[0]);for(letitemofitems){try{lettitle=_pdfh(item,p[1]);letimg="";try{img=_pd(item,p[2],MY_URL)}catch(e){}letdesc=_pdfh(item,p[3]);letlinks=[];for(letp5ofp[4].split("+")){letlink=!homeVodObj.detailUrl?_pd(item,p5,MY_URL):_pdfh(item,p5);links.push(link)}letvod={vod_name:title,vod_pic:img,vod_remarks:desc,vod_id:links.join("$")};d.push(vod)}catch(e){}}}}catch(e){}}returnJSON.stringify({list:d})}functioncategoryParse(cateObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letp=cateObj.一级;if(!p||typeofp!=="string"){return"{}"}letd=[];leturl=cateObj.url.replaceAll("fyclass",cateObj.tid);if(rule.filter_url){if(!/fyfilter/.test(url)){if(!url.endsWith("&")&&!rule.filter_url.startsWith("&")){url+="&"}url+=rule.filter_url}else{url=url.replace("fyfilter",rule.filter_url)}letfl=cateObj.filter?cateObj.extend:{};letnew_url;new_url=cheerio.jinja2(url,{fl:fl});if(/object Object/.test(new_url)){new_url=drT.renderText(url,fl)}url=new_url}if(/fypage/.test(url)){if(url.includes("(")&&url.includes(")")){leturl_rep=url.match(/.*?\((.*)\)/)[1];letcnt_page=url_rep.replaceAll("fypage",cateObj.pg);letcnt_pg=eval(cnt_page);url=url.replaceAll(url_rep,cnt_pg).replaceAll("(","").replaceAll(")","")}else{url=url.replaceAll("fypage",cateObj.pg)}}if(cateObj.pg===1&&url.includes("[")&&url.includes("]")){url=url.split("[")[1].split("]")[0]}MY_URL=url;console.log(MY_URL);p=p.trim();constMY_CATE=cateObj.tid;if(p.startsWith("js:")){varMY_FL=cateObj.extend;constTYPE="cate";varinput=MY_URL;constMY_PAGE=cateObj.pg;vardesc="";eval(p.trim().replace("js:",""));d=VODS}else{p=p.split(";");if(p.length<5){return"{}"}let_ps=parseTags.getParse(p[0]);_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;letis_json=p[0].startsWith("json:");p[0]=p[0].replace(/^(jsp:|json:|jq:)/,"");try{lethtml=getHtml(MY_URL);if(html){if(is_json){html=dealJson(html)}letlist=_pdfa(html,p[0]);list.forEach(it=>{letlinks=p[4].split("+").map(p4=>{return!rule.detailUrl?_pd(it,p4,MY_URL):_pdfh(it,p4)});letlink=links.join("$");letvod_id=rule.detailUrl?MY_CATE+"$"+link:link;d.push({vod_id:vod_id,vod_name:_pdfh(it,p[1]).replace(/\n|\t/g,"").trim(),vod_pic:_pd(it,p[2],MY_URL),vod_remarks:_pdfh(it,p[3]).replace(/\n|\t/g,"").trim()})})}}catch(e){console.log(e.message)}}returnd.length<1?"{}":JSON.stringify({page:parseInt(cateObj.pg),pagecount:999,limit:20,total:999,list:d})}functionsearchParse(searchObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letd=[];if(!searchObj.searchUrl){return"{}"}letp=searchObj.搜索==="*"&&rule.一级?rule.一级:searchObj.搜索;if(!p||typeofp!=="string"){return"{}"}p=p.trim();leturl=searchObj.searchUrl.replaceAll("**",searchObj.wd).replaceAll("fypage",searchObj.pg);MY_URL=url;console.log(MY_URL);if(p.startsWith("js:")){constTYPE="search";constMY_PAGE=searchObj.pg;constKEY=searchObj.wd;varinput=MY_URL;vardetailUrl=rule.detailUrl||"";eval(p.trim().replace("js:",""));d=VODS}else{p=p.split(";");if(p.length<5){return"{}"}let_ps=parseTags.getParse(p[0]);_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;letis_json=p[0].startsWith("json:");p[0]=p[0].replace(/^(jsp:|json:|jq:)/,"");try{lethtml=getHtml(MY_URL);if(html){if(/系统安全验证|输入验证码/.test(html)){letcookie=verifyCode(MY_URL);if(cookie){console.log(`本次成功过验证,cookie:${cookie}`);setItem(RULE_CK,cookie)}else{console.log(`本次自动过搜索验证失败,cookie:${cookie}`)}html=getHtml(MY_URL)}if(!html.includes(searchObj.wd)){console.log("搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码");console.log(html)}if(is_json){html=dealJson(html)}letlist=_pdfa(html,p[0]);list.forEach(it=>{letlinks=p[4].split("+").map(p4=>{return!rule.detailUrl?_pd(it,p4,MY_URL):_pdfh(it,p4)});letlink=links.join("$");letob={vod_id:link,vod_name:_pdfh(it,p[1]).replace(/\n|\t/g,"").trim(),vod_pic:_pd(it,p[2],MY_URL),vod_remarks:_pdfh(it,p[3]).replace(/\n|\t/g,"").trim()};if(p.length>5&&p[5]){ob.vod_content=_pdfh(it,p[5])}d.push(ob)})}}catch(e){return"{}"}}returnJSON.stringify({page:parseInt(searchObj.pg),pagecount:10,limit:20,total:100,list:d})}functiondetailParse(detailObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letvod={vod_id:"id",vod_name:"片名",vod_pic:"",type_name:"剧情",vod_year:"年份",vod_area:"地区",vod_remarks:"更新信息",vod_actor:"主演",vod_director:"导演",vod_content:"简介"};letp=detailObj.二级;leturl=detailObj.url;letdetailUrl=detailObj.detailUrl;letfyclass=detailObj.fyclass;lettab_exclude=detailObj.tab_exclude;lethtml=detailObj.html||"";MY_URL=url;console.log(MY_URL);if(p==="*"){vod.vod_play_from="道长在线";vod.vod_remarks=detailUrl;vod.vod_actor="没有二级,只有一级链接直接嗅探播放";vod.vod_content=MY_URL;vod.vod_play_url="嗅探播放$"+MY_URL}elseif(typeofp==="string"&&p.trim().startsWith("js:")){constTYPE="detail";varinput=MY_URL;eval(p.trim().replace("js:",""));vod=VOD;console.log(JSON.stringify(vod))}elseif(p&&typeofp==="object"){if(!html){html=getHtml(MY_URL)}let_ps;if(p.is_json){_ps=parseTags.json;html=dealJson(html)}elseif(p.is_jsp){_ps=parseTags.jsp}elseif(p.is_jq){_ps=parseTags.jq}else{_ps=parseTags.jq}_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;if(p.title){letp1=p.title.split(";");vod.vod_name=_pdfh(html,p1[0]).replace(/\n|\t/g,"").trim();lettype_name=p1.length>1?_pdfh(html,p1[1]).replace(/\n|\t/g,"").replace(/ /g,"").trim():"";vod.type_name=type_name||vod.type_name}if(p.desc){try{letp1=p.desc.split(";");vod.vod_remarks=_pdfh(html,p1[0]).replace(/\n|\t/g,"").trim();vod.vod_year=p1.length>1?_pdfh(html,p1[1]).replace(/\n|\t/g,"").trim():"";vod.vod_area=p1.length>2?_pdfh(html,p1[2]).replace(/\n|\t/g,"").trim():"";vod.vod_actor=p1.length>3?_pdfh(html,p1[3]).replace(/\n|\t/g,"").trim():"";vod.vod_director=p1.length>4?_pdfh(html,p1[4]).replace(/\n|\t/g,"").trim():""}catch(e){}}if(p.content){try{letp1=p.content.split(";");vod.vod_content=_pdfh(html,p1[0]).replace(/\n|\t/g,"").trim()}catch(e){}}if(p.img){try{letp1=p.img.split(";");vod.vod_pic=_pd(html,p1[0],MY_URL)}catch(e){}}letvod_play_from="$$$";letplayFrom=[];if(p.重定向&&p.重定向.startsWith("js:")){html=eval(p.重定向.replace("js:",""))}if(p.tabs){letp_tab=p.tabs.split(";")[0];console.log(p_tab);letvHeader=_pdfa(html,p_tab);console.log(vHeader.length);for(letvofvHeader){letv_title=_pdfh(v,"body&&Text");console.log(v_title);if(tab_exclude&&newRegExp(tab_exclude).test(v_title)){continue}playFrom.push(v_title)}console.log(JSON.stringify(playFrom))}else{playFrom=["道长在线"]}vod.vod_play_from=playFrom.join(vod_play_from);letvod_play_url="$$$";letvod_tab_list=[];if(p.lists){for(leti=0;i<playFrom.length;i++){lettab_name=playFrom[i];lettab_ext=p.tabs.split(";").length>1?p.tabs.split(";")[1]:"";letp1=p.lists.replaceAll("#idv",tab_name).replaceAll("#id",i);tab_ext=tab_ext.replaceAll("#idv",tab_name).replaceAll("#id",i);console.log(p1);letvodList=[];try{vodList=_pdfa(html,p1);console.log("len(vodList):"+vodList.length)}catch(e){}letnew_vod_list=[];lettabName=tab_ext?_pdfh(html,tab_ext):tab_name;console.log(tabName);vodList.forEach(it=>{new_vod_list.push(cheerio.load(it).text()+"$"+_pd(it,"a&&href",MY_URL))});letvlist=new_vod_list.join("#");vod_tab_list.push(vlist)}}vod.vod_play_url=vod_tab_list.join(vod_play_url)}returnJSON.stringify({list:[vod]})}functionplayParse(playObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));MY_URL=playObj.url;if(!/http/.test(MY_URL)){try{MY_URL=base64Decode(MY_URL)}catch(e){}}MY_URL=decodeURIComponent(MY_URL);varinput=MY_URL;letcommon_play={parse:1,url:input};letlazy_play;if(!rule.play_parse||!rule.lazy){lazy_play=common_play}elseif(rule.play_parse&&rule.lazy&&typeofrule.lazy==="string"){try{letlazy_code=rule.lazy.replace("js:","").trim();print("开始执行js免嗅=>"+lazy_code);eval(lazy_code);lazy_play=typeofinput==="object"?input:{parse:1,jx:1,url:input}}catch(e){print("js免嗅错误:"+e.message);lazy_play=common_play}}else{lazy_play=common_play}console.log(JSON.stringify(lazy_play));returnJSON.stringify(lazy_play)}functioninit(ext){console.log("init");try{if(typeofext=="object"){rule=ext;if(rule.template){rule=Object.assign(muban[rule.template],rule)}}elseif(typeofext=="string"){if(ext.startsWith("http")){letjs=request(ext,{method:"GET"});if(js){eval(js.replace("var rule","rule"))}}}else{eval(ext.replace("var rule","rule"))}letrule_cate_excludes=(rule.cate_exclude||"").split("|").filter(it=>it.trim());letrule_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("|");rule.tab_exclude=rule_tab_excludes.join("|");rule.host=(rule.host||"").rstrip("/");rule.url=rule.url||"";rule.double=rule.double||false;rule.homeUrl=rule.homeUrl||"";rule.detailUrl=rule.detailUrl||"";rule.searchUrl=rule.searchUrl||"";rule.homeUrl=rule.host&&rule.homeUrl?urljoin(rule.host,rule.homeUrl):rule.homeUrl||rule.host;rule.detailUrl=rule.host&&rule.detailUrl?urljoin(rule.host,rule.detailUrl):rule.detailUrl;if(rule.url.includes("[")&&rule.url.includes("]")){letu1=rule.url.split("[")[0];letu2=rule.url.split("[")[1].split("]")[0];rule.url=rule.host&&rule.url?urljoin(rule.host,u1)+"["+urljoin(rule.host,u2)+"]":rule.url}else{rule.url=rule.host&&rule.url?urljoin(rule.host,rule.url):rule.url}rule.searchUrl=rule.host&&rule.searchUrl?urljoin(rule.host,rule.searchUrl):rule.searchUrl;rule.timeout=rule.timeout||5e3;rule.encoding=rule.编码||rule.encoding||"utf-8";if(rule.headers&&typeofrule.headers==="object"){try{letheader_keys=Object.keys(rule.headers);for(letkofheader_keys){if(k.toLowerCase()==="user-agent"){letv=rule.headers[k];console.log(v);if(["MOBILE_UA","PC_UA","UC_UA","IOS_UA","UA"].includes(v)){rule.headers[k]=eval(v)}}}}catch(e){console.log("处理headers发生错误:"+e.message)}}rule_fetch_params={headers:rule.headers||false,timeout:rule.timeout,encoding:rule.encoding};oheaders=rule.headers||{};RKEY=typeofkey!=="undefined"&&key?key:"drpy_"+(rule.title||rule.host);init_test()}catch(e){console.log("init_test发生错误:"+e.message)}}functionhome(filter){console.log("home");lethomeObj={filter:rule.filter||false,MY_URL:rule.homeUrl,class_name:rule.class_name||"",class_url:rule.class_url||"",class_parse:rule.class_parse||"",cate_exclude:rule.cate_exclude};returnhomeParse(homeObj)}functionhomeVod(params){lethomeVodObj={"推荐":rule.推荐,double:rule.double,homeUrl:rule.homeUrl,detailUrl:rule.detailUrl};returnhomeVodParse(homeVodObj)}functioncategory(tid,pg,filter,extend){letcateObj={url:rule.url,"一级":rule.一级,tid:tid,pg:parseInt(pg),filter:filter,extend:extend};returncategoryParse(cateObj)}functiondetail(vod_url){letfyclass="";if(vod_url.indexOf("$")>-1){lettmp=vod_url.split("$");fyclass=tmp[0];vod_url=tmp[1]}letdetailUrl=vod_url;leturl;if(!detailUrl.startsWith("http")&&!detailUrl.includes("/")){url=rule.detailUrl.replaceAll("fyid",detailUrl).replaceAll("fyclass",fyclass)}elseif(detailUrl.includes("/")){url=urljoin(rule.homeUrl,detailUrl)}else{url=detailUrl}letdetailObj={url:url,"二级":rule.二级,detailUrl:detailUrl,fyclass:fyclass,tab_exclude:rule.tab_exclude};returndetailParse(detailObj)}functionplay(flag,id,flags){letplayObj={url:id,flag:flag,flags:flags};returnplayParse(playObj)}functionsearch(wd,quick){letsearchObj={searchUrl:rule.searchUrl,"搜索":rule.搜索,wd:wd,pg:1,quick:quick};returnsearchParse(searchObj)}functionDRPY(){return{init:init,home:home,homeVod:homeVod,category:category,detail:detail,play:play,search:search}}exportdefault{init:init,home:home,homeVod:homeVod,category:category,detail:detail,play:play,search:search,DRPY:DRPY};
\ No newline at end of file
importcheeriofrom"https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/cheerio.min.js";import"https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/crypto-js.js";import"https://gitcode.net/qq_32394351/dr_py/-/raw/master/libs/drT.js";functioninit_test(){console.log("init_test_start");console.log(RKEY);console.log(JSON.stringify(rule));console.log("init_test_end")}letrule={};constMOBILE_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";constPC_UA="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.54 Safari/537.36";constUA="Mozilla/5.0";constUC_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";constIOS_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";constRULE_CK="cookie";constCATE_EXCLUDE="首页|留言|APP|下载|资讯|新闻|动态";constTAB_EXCLUDE="猜你|喜欢|APP|下载|剧情|热播";constOCR_RETRY=3;constOCR_API="http://cms.nokia.press/parse/ocr";if(typeofMY_URL==="undefined"){varMY_URL}varRKEY;varfetch;varprint;varlog;varrule_fetch_params;varfetch_params;varoheaders;var_pdfh;var_pdfa;var_pd;constDOM_CHECK_ATTR=/(url|src|href|data-original|data-src)$/;constSELECT_REGEX=/:eq|:lt|:gt|#/g;constSELECT_REGEX_A=/:eq|:lt|:gt/g;if(typeofObject.assign!="function"){Object.assign=function(){vartarget=arguments[0];for(vari=1;i<arguments.length;i++){varsource=arguments[i];for(varkeyinsource){if(Object.prototype.hasOwnProperty.call(source,key)){target[key]=source[key]}}}returntarget}}if(!String.prototype.includes){String.prototype.includes=function(search,start){if(typeofstart!=="number"){start=0}if(start+search.length>this.length){returnfalse}else{returnthis.indexOf(search,start)!==-1}}}if(!Array.prototype.includes){Object.defineProperty(Array.prototype,"includes",{value:function(searchElement,fromIndex){if(this==null){thrownewTypeError('"this" is null or not defined')}varo=Object(this);varlen=o.length>>>0;if(len===0){returnfalse}varn=fromIndex|0;vark=Math.max(n>=0?n:len-Math.abs(n),0);while(k<len){if(o[k]===searchElement){returntrue}k++}returnfalse}})}if(typeofString.prototype.startsWith!="function"){String.prototype.startsWith=function(prefix){returnthis.slice(0,prefix.length)===prefix}}if(typeofString.prototype.endsWith!="function"){String.prototype.endsWith=function(suffix){returnthis.indexOf(suffix,this.length-suffix.length)!==-1}}Object.prototype.myValues=function(obj){if(obj==null){thrownewTypeError("Cannot convert undefined or null to object")}varres=[];for(varkinobj){if(obj.hasOwnProperty(k)){res.push(obj[k])}}returnres};if(typeofObject.prototype.values!="function"){Object.prototype.values=function(obj){if(obj==null){thrownewTypeError("Cannot convert undefined or null to object")}varres=[];for(varkinobj){if(obj.hasOwnProperty(k)){res.push(obj[k])}}returnres}}if(typeofArray.prototype.join!="function"){Array.prototype.join=function(emoji){emoji=emoji||"";letself=this;letstr="";leti=0;if(!Array.isArray(self)){throwString(self)+"is not Array"}if(self.length===0){return""}if(self.length===1){returnString(self[0])}i=1;str=this[0];for(;i<self.length;i++){str+=String(emoji)+String(self[i])}returnstr}}String.prototype.rstrip=function(chars){letregex=newRegExp(chars+"$");returnthis.replace(regex,"")};Array.prototype.append=Array.prototype.push;String.prototype.strip=String.prototype.trim;function是否正版(vipUrl){letflag=newRegExp("qq.com|iqiyi.com|youku.com|mgtv.com|bilibili.com|sohu.com|ixigua.com|pptv.com|miguvideo.com|le.com|1905.com|fun.tv");returnflag.test(vipUrl)}functionurlDeal(vipUrl){if(!vipUrl){return""}if(!是否正版(vipUrl)){returnvipUrl}if(!/miguvideo/.test(vipUrl)){vipUrl=vipUrl.split("#")[0].split("?")[0]}returnvipUrl}functionsetResult(d){if(!Array.isArray(d)){return[]}VODS=[];d.forEach(function(it){letobj={vod_id:it.url||"",vod_name:it.title||"",vod_remarks:it.desc||"",vod_content:it.content||"",vod_pic:it.pic_url||it.img||""};letkeys=Object.keys(it);if(keys.includes("tname")){obj.type_name=it.tname||""}if(keys.includes("tid")){obj.type_id=it.tid||""}if(keys.includes("year")){obj.vod_year=it.year||""}if(keys.includes("actor")){obj.vod_actor=it.actor||""}if(keys.includes("director")){obj.vod_director=it.director||""}if(keys.includes("area")){obj.vod_area=it.area||""}VODS.push(obj)});returnVODS}functionsetResult2(res){VODS=res.list||[];returnVODS}functionsetHomeResult(res){if(!res||typeofres!=="object"){return[]}returnsetResult(res.list)}functionmaoss(jxurl,ref,key){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));eval(getCryptoJS());try{vargetVideoInfo=function(text){returnCryptoJS.AES.decrypt(text,key,{iv:iv,padding:CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8)};vartoken_key=key==undefined?"dvyYRQlnPRCMdQSe":key;if(ref){varhtml=request(jxurl,{headers:{Referer:ref}})}else{varhtml=request(jxurl)}if(html.indexOf("&btwaf=")!=-1){html=request(jxurl+"&btwaf"+html.match(/&btwaf(.*?)"/)[1],{headers:{Referer:ref}})}vartoken_iv=html.split('_token = "')[1].split('"')[0];varkey=CryptoJS.enc.Utf8.parse(token_key);variv=CryptoJS.enc.Utf8.parse(token_iv);eval(html.match(/var config = {[\s\S]*?}/)[0]+"");if(!config.url.startsWith("http")){config.url=CryptoJS.AES.decrypt(config.url,key,{iv:iv,padding:CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8)}returnconfig.url}catch(e){return""}}functionurlencode(str){str=(str+"").toString();returnencodeURIComponent(str).replace(/!/g,"%21").replace(/'/g,"%27").replace(/\(/g,"%28").replace(/\)/g,"%29").replace(/\*/g,"%2A").replace(/%20/g,"+")}functionbase64Encode(text){returnCryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text))}functionbase64Decode(text){returnCryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(text))}functionmd5(text){returnCryptoJS.MD5(text).toString()}functiongetCryptoJS(){return'console.log("CryptoJS已装载");'}globalThis.VODS=[];globalThis.VOD={};globalThis.encodeUrl=urlencode;globalThis.urlencode=urlencode;functionurljoin(fromPath,nowPath){fromPath=fromPath||"";nowPath=nowPath||"";returnjoinUrl(fromPath,nowPath)}varurljoin2=urljoin;functionpD(html,parse,uri){letret=pdfh(html,parse);if(typeofuri==="undefined"||!uri){uri=""}if(DOM_CHECK_ATTR.test(parse)){if(/http/.test(ret)){ret=ret.substr(ret.indexOf("http"))}else{ret=urljoin(MY_URL,ret)}}returnret}constparseTags={jsp:{pdfh:pdfh,pdfa:pdfa,pd:pD},json:{pdfh(html,parse){if(!parse||!parse.trim()){return""}if(typeofhtml==="string"){html=JSON.parse(html)}parse=parse.trim();if(!parse.startsWith("$.")){parse="$."+parse}parse=parse.split("||");for(letpsofparse){letret=cheerio.jp(ps,html);if(Array.isArray(ret)){ret=ret[0]||""}else{ret=ret||""}if(ret&&typeofret!=="string"){ret=ret.toString()}if(ret){returnret}}return""},pdfa(html,parse){if(!parse||!parse.trim()){return""}if(typeofhtml==="string"){html=JSON.parse(html)}parse=parse.trim();if(!parse.startsWith("$.")){parse="$."+parse}letret=cheerio.jp(parse,html);if(Array.isArray(ret)&&Array.isArray(ret[0])&&ret.length===1){returnret[0]||[]}returnret||[]},pd(html,parse){letret=parseTags.json.pdfh(html,parse);if(ret){returnurljoin(MY_URL,ret)}returnret}},jq:{pdfh(html,parse,base_url){if(!parse||!parse.trim()){return""}letoption=undefined;if(parse.indexOf("&&")>-1){letsp=parse.split("&&");option=sp[sp.length-1];sp.splice(sp.length-1);if(sp.length>1){for(letiinsp){if(!SELECT_REGEX.test(sp[i])){sp[i]=sp[i]+":eq(0)"}}}else{if(!SELECT_REGEX.test(sp[0])){sp[0]=sp[0]+":eq(0)"}}parse=sp.join("")}letresult="";const$=cheerio.load(html);letret=$(parse);if(option){if(option==="Text"){result=$(ret).text()}elseif(option==="Html"){result=$(ret).html()}else{result=$(ret).attr(option)}if(result&&base_url&&DOM_CHECK_ATTR.test(option)){if(/http/.test(result)){result=result.substr(result.indexOf("http"))}else{result=urljoin(base_url,result)}}}else{result=$(ret).toString()}returnresult},pdfa(html,parse){if(!parse||!parse.trim()){return[]}if(parse.indexOf("&&")>-1){letsp=parse.split("&&");for(letiinsp){if(!SELECT_REGEX_A.test(sp[i])&&i<sp.length-1){sp[i]=sp[i]+":eq(0)"}}parse=sp.join("")}const$=cheerio.load(html);letret=$(parse);letresult=[];if(ret){ret.each(function(idx,ele){result.push($(ele).toString())})}returnresult},pd(html,parse,uri){returnparseTags.jq.pdfh(html,parse,MY_URL)}},getParse(p0){if(p0.startsWith("jsp:")){returnthis.jsp}elseif(p0.startsWith("json:")){returnthis.json}elseif(p0.startsWith("jq:")){returnthis.jq}else{returnthis.jq}}};conststringify=JSON.stringify;constjsp=parseTags.jsp;constjq=parseTags.jq;functionreadFile(filePath){filePath=filePath||"./uri.min.js";varfd=os.open(filePath);varbuffer=newArrayBuffer(1024);varlen=os.read(fd,buffer,0,1024);console.log(len);lettext=String.fromCharCode.apply(null,newUint8Array(buffer));console.log(text);returntext}functiondealJson(html){try{returnhtml.match(/[\w|\W|\s|\S]*?(\{[\w|\W|\s|\S]*\})/).group[1]}catch(e){}try{html=JSON.parse(html)}catch(e){}returnhtml}varOcrApi={api:OCR_API,classification:function(img){letcode="";try{lethtml=request(this.api,{data:{img:img},headers:{"User-Agent":PC_UA},method:"POST"});html=JSON.parse(html);code=html.url||""}catch(e){}returncode}};functionverifyCode(url){letcnt=0;lethost=getHome(url);letcookie="";while(cnt<OCR_RETRY){try{letyzm_url=`${host}/index.php/verify/index.html`;console.log(`验证码链接:${yzm_url}`);lethhtml=request(yzm_url,{withHeaders:true,toBase64:true});letjson=JSON.parse(hhtml);if(!cookie){cookie=json["set-cookie"]?json["set-cookie"].split(";")[0]:""}console.log("cookie:"+cookie);letimg=json.body;letcode=OcrApi.classification(img);console.log(`第${cnt+1}次验证码识别结果:${code}`);letsubmit_url=`${host}/index.php/ajax/verify_check?type=search&verify=${code}`;console.log(submit_url);lethtml=request(submit_url,{headers:{Cookie:cookie,"User-Agent":MOBILE_UA},method:"POST"});html=JSON.parse(html);if(html.msg==="ok"){console.log(`第${cnt+1}次验证码提交成功`);returncookie}elseif(html.msg!=="ok"&&cnt+1>=OCR_RETRY){cookie=""}}catch(e){console.log(`第${cnt+1}次验证码提交失败:${e.message}`);if(cnt+1>=OCR_RETRY){cookie=""}}cnt+=1}returncookie}functionsetItem(k,v){local.set(RKEY,k,v);console.log(`规则${RKEY}设置${k} => ${v}`)}functiongetItem(k,v){returnlocal.get(RKEY,k)||v}functionclearItem(k){local.delete(RKEY,k)}functiongetHome(url){if(!url){return""}lettmp=url.split("//");url=tmp[0]+"//"+tmp[1].split("/")[0];try{url=decodeURIComponent(url)}catch(e){}returnurl}functionbuildUrl(url,obj){obj=obj||{};if(url.indexOf("?")<0){url+="?"}letparam_list=[];letkeys=Object.keys(obj);keys.forEach(it=>{param_list.push(it+"="+obj[it])});letprs=param_list.join("&");if(keys.length>0&&!url.endsWith("?")){url+="&"}url+=prs;returnurl}functionrequire(url){eval(request(url))}functionrequest(url,obj){if(typeofobj==="undefined"||!obj||obj==={}){if(!fetch_params||!fetch_params.headers){letheaders={"User-Agent":MOBILE_UA};if(rule.headers){Object.assign(headers,rule.headers)}fetch_params.headers=headers}if(!fetch_params.headers.Referer){fetch_params.headers.Referer=getHome(url)}obj=fetch_params}else{letheaders=obj.headers||{};letkeys=Object.keys(headers).map(it=>it.toLowerCase());if(!keys.includes("user-agent")){headers["User-Agent"]=MOBILE_UA}if(!keys.includes("referer")){headers["Referer"]=getHome(url)}obj.headers=headers}console.log(JSON.stringify(obj.headers));if(typeofobj.headers.body!="undefined"&&obj.headers.body&&typeofobj.headers.body==="string"){letdata={};obj.headers.body.split("&").forEach(it=>{data[it.split("=")[0]]=it.split("=")[1]});obj.data=data;deleteobj.headers.body}if(!url){returnobj.withHeaders?"{}":""}if(obj.toBase64){obj.buffer=2;deleteobj.toBase64}console.log("request:"+url);letres=req(url,obj);lethtml=res.content||"";if(obj.withHeaders){lethtmlWithHeaders=res.headers;htmlWithHeaders.body=html;returnJSON.stringify(htmlWithHeaders)}else{returnhtml}}fetch=request;print=function(data){data=data||"";if(typeofdata!=="string"){try{data=JSON.stringify(data)}catch(e){console.log("print:"+e.message)}}console.log(data)};log=print;functioncheckHtml(html,url,obj){if(/\?btwaf=/.test(html)){letbtwaf=html.match(/btwaf(.*?)"/)[1];url=url.split("#")[0]+"?btwaf"+btwaf;html=request(url,obj)}returnhtml}functiongetCode(url,obj){lethtml=request(url,obj);html=checkHtml(html,url,obj);returnhtml}functiongetHtml(url){letobj={};if(rule.headers){obj.headers=rule.headers}letcookie=getItem(RULE_CK,"");if(cookie){if(obj.headers&&!Object.keys(obj.headers).map(it=>it.toLowerCase()).includes("cookie")){obj.headers["Cookie"]=cookie}elseif(!obj.headers){obj.headers={Cookie:cookie}}}lethtml=getCode(url,obj);returnhtml}functionhomeParse(homeObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letclasses=[];if(homeObj.class_name&&homeObj.class_url){letnames=homeObj.class_name.split("&");leturls=homeObj.class_url.split("&");letcnt=Math.min(names.length,urls.length);for(leti=0;i<cnt;i++){classes.push({type_id:urls[i],type_name:names[i]})}}if(homeObj.class_parse){letp=homeObj.class_parse.split(";");if(p.length>=4){try{lethtml=getHtml(homeObj.MY_URL);if(html){letlist=pdfa(html,p[0]);if(list&&list.length>0){list.forEach((it,idex)=>{try{letname=pdfh(it,p[1]);if(homeObj.cate_exclude&&newRegExp(homeObj.cate_exclude).test(name)){return}leturl=pdfh(it,p[2]);if(p[3]){letexp=newRegExp(p[3]);url=url.match(exp)[1]}classes.push({type_id:url,type_name:name})}catch(e){console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`)}})}}}catch(e){console.log(e.message)}}}classes=classes.filter(it=>!homeObj.cate_exclude||!newRegExp(homeObj.cate_exclude).test(it.type_name));letresp={class:classes};if(homeObj.filter){resp.filters=homeObj.filter}console.log(JSON.stringify(resp));returnJSON.stringify(resp)}functionhomeVodParse(homeVodObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letd=[];MY_URL=homeVodObj.homeUrl;console.log(MY_URL);letp=homeVodObj.推荐;if(!p||typeofp!=="string"){return"{}"}p=p.trim();if(p.startsWith("js:")){constTYPE="home";varinput=MY_URL;constHOST=rule.host;eval(p.replace("js:",""));d=VODS}else{p=p.split(";");if(!homeVodObj.double&&p.length<5){return"{}"}elseif(homeVodObj.double&&p.length<6){return"{}"}let_ps=parseTags.getParse(p[0]);_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;letis_json=p[0].startsWith("json:");p[0]=p[0].replace(/^(jsp:|json:|jq:)/,"");lethtml=getHtml(MY_URL);if(is_json){html=dealJson(html)}try{console.log("double:"+homeVodObj.double);if(homeVodObj.double){letitems=_pdfa(html,p[0]);for(letitemofitems){letitems2=_pdfa(item,p[1]);for(letitem2ofitems2){try{lettitle=_pdfh(item2,p[2]);letimg="";try{img=_pd(item2,p[3])}catch(e){}letdesc=_pdfh(item2,p[4]);letlinks=[];for(letp5ofp[5].split("+")){letlink=!homeVodObj.detailUrl?_pd(item2,p5,MY_URL):_pdfh(item2,p5);links.push(link)}letvod={vod_name:title,vod_pic:img,vod_remarks:desc,vod_id:links.join("$")};d.push(vod)}catch(e){console.log("首页列表处理发生错误:"+e.message)}}}}else{letitems=_pdfa(html,p[0]);for(letitemofitems){try{lettitle=_pdfh(item,p[1]);letimg="";try{img=_pd(item,p[2],MY_URL)}catch(e){}letdesc=_pdfh(item,p[3]);letlinks=[];for(letp5ofp[4].split("+")){letlink=!homeVodObj.detailUrl?_pd(item,p5,MY_URL):_pdfh(item,p5);links.push(link)}letvod={vod_name:title,vod_pic:img,vod_remarks:desc,vod_id:links.join("$")};d.push(vod)}catch(e){}}}}catch(e){}}returnJSON.stringify({list:d})}functioncategoryParse(cateObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letp=cateObj.一级;if(!p||typeofp!=="string"){return"{}"}letd=[];leturl=cateObj.url.replaceAll("fyclass",cateObj.tid);if(rule.filter_url){if(!/fyfilter/.test(url)){if(!url.endsWith("&")&&!rule.filter_url.startsWith("&")){url+="&"}url+=rule.filter_url}else{url=url.replace("fyfilter",rule.filter_url)}letfl=cateObj.filter?cateObj.extend:{};letnew_url;new_url=cheerio.jinja2(url,{fl:fl});if(/object Object/.test(new_url)){new_url=drT.renderText(url,fl)}url=new_url}if(/fypage/.test(url)){if(url.includes("(")&&url.includes(")")){leturl_rep=url.match(/.*?\((.*)\)/)[1];letcnt_page=url_rep.replaceAll("fypage",cateObj.pg);letcnt_pg=eval(cnt_page);url=url.replaceAll(url_rep,cnt_pg).replaceAll("(","").replaceAll(")","")}else{url=url.replaceAll("fypage",cateObj.pg)}}if(cateObj.pg===1&&url.includes("[")&&url.includes("]")){url=url.split("[")[1].split("]")[0]}MY_URL=url;console.log(MY_URL);p=p.trim();constMY_CATE=cateObj.tid;if(p.startsWith("js:")){varMY_FL=cateObj.extend;constTYPE="cate";varinput=MY_URL;constMY_PAGE=cateObj.pg;vardesc="";eval(p.trim().replace("js:",""));d=VODS}else{p=p.split(";");if(p.length<5){return"{}"}let_ps=parseTags.getParse(p[0]);_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;letis_json=p[0].startsWith("json:");p[0]=p[0].replace(/^(jsp:|json:|jq:)/,"");try{lethtml=getHtml(MY_URL);if(html){if(is_json){html=dealJson(html)}letlist=_pdfa(html,p[0]);list.forEach(it=>{letlinks=p[4].split("+").map(p4=>{return!rule.detailUrl?_pd(it,p4,MY_URL):_pdfh(it,p4)});letlink=links.join("$");letvod_id=rule.detailUrl?MY_CATE+"$"+link:link;d.push({vod_id:vod_id,vod_name:_pdfh(it,p[1]).replace(/\n|\t/g,"").trim(),vod_pic:_pd(it,p[2],MY_URL),vod_remarks:_pdfh(it,p[3]).replace(/\n|\t/g,"").trim()})})}}catch(e){console.log(e.message)}}returnd.length<1?"{}":JSON.stringify({page:parseInt(cateObj.pg),pagecount:999,limit:20,total:999,list:d})}functionsearchParse(searchObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letd=[];if(!searchObj.searchUrl){return"{}"}letp=searchObj.搜索==="*"&&rule.一级?rule.一级:searchObj.搜索;if(!p||typeofp!=="string"){return"{}"}p=p.trim();leturl=searchObj.searchUrl.replaceAll("**",searchObj.wd).replaceAll("fypage",searchObj.pg);MY_URL=url;console.log(MY_URL);if(p.startsWith("js:")){constTYPE="search";constMY_PAGE=searchObj.pg;constKEY=searchObj.wd;varinput=MY_URL;vardetailUrl=rule.detailUrl||"";eval(p.trim().replace("js:",""));d=VODS}else{p=p.split(";");if(p.length<5){return"{}"}let_ps=parseTags.getParse(p[0]);_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;letis_json=p[0].startsWith("json:");p[0]=p[0].replace(/^(jsp:|json:|jq:)/,"");try{lethtml=getHtml(MY_URL);if(html){if(/系统安全验证|输入验证码/.test(html)){letcookie=verifyCode(MY_URL);if(cookie){console.log(`本次成功过验证,cookie:${cookie}`);setItem(RULE_CK,cookie)}else{console.log(`本次自动过搜索验证失败,cookie:${cookie}`)}html=getHtml(MY_URL)}if(!html.includes(searchObj.wd)){console.log("搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码");console.log(html)}if(is_json){html=dealJson(html)}letlist=_pdfa(html,p[0]);list.forEach(it=>{letlinks=p[4].split("+").map(p4=>{return!rule.detailUrl?_pd(it,p4,MY_URL):_pdfh(it,p4)});letlink=links.join("$");letob={vod_id:link,vod_name:_pdfh(it,p[1]).replace(/\n|\t/g,"").trim(),vod_pic:_pd(it,p[2],MY_URL),vod_remarks:_pdfh(it,p[3]).replace(/\n|\t/g,"").trim()};if(p.length>5&&p[5]){ob.vod_content=_pdfh(it,p[5])}d.push(ob)})}}catch(e){return"{}"}}returnJSON.stringify({page:parseInt(searchObj.pg),pagecount:10,limit:20,total:100,list:d})}functiondetailParse(detailObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));letvod={vod_id:"id",vod_name:"片名",vod_pic:"",type_name:"剧情",vod_year:"年份",vod_area:"地区",vod_remarks:"更新信息",vod_actor:"主演",vod_director:"导演",vod_content:"简介"};letp=detailObj.二级;leturl=detailObj.url;letdetailUrl=detailObj.detailUrl;letfyclass=detailObj.fyclass;lettab_exclude=detailObj.tab_exclude;lethtml=detailObj.html||"";MY_URL=url;console.log(MY_URL);if(p==="*"){vod.vod_play_from="道长在线";vod.vod_remarks=detailUrl;vod.vod_actor="没有二级,只有一级链接直接嗅探播放";vod.vod_content=MY_URL;vod.vod_play_url="嗅探播放$"+MY_URL}elseif(typeofp==="string"&&p.trim().startsWith("js:")){constTYPE="detail";varinput=MY_URL;eval(p.trim().replace("js:",""));vod=VOD;console.log(JSON.stringify(vod))}elseif(p&&typeofp==="object"){if(!html){html=getHtml(MY_URL)}let_ps;if(p.is_json){_ps=parseTags.json;html=dealJson(html)}elseif(p.is_jsp){_ps=parseTags.jsp}elseif(p.is_jq){_ps=parseTags.jq}else{_ps=parseTags.jq}_pdfa=_ps.pdfa;_pdfh=_ps.pdfh;_pd=_ps.pd;if(p.title){letp1=p.title.split(";");vod.vod_name=_pdfh(html,p1[0]).replace(/\n|\t/g,"").trim();lettype_name=p1.length>1?_pdfh(html,p1[1]).replace(/\n|\t/g,"").replace(/ /g,"").trim():"";vod.type_name=type_name||vod.type_name}if(p.desc){try{letp1=p.desc.split(";");vod.vod_remarks=_pdfh(html,p1[0]).replace(/\n|\t/g,"").trim();vod.vod_year=p1.length>1?_pdfh(html,p1[1]).replace(/\n|\t/g,"").trim():"";vod.vod_area=p1.length>2?_pdfh(html,p1[2]).replace(/\n|\t/g,"").trim():"";vod.vod_actor=p1.length>3?_pdfh(html,p1[3]).replace(/\n|\t/g,"").trim():"";vod.vod_director=p1.length>4?_pdfh(html,p1[4]).replace(/\n|\t/g,"").trim():""}catch(e){}}if(p.content){try{letp1=p.content.split(";");vod.vod_content=_pdfh(html,p1[0]).replace(/\n|\t/g,"").trim()}catch(e){}}if(p.img){try{letp1=p.img.split(";");vod.vod_pic=_pd(html,p1[0],MY_URL)}catch(e){}}letvod_play_from="$$$";letplayFrom=[];if(p.重定向&&p.重定向.startsWith("js:")){html=eval(p.重定向.replace("js:",""))}if(p.tabs){letp_tab=p.tabs.split(";")[0];console.log(p_tab);letvHeader=_pdfa(html,p_tab);console.log(vHeader.length);for(letvofvHeader){letv_title=_pdfh(v,"body&&Text");console.log(v_title);if(tab_exclude&&newRegExp(tab_exclude).test(v_title)){continue}playFrom.push(v_title)}console.log(JSON.stringify(playFrom))}else{playFrom=["道长在线"]}vod.vod_play_from=playFrom.join(vod_play_from);letvod_play_url="$$$";letvod_tab_list=[];if(p.lists){for(leti=0;i<playFrom.length;i++){lettab_name=playFrom[i];lettab_ext=p.tabs.split(";").length>1?p.tabs.split(";")[1]:"";letp1=p.lists.replaceAll("#idv",tab_name).replaceAll("#id",i);tab_ext=tab_ext.replaceAll("#idv",tab_name).replaceAll("#id",i);console.log(p1);letvodList=[];try{vodList=_pdfa(html,p1);console.log("len(vodList):"+vodList.length)}catch(e){}letnew_vod_list=[];lettabName=tab_ext?_pdfh(html,tab_ext):tab_name;console.log(tabName);vodList.forEach(it=>{new_vod_list.push(cheerio.load(it).text()+"$"+_pd(it,"a&&href",MY_URL))});letvlist=new_vod_list.join("#");vod_tab_list.push(vlist)}}vod.vod_play_url=vod_tab_list.join(vod_play_url)}returnJSON.stringify({list:[vod]})}functionplayParse(playObj){fetch_params=JSON.parse(JSON.stringify(rule_fetch_params));MY_URL=playObj.url;if(!/http/.test(MY_URL)){try{MY_URL=base64Decode(MY_URL)}catch(e){}}MY_URL=decodeURIComponent(MY_URL);varinput=MY_URL;letcommon_play={parse:1,url:input};letlazy_play;if(!rule.play_parse||!rule.lazy){lazy_play=common_play}elseif(rule.play_parse&&rule.lazy&&typeofrule.lazy==="string"){try{letlazy_code=rule.lazy.replace("js:","").trim();print("开始执行js免嗅=>"+lazy_code);eval(lazy_code);lazy_play=typeofinput==="object"?input:{parse:1,jx:1,url:input}}catch(e){print("js免嗅错误:"+e.message);lazy_play=common_play}}else{lazy_play=common_play}console.log(JSON.stringify(lazy_play));returnJSON.stringify(lazy_play)}functioninit(ext){console.log("init");try{if(typeofglobalThis.mubanJs==="undefined"){letmubanJs=request("https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js",{"User-Agent":MOBILE_UA});mubanJs=mubanJs.replace("export default","(function() {return muban;}()) // export default");globalThis.mubanJs=mubanJs}letmuban=eval(globalThis.mubanJs);if(typeofext=="object"){rule=ext;if(rule.template){rule=Object.assign(muban[rule.template],rule)}}elseif(typeofext=="string"){if(ext.startsWith("http")){letjs=request(ext,{method:"GET"});if(js){eval(js.replace("var rule","rule"))}}}else{eval(ext.replace("var rule","rule"))}letrule_cate_excludes=(rule.cate_exclude||"").split("|").filter(it=>it.trim());letrule_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("|");rule.tab_exclude=rule_tab_excludes.join("|");rule.host=(rule.host||"").rstrip("/");rule.url=rule.url||"";rule.double=rule.double||false;rule.homeUrl=rule.homeUrl||"";rule.detailUrl=rule.detailUrl||"";rule.searchUrl=rule.searchUrl||"";rule.homeUrl=rule.host&&rule.homeUrl?urljoin(rule.host,rule.homeUrl):rule.homeUrl||rule.host;rule.detailUrl=rule.host&&rule.detailUrl?urljoin(rule.host,rule.detailUrl):rule.detailUrl;if(rule.url.includes("[")&&rule.url.includes("]")){letu1=rule.url.split("[")[0];letu2=rule.url.split("[")[1].split("]")[0];rule.url=rule.host&&rule.url?urljoin(rule.host,u1)+"["+urljoin(rule.host,u2)+"]":rule.url}else{rule.url=rule.host&&rule.url?urljoin(rule.host,rule.url):rule.url}rule.searchUrl=rule.host&&rule.searchUrl?urljoin(rule.host,rule.searchUrl):rule.searchUrl;rule.timeout=rule.timeout||5e3;rule.encoding=rule.编码||rule.encoding||"utf-8";if(rule.headers&&typeofrule.headers==="object"){try{letheader_keys=Object.keys(rule.headers);for(letkofheader_keys){if(k.toLowerCase()==="user-agent"){letv=rule.headers[k];console.log(v);if(["MOBILE_UA","PC_UA","UC_UA","IOS_UA","UA"].includes(v)){rule.headers[k]=eval(v)}}}}catch(e){console.log("处理headers发生错误:"+e.message)}}rule_fetch_params={headers:rule.headers||false,timeout:rule.timeout,encoding:rule.encoding};oheaders=rule.headers||{};RKEY=typeofkey!=="undefined"&&key?key:"drpy_"+(rule.title||rule.host);init_test()}catch(e){console.log("init_test发生错误:"+e.message)}}functionhome(filter){console.log("home");lethomeObj={filter:rule.filter||false,MY_URL:rule.homeUrl,class_name:rule.class_name||"",class_url:rule.class_url||"",class_parse:rule.class_parse||"",cate_exclude:rule.cate_exclude};returnhomeParse(homeObj)}functionhomeVod(params){lethomeVodObj={"推荐":rule.推荐,double:rule.double,homeUrl:rule.homeUrl,detailUrl:rule.detailUrl};returnhomeVodParse(homeVodObj)}functioncategory(tid,pg,filter,extend){letcateObj={url:rule.url,"一级":rule.一级,tid:tid,pg:parseInt(pg),filter:filter,extend:extend};returncategoryParse(cateObj)}functiondetail(vod_url){letfyclass="";if(vod_url.indexOf("$")>-1){lettmp=vod_url.split("$");fyclass=tmp[0];vod_url=tmp[1]}letdetailUrl=vod_url;leturl;if(!detailUrl.startsWith("http")&&!detailUrl.includes("/")){url=rule.detailUrl.replaceAll("fyid",detailUrl).replaceAll("fyclass",fyclass)}elseif(detailUrl.includes("/")){url=urljoin(rule.homeUrl,detailUrl)}else{url=detailUrl}letdetailObj={url:url,"二级":rule.二级,detailUrl:detailUrl,fyclass:fyclass,tab_exclude:rule.tab_exclude};returndetailParse(detailObj)}functionplay(flag,id,flags){letplayObj={url:id,flag:flag,flags:flags};returnplayParse(playObj)}functionsearch(wd,quick){letsearchObj={searchUrl:rule.searchUrl,"搜索":rule.搜索,wd:wd,pg:1,quick:quick};returnsearchParse(searchObj)}functionDRPY(){return{init:init,home:home,homeVod:homeVod,category:category,detail:detail,play:play,search:search}}exportdefault{init:init,home:home,homeVod:homeVod,category:category,detail:detail,play:play,search:search,DRPY:DRPY};