drpy2.js 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500
  1. import cheerio from './cheerio.min.js';
  2. import './crypto-js.js';
  3. import './jsencrypt.js';
  4. import './node-rsa.js';
  5. import './pako.min.js';
  6. // import JSEncrypt from './jsencrypt.js'; // 会导致壳子崩溃的
  7. import 模板 from './模板.js'
  8. import {gbkTool} from './gbk.js'
  9. // import cheerio from "https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/cheerio.min.js";
  10. // import "https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/crypto-js.js";
  11. // import 模板 from"https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/js/模板.js";
  12. // import {gbkTool} from 'https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/gbk.js'
  13. function init_test() {
  14. // console.log(typeof(CryptoJS));
  15. console.log("init_test_start");
  16. // print(模板);
  17. // print(typeof(模板.getMubans));
  18. console.log("当前版本号:" + VERSION);
  19. console.log('本地代理地址:' + getProxyUrl());
  20. console.log(RKEY);
  21. // ocr_demo_test();
  22. // rsa_demo_test();
  23. // console.log('Uint8Array:'+typeof(Uint8Array)+' '+'Uint16Array:'+typeof(Uint16Array));
  24. // console.log('encodeURIComponent:'+typeof(encodeURIComponent)+' '+'decodeURIComponent:'+typeof(decodeURIComponent));
  25. // console.log('atob:'+typeof(atob)+' '+'btoa:'+typeof(btoa));
  26. // log('typeof (JSEncrypt):'+typeof (JSEncrypt));
  27. // log('typeof (pako):'+typeof (pako));
  28. // let b64_str = btoa('hello hipy');
  29. // let str = atob(b64_str);
  30. // console.log(`btoa加密文本:${b64_str},atob解密文本:${str}`)
  31. // let gzip_str = gzip('{"a":"电影","b":"电影","c":"电影","d":"电影","e":"电影","f":"电影"}');
  32. // let ungzip_str = ungzip(gzip_str);
  33. // console.log(`gzip加密文本:${gzip_str},长度:${gzip_str.length},ungzip解密文本:${ungzip_str},长度:${ungzip_str.length}`);
  34. // let a = {"1":[{"key":"类型","name":"类型","value":[{"n":"全部","v":""},{"n":"Netflix","v":"NETFLIX"},{"n":"剧情","v":"剧情"},{"n":"喜剧","v":"喜剧"},{"n":"动作","v":"动作"},{"n":"爱情","v":"爱情"},{"n":"恐怖","v":"恐怖"},{"n":"惊悚","v":"惊悚"},{"n":"犯罪","v":"犯罪"},{"n":"科幻","v":"科幻"},{"n":"悬疑","v":"悬疑"},{"n":"奇幻","v":"奇幻"},{"n":"冒险","v":"冒险"},{"n":"战争","v":"战争"},{"n":"历史","v":"历史"},{"n":"古装","v":"古装"},{"n":"家庭","v":"家庭"},{"n":"传记","v":"传记"},{"n":"武侠","v":"武侠"},{"n":"歌舞","v":"歌舞"},{"n":"短片","v":"短片"},{"n":"动画","v":"动画"},{"n":"儿童","v":"儿童"},{"n":"职场","v":"职场"}]},{"key":"地区","name":"地区","value":[{"n":"全部","v":""},{"n":"大陆","v":"中国大陆"},{"n":"香港","v":"中国香港"},{"n":"台湾","v":"中国台湾"},{"n":"美国","v":"美国"},{"n":"日本","v":"日本"},{"n":"韩国","v":"韩国"},{"n":"英国","v":"英国"},{"n":"法国","v":"法国"},{"n":"德国","v":"德国"},{"n":"印度","v":"印度"},{"n":"泰国","v":"泰国"},{"n":"丹麦","v":"丹麦"},{"n":"瑞典","v":"瑞典"},{"n":"巴西","v":"巴西"},{"n":"加拿大","v":"加拿大"},{"n":"俄罗斯","v":"俄罗斯"},{"n":"意大利","v":"意大利"},{"n":"比利时","v":"比利时"},{"n":"爱尔兰","v":"爱尔兰"},{"n":"西班牙","v":"西班牙"},{"n":"澳大利亚","v":"澳大利亚"},{"n":"其他","v":"其他"}]},{"key":"语言","name":"语言","value":[{"n":"全部","v":""},{"n":"国语","v":"国语"},{"n":"粤语","v":"粤语"},{"n":"英语","v":"英语"},{"n":"日语","v":"日语"},{"n":"韩语","v":"韩语"},{"n":"法语","v":"法语"},{"n":"其他","v":"其他"}]},{"key":"年份","name":"年份","value":[{"n":"全部","v":""},{"n":"2024","v":"2024"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"10年代","v":"2010_2019"},{"n":"00年代","v":"2000_2009"},{"n":"90年代","v":"1990_1999"},{"n":"80年代","v":"1980_1989"},{"n":"更早","v":"0_1979"}]},{"key":"排序","name":"排序","value":[{"n":"综合","v":""},{"n":"最新","v":"2"},{"n":"最热","v":"3"},{"n":"评分","v":"4"}]}],"2":[{"key":"类型","name":"类型","value":[{"n":"全部","v":""},{"n":"Netflix","v":"Netflix"},{"n":"剧情","v":"剧情"},{"n":"爱情","v":"爱情"},{"n":"喜剧","v":"喜剧"},{"n":"犯罪","v":"犯罪"},{"n":"悬疑","v":"悬疑"},{"n":"古装","v":"古装"},{"n":"动作","v":"动作"},{"n":"家庭","v":"家庭"},{"n":"惊悚","v":"惊悚"},{"n":"奇幻","v":"奇幻"},{"n":"美剧","v":"美剧"},{"n":"科幻","v":"科幻"},{"n":"历史","v":"历史"},{"n":"战争","v":"战争"},{"n":"韩剧","v":"韩剧"},{"n":"武侠","v":"武侠"},{"n":"言情","v":"言情"},{"n":"恐怖","v":"恐怖"},{"n":"冒险","v":"冒险"},{"n":"都市","v":"都市"},{"n":"职场","v":"职场"}]},{"key":"地区","name":"地区","value":[{"n":"地区","v":""},{"n":"大陆","v":"中国大陆"},{"n":"香港","v":"中国香港"},{"n":"韩国","v":"韩国"},{"n":"美国","v":"美国"},{"n":"日本","v":"日本"},{"n":"法国","v":"法国"},{"n":"英国","v":"英国"},{"n":"德国","v":"德国"},{"n":"台湾","v":"中国台湾"},{"n":"泰国","v":"泰国"},{"n":"印度","v":"印度"},{"n":"其他","v":"其他"}]},{"key":"语言","name":"语言","value":[{"n":"全部","v":""},{"n":"国语","v":"国语"},{"n":"粤语","v":"粤语"},{"n":"英语","v":"英语"},{"n":"日语","v":"日语"},{"n":"韩语","v":"韩语"},{"n":"法语","v":"法语"},{"n":"其他","v":"其他"}]},{"key":"年份","name":"年份","value":[{"n":"全部","v":""},{"n":"2024","v":"2024"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"10年代","v":"2010_2019"},{"n":"00年代","v":"2000_2009"},{"n":"90年代","v":"1990_1999"},{"n":"80年代","v":"1980_1989"},{"n":"更早","v":"0_1979"}]},{"key":"排序","name":"排序","value":[{"n":"综合","v":""},{"n":"最新","v":"2"},{"n":"最热","v":"3"},{"n":"评分","v":"4"}]}],"3":[{"key":"类型","name":"类型","value":[{"n":"全部","v":""},{"n":"Netflix","v":"Netflix"},{"n":"动态漫画","v":"动态漫画"},{"n":"剧情","v":"剧情"},{"n":"动画","v":"动画"},{"n":"喜剧","v":"喜剧"},{"n":"冒险","v":"冒险"},{"n":"动作","v":"动作"},{"n":"奇幻","v":"奇幻"},{"n":"科幻","v":"科幻"},{"n":"儿童","v":"儿童"},{"n":"搞笑","v":"搞笑"},{"n":"爱情","v":"爱情"},{"n":"家庭","v":"家庭"},{"n":"短片","v":"短片"},{"n":"热血","v":"热血"},{"n":"益智","v":"益智"},{"n":"悬疑","v":"悬疑"},{"n":"经典","v":"经典"},{"n":"校园","v":"校园"},{"n":"Anime","v":"Anime"},{"n":"运动","v":"运动"},{"n":"亲子","v":"亲子"},{"n":"青春","v":"青春"},{"n":"恋爱","v":"恋爱"},{"n":"武侠","v":"武侠"},{"n":"惊悚","v":"惊悚"}]},{"key":"地区","name":"地区","value":[{"n":"全部","v":""},{"n":"日本","v":"日本"},{"n":"大陆","v":"中国大陆"},{"n":"台湾","v":"中国台湾"},{"n":"美国","v":"美国"},{"n":"香港","v":"中国香港"},{"n":"韩国","v":"韩国"},{"n":"英国","v":"英国"},{"n":"法国","v":"法国"},{"n":"德国","v":"德国"},{"n":"印度","v":"印度"},{"n":"泰国","v":"泰国"},{"n":"丹麦","v":"丹麦"},{"n":"瑞典","v":"瑞典"},{"n":"巴西","v":"巴西"},{"n":"加拿大","v":"加拿大"},{"n":"俄罗斯","v":"俄罗斯"},{"n":"意大利","v":"意大利"},{"n":"比利时","v":"比利时"},{"n":"爱尔兰","v":"爱尔兰"},{"n":"西班牙","v":"西班牙"},{"n":"澳大利亚","v":"澳大利亚"},{"n":"其他","v":"其他"}]},{"key":"语言","name":"语言","value":[{"n":"全部","v":""},{"n":"国语","v":"国语"},{"n":"粤语","v":"粤语"},{"n":"英语","v":"英语"},{"n":"日语","v":"日语"},{"n":"韩语","v":"韩语"},{"n":"法语","v":"法语"},{"n":"其他","v":"其他"}]},{"key":"年份","name":"年份","value":[{"n":"全部","v":""},{"n":"2024","v":"2024"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"10年代","v":"2010_2019"},{"n":"00年代","v":"2000_2009"},{"n":"90年代","v":"1990_1999"},{"n":"80年代","v":"1980_1989"},{"n":"更早","v":"0_1979"}]},{"key":"排序","name":"排序","value":[{"n":"综合","v":""},{"n":"最新","v":"2"},{"n":"最热","v":"3"},{"n":"评分","v":"4"}]}],"4":[{"key":"类型","name":"类型","value":[{"n":"全部","v":""},{"n":"纪录","v":"纪录"},{"n":"真人秀","v":"真人秀"},{"n":"记录","v":"记录"},{"n":"脱口秀","v":"脱口秀"},{"n":"剧情","v":"剧情"},{"n":"历史","v":"历史"},{"n":"喜剧","v":"喜剧"},{"n":"传记","v":"传记"},{"n":"相声","v":"相声"},{"n":"节目","v":"节目"},{"n":"歌舞","v":"歌舞"},{"n":"冒险","v":"冒险"},{"n":"运动","v":"运动"},{"n":"Season","v":"Season"},{"n":"犯罪","v":"犯罪"},{"n":"短片","v":"短片"},{"n":"搞笑","v":"搞笑"},{"n":"晚会","v":"晚会"}]},{"key":"地区","name":"地区","value":[{"n":"全部","v":""},{"n":"大陆","v":"中国大陆"},{"n":"香港","v":"中国香港"},{"n":"台湾","v":"中国台湾"},{"n":"美国","v":"美国"},{"n":"日本","v":"日本"},{"n":"韩国","v":"韩国"},{"n":"其他","v":"其他"}]},{"key":"语言","name":"语言","value":[{"n":"全部","v":""},{"n":"国语","v":"国语"},{"n":"粤语","v":"粤语"},{"n":"英语","v":"英语"},{"n":"日语","v":"日语"},{"n":"韩语","v":"韩语"},{"n":"法语","v":"法语"},{"n":"其他","v":"其他"}]},{"key":"年份","name":"年份","value":[{"n":"全部","v":""},{"n":"2024","v":"2024"},{"n":"2023","v":"2023"},{"n":"2022","v":"2022"},{"n":"2021","v":"2021"},{"n":"2020","v":"2020"},{"n":"10年代","v":"2010_2019"},{"n":"00年代","v":"2000_2009"},{"n":"90年代","v":"1990_1999"},{"n":"80年代","v":"1980_1989"},{"n":"更早","v":"0_1979"}]},{"key":"排序","name":"排序","value":[{"n":"综合","v":""},{"n":"最新","v":"2"},{"n":"最热","v":"3"},{"n":"评分","v":"4"}]}],"6":[{"key":"类型","name":"类型","value":[{"n":"类型","v":""},{"n":"逆袭","v":"逆袭"},{"n":"甜宠","v":"甜宠"},{"n":"虐恋","v":"虐恋"},{"n":"穿越","v":"穿越"},{"n":"重生","v":"重生"},{"n":"剧情","v":"剧情"},{"n":"科幻","v":"科幻"},{"n":"武侠","v":"武侠"},{"n":"爱情","v":"爱情"},{"n":"动作","v":"动作"},{"n":"战争","v":"战争"},{"n":"冒险","v":"冒险"},{"n":"其它","v":"其它"}]},{"key":"排序","name":"排序","value":[{"n":"综合","v":""},{"n":"最新","v":"2"},{"n":"最热","v":"3"}]}]};
  35. // log(gzip(JSON.stringify(a)));
  36. console.log(JSON.stringify(rule));
  37. console.log("init_test_end");
  38. // log('typeof (JSEncrypt):'+typeof (JSEncrypt));
  39. // let publicKey = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwEc7wBMtYKkxvrQNI3+ITBZwAkPkGvsv4TsAHFskKGZWz9eYl3scivhmlEfWHlEkdyb0m82CmB1qAgef+pD4cZu+Cdmm2e9lnExhLwm8cBgpkAen9QRNdjojZgxM0W+JcReH4W6pw+uFXiLRn4AIQkDftWGNLg6wlNS+39Z/RvP9zyATJLZ9AKDdHp62XMxEK1KZvWBuIg+Oa5UzgA9jy+2XyIqwhBtO8tPbUl21t2pvTzHoLUjSkPNm2LurcUk6+jQ2r6aiS2CN1NXIucPJU6mkuIQ821SjvkYPtIdRMntW4y2u4cyiqVEEQwlzWVMHh+/vfrWAQr9fgjDuYYtvPQIDAQAB';
  40. // let privateKey = 'MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDARzvAEy1gqTG+tA0jf4hMFnACQ+Qa+y/hOwAcWyQoZlbP15iXexyK+GaUR9YeUSR3JvSbzYKYHWoCB5/6kPhxm74J2abZ72WcTGEvCbxwGCmQB6f1BE12OiNmDEzRb4lxF4fhbqnD64VeItGfgAhCQN+1YY0uDrCU1L7f1n9G8/3PIBMktn0AoN0enrZczEQrUpm9YG4iD45rlTOAD2PL7ZfIirCEG07y09tSXbW3am9PMegtSNKQ82bYu6txSTr6NDavpqJLYI3U1ci5w8lTqaS4hDzbVKO+Rg+0h1Eye1bjLa7hzKKpUQRDCXNZUweH7+9+tYBCv1+CMO5hi289AgMBAAECggEBAIRbRJUWXmEwdq64kGbELlV6CIZ2p3mvOSlIjO34Cy7IK7AMz9xOgbpj/XDK9miOIJTouu7ZC7GcZdGZ4BUCYBMMS0fKjGFuurpZlXhkslNTPqEHtCUkXhIpOR7RDrwIlErGEOIsZC4aXQcM3tF1t7mroJLh4OY4dHMu82lv5NM4hhFMNvHzXVvrPXeTzw26gddHVG/ke0WUYOcB5j3cPp8xaVp7JV8bdxtGtkqIfBLY/dIczzJu/3F3cBpU2nNwt8uVUF/w/HKlr7j8FqqFHXWh182beU0n5AIdRyRJBrRUAEhdtsUnvJOVBDqzZa+9DJ5395F7V8KRlQptxETdhCECgYEA4x/2HM9fnVIhG6wTbEt1LhGTKYb/igMAHLqquEMfRsB44tobI8gVNwR3qJQY/nKXxcQemQV29PcdqpENCKyXUXGD8SI1UPg15rHFBI8CIqlCXfzJybdHjmzlhaA9I5lofIVh+5MW7WkvHZoRy7NeDMhHUuaiveuqC4OJ8n+dD2kCgYEA2LkmUVef3WkBBwUBRdkyoog3DMwR+/ubb0ncJVYy3ItYVJltQ4HqmrRiJc8xBAoFnG8rbiqDnmTnDR3WbuxU1G2hml09fqId+rQds2UfESswCXHU43A4f77m1XyA6PprBxpozVIcmK69N4rR9jOXflLWo3O+p2ipUbmNpId7+rUCgYBSpcbBJRT+AmzZzPwkZDD32p1ady114zGfQq3s7z/qVw+mPQezNZPCuXVxerK9pKVl6b/Ynwxyh5nb/3xms6c8k7oXfQM5u5ihof63cfKs+jqUSPCE3pTDVw0OWwjkc2Z6KW9GRHgLXEMw2mevYE3RCPArUpHV2nO+TNddzuIwQQKBgQDOZwdnUNygMfEYjlu3+jOPN8u2FGTMZ8SRKPbRWFb4VH27lKPLN2AIFuOivsEf56uQYRAry7GumMq0Y0ZmPg5Mglz2dvaqNBv5OLFQuW3tHAST+iWWtroYb+fISts7B8QG79AAO8OgZksvKrbslBYj6SEiaomZRsR7YQzVNXOOQQKBgQCovElZ50c8ZJ6m9D9fw3Nes7u9vshpyyac5tt4tZ7yfU4l5pWGrIUqCE703qZp4NAqEvlZUCJbj9kkysaj/2MfFb2b9jSvdNB+V/YW9Cwg+5TziYoOcQzN1z2u4p4goTAv0S+pTNSr3qWaTUI4TXUXQajif45Fexv+MrP5AAXQyw=='
  41. // // let text = '你好';
  42. // let text = '[{"vod_name":"兔小贝原创儿歌","vod_pic":"https://resource-cdn.tuxiaobei.com/video-album/FnQ8ieJHgsbgCKWXNBg4uoOmKgG5.jpg","vod_remarks":"共229首","vod_content":"","vod_id":"/subject/17@@兔小贝原创儿歌@@https://resource-cdn.tuxiaobei.com/video-album/FnQ8ieJHgsbgCKWXNBg4uoOmKgG5.jpg"},{"vod_name":"英文儿歌","vod_pic":"https://resource-cdn.tuxiaobei.com/video-album/Fqjpx2H_-QaYNAYn2MekRuDpeyUv.jpg","vod_remarks":"共10首","vod_content":"","vod_id":"/subject/23@@英文儿歌@@https://resource-cdn.tuxiaobei.com/video-album/Fqjpx2H_-QaYNAYn2MekRuDpeyUv.jpg"}]';
  43. // let str = RSA.encode(text, publicKey);
  44. // console.log("加密数据:" + str);
  45. // let str1 = 'Wa2c/868VOm0PgpGG2s2aMrDbGOlJRdZXlSGswjFgywd3nZNB7ND8kVMdNB/OsNFoQXJXSJMvPaE73BH7rs8fz54JGdYQK+qTgfQRqQZvomCjbzseSR4bm4NOrtIOOslL3WqxlzOuU0M1P1eERmkLEVU2WSyc3RGtJro3b3MOWYCNdKMoZdncfOHJndkl4wm9V3GGc3uH98hs6OxLvBWgXoW9jZQ3n0vR2FtS2KYrPGuSuKGkxlt9Kw5TD6nri142NOimz05WK55Xe04YUQ1VZd51t0wzJGXolWgfzIQaK2zzhk5Zjlm+IQJxXqEWiJ2+O6TJ+lIttvsDSaUflcDXQ==';
  46. // let str2 = 'R86mW9DzBw05pxBSh9ECh1stXxINmnudgZBbzU/cz1EcFgrEgdk0Zk4ruAiJZB2fP5c7d3gMmN8+Dv19IfARWSzw85xCEjUhpdcMJ0jn6ZE5H+muadND9LzjeVisojqwYxot3YVdKof7HMhPFN8QR0jfzqhjmnGFTlY1jMXzJK0MSOLNRLDar480CdKNb/cxALC8+xKIlhM9E4B31t8J4rNMUWSCAr49lbZ3jx3PxieBpTQUdDJz96AttR93Pc+c51wrxh0Ch/Mt4Rs09HGMXwIpNV+CxsGwSGRQUlyJo2k3d0WqsVzpz6S8A4VGEMTRLGI3IjEt+eWt7wM3nAXarg==';
  47. // let str3 = 'D4eOsRqua+jYA5+ZOR9PLI2PExKjKfArQfv9/wGeG50bQSjWypShJPY6RQfO+rghyf0juzHIUSxqH91OxinhCFkONaF2Vod2QVyphyn9eh73dAcEFKIFFKGXoPCjbMWrr3p4d+hgVrHzrFeGqkRq8JFOvG2L5XDxVfWbV8KmUA0DKuz6QwWg7P4kesy+C7BbLALy5W/wfZchD3gnsBvx/pjFoe11VfAify9isLxg9a15jj52xr6lzQ9kge9C2JcV8yq85bFKaUpJWgobzz+BSIv3lVMU6vgcldmOrhkyiETpFGFGGF00DphGCEoK6uAyyNDh7+Jn8P17zf/DW1wV3A==';
  48. // let uncrypted = RSA.decode(str, privateKey);
  49. // log('解密数据:'+uncrypted);
  50. // uncrypted = RSA.decode(str1, privateKey);
  51. // log('解密数据1:'+uncrypted);
  52. // uncrypted = RSA.decode(str2, privateKey);
  53. // log('解密数据2:'+uncrypted);
  54. // uncrypted = RSA.decode(str3, privateKey);
  55. // log('解密数据3:'+uncrypted);
  56. // log('rsax:'+typeof(rsax));
  57. // log('rsaX:'+typeof(rsaX));
  58. // let data = base64Encode('你好');
  59. // let publicKey = 'dzyyds';
  60. // console.log(typeof (RSA.encode));
  61. // let encryptBase64Data = RSA.encode(data,publicKey);
  62. // log('encryptBase64Data:'+encryptBase64Data);
  63. // let str = RSA.decode(data,publicKey);
  64. // log('str:'+str);
  65. }
  66. /**
  67. * 验证码ocr识别的测试案例
  68. */
  69. function ocr_demo_test() {
  70. // 这张图片为4113的验证码
  71. let img_base64 = `iVBORw0KGgoAAAANSUhEUgAAAIAAAAAoBAMAAADEX+97AAAAG1BMVEXz+/4thQTa7N6QwIFFkyNeokKozqDB3b93sWHFR+MEAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABN0lEQVRIie2TQU+DQBCFt9vScvQpxR4xrcSjJCZ67JDGXsX+AdR4B3vpsSYm/m2HXaRLmuySepR3Gdidb/btDAjRq5dT96eCMlfBuzi1QLZUoZy2yz5sOvI+9iomaPEZ6nWnEtxqIyiM1RcAy44GNDhBXUjot/VVNweV1ah68FqWRyjKIOqAcyYF6rGcmpYnHzGt3fycNoMw0d3/THFu7hFSJ/8OXO6iTM8/KSg09obAzIHLO250LgQ0txOZSfgrV4Exdw98uGycJ0ErAeExZGhOmFHV9zHO6qVSj0MpLq7xZON56o++MjlsEgfVhbQWWME+xQX7J4V6zfi9A1Ly9rP1BvEXp+BbVJ/M77n+wfOIDVp51pZ4iBxvmj9AGrtvry6emwfKnVkW+ZRKd5ZNMvob36vXP9YPDmQki8QiCFAAAAAASUVORK5CYII=`;
  72. // 更换api-可以通过这个代码换掉默认的ocr接口
  73. OcrApi.api = OCR_API;
  74. let code = OcrApi.classification(img_base64);
  75. log('测试验证码图片的ocr识别结果为:' + code);
  76. }
  77. /**
  78. * rsa加解密的全方位测试案例
  79. */
  80. function rsa_demo_test() {
  81. let t1 = new Date().getTime();
  82. let pkcs1_public = `
  83. -----BEGIN RSA PUBLIC KEY-----
  84. MEgCQQCrI0pQ/ERRpJ3Ou190XJedFq846nDYP52rOtXyDxlFK5D3p6JJu2RwsKwy
  85. lsQ9xY0xYPpRZUZKMEeR7e9gmRNLAgMBAAE=
  86. -----END RSA PUBLIC KEY-----
  87. `.trim();
  88. let pkcs1_public_pem = `
  89. MEgCQQCrI0pQ/ERRpJ3Ou190XJedFq846nDYP52rOtXyDxlFK5D3p6JJu2RwsKwy
  90. lsQ9xY0xYPpRZUZKMEeR7e9gmRNLAgMBAAE=
  91. `.trim();
  92. let pkcs8_public = `
  93. -----BEGIN PUBLIC KEY-----
  94. MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKsjSlD8RFGknc67X3Rcl50WrzjqcNg/
  95. nas61fIPGUUrkPenokm7ZHCwrDKWxD3FjTFg+lFlRkowR5Ht72CZE0sCAwEAAQ==
  96. -----END PUBLIC KEY-----`.trim();
  97. let pkcs8_public_pem = `
  98. MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKsjSlD8RFGknc67X3Rcl50WrzjqcNg/
  99. nas61fIPGUUrkPenokm7ZHCwrDKWxD3FjTFg+lFlRkowR5Ht72CZE0sCAwEAAQ==
  100. `.trim();
  101. let pkcs1_private = `
  102. -----BEGIN RSA PRIVATE KEY-----
  103. MIIBOAIBAAJBAKsjSlD8RFGknc67X3Rcl50WrzjqcNg/nas61fIPGUUrkPenokm7
  104. ZHCwrDKWxD3FjTFg+lFlRkowR5Ht72CZE0sCAwEAAQI/b6OV1z65UokQaMvSeRXt
  105. 0Yv6wiYtduQI9qpq5nzy/ytaqsbBfClNTi/HifKPKxlRouWFkc518EQI8LBxoarJ
  106. AiEA4DaONMplV8PQNa3TKn2F+SDEvLOCjdL0kHKdN90Ti28CIQDDZnTBaHgZwZbA
  107. hS7Bbf5yvwjWMhO6Y7l04/Qm7R+35QIgPuQuqXIoUSD080mp1N5WyRW++atksIF+
  108. 5lGv9e6GP/MCICnj8y/rl6Pd7tXDN6zcSeqLrfdNsREKhB3dKOCXgW9JAiAFYtFS
  109. EJNBXVRTK42SNsZ2hJ/9xLwOwnH2epT8Q43s3Q==
  110. -----END RSA PRIVATE KEY-----
  111. `.trim()
  112. let pkcs8_private = `
  113. -----BEGIN PRIVATE KEY-----
  114. MIIBUgIBADANBgkqhkiG9w0BAQEFAASCATwwggE4AgEAAkEAqyNKUPxEUaSdzrtf
  115. dFyXnRavOOpw2D+dqzrV8g8ZRSuQ96eiSbtkcLCsMpbEPcWNMWD6UWVGSjBHke3v
  116. YJkTSwIDAQABAj9vo5XXPrlSiRBoy9J5Fe3Ri/rCJi125Aj2qmrmfPL/K1qqxsF8
  117. KU1OL8eJ8o8rGVGi5YWRznXwRAjwsHGhqskCIQDgNo40ymVXw9A1rdMqfYX5IMS8
  118. s4KN0vSQcp033ROLbwIhAMNmdMFoeBnBlsCFLsFt/nK/CNYyE7pjuXTj9CbtH7fl
  119. AiA+5C6pcihRIPTzSanU3lbJFb75q2SwgX7mUa/17oY/8wIgKePzL+uXo93u1cM3
  120. rNxJ6out902xEQqEHd0o4JeBb0kCIAVi0VIQk0FdVFMrjZI2xnaEn/3EvA7CcfZ6
  121. lPxDjezd
  122. -----END PRIVATE KEY-----
  123. `.trim()
  124. let data = `
  125. NodeRsa
  126. 这是node-rsa 现在修改集成在drpy里使用`.trim();
  127. let encryptedWithPublic = NODERSA.encryptRSAWithPublicKey(data, pkcs1_public, {
  128. // PublicFormat: "pkcs1-public-pem",
  129. outputEncoding: "base64",
  130. options: {environment: "browser", encryptionScheme: 'pkcs1_oaep'},
  131. });
  132. console.log("公钥加密");
  133. console.log(encryptedWithPublic);
  134. let decryptedWithPrivate = NODERSA.decryptRSAWithPrivateKey(encryptedWithPublic, pkcs1_private, {
  135. // PublicFormat: "pkcs1-private",
  136. // outEncoding: "hex"
  137. options: {environment: "browser", encryptionScheme: 'pkcs1_oaep'},
  138. });
  139. console.log("私钥解密");
  140. console.log(decryptedWithPrivate);
  141. // https://www.btool.cn/rsa-sign
  142. let pkcs1_sha256_sign = NODERSA.sign("1", pkcs1_private, {
  143. outputEncoding: "base64",
  144. options: {environment: "browser", encryptionScheme: 'pkcs1', signingScheme: "pkcs1-sha256"},
  145. });
  146. console.log("pkcs1_sha256_sign");
  147. console.log(pkcs1_sha256_sign);
  148. let pkcs1_sha256_sign_verify = NODERSA.verify("1", "Oulx2QrgeipKYBtqEDqFb2s/+ndk2cGQxO4CkhU7iBM1vyNmmvqubpsmeoUuN3waGrYZLknSEdwBkfv0tUMpFQ==", pkcs1_private, {
  149. options: {environment: "browser", encryptionScheme: 'pkcs1', signingScheme: "pkcs1-sha256"},
  150. });
  151. console.log("pkcs1_sha256_sign_verify");
  152. console.log(pkcs1_sha256_sign_verify);
  153. let pkcs1_oaep_sha256 = NODERSA.encryptRSAWithPublicKey(data, `-----BEGIN RSA PUBLIC KEY-----
  154. MIIBCgKCAQEA5KOq1gRNyllLNWKQy8sGpZE3Q1ULLSmzZw+eaAhj9lvqn7IsT1du
  155. SYn08FfoOA2qMwtz+1O2l1mgzNoSVCyVpVabnTG+C9XKeZXAnJHd8aYA7l7Sxhdm
  156. kte+iymYZ0ZBPzijo8938iugtVvqi9UgDmnY3u/NlQDqiL5BGqSxSTd/Sgmy3zD8
  157. PYzEa3wD9vehQ5fZZ45vKIq8GNVh2Z8+IGO85FF1OsN7+b2yGJa/FmDDNn0+HP+m
  158. PfI+kYBqEVpo0Ztbc3UdxgFwGC8O1n8AQyriwHnSOtIiuBH62J/7qyC/3LEAApRb
  159. Dd9YszqzmODjQUddZKHmvc638VW+azc0EwIDAQAB
  160. -----END RSA PUBLIC KEY-----
  161. `, {
  162. outputEncoding: "base64",
  163. options: {
  164. environment: "browser", encryptionScheme: {
  165. scheme: "pkcs1_oaep",
  166. hash: "sha256",
  167. },
  168. }
  169. // options: { environment: "browser", encryptionScheme: 'pkcs1' },
  170. });
  171. console.log("pkcs1_oaep_sha256");
  172. console.log(pkcs1_oaep_sha256);
  173. decryptedWithPrivate = NODERSA.decryptRSAWithPrivateKey("kSZesAAyYh2hdsQnYMdGqb6gKAzTauBKouvBzWcc4+F8RvGd0nwO6mVkUMVilPgUuNxjEauHayHiY8gI3Py45UI3+km0rSGyHrS6dHiHgCkMejXHieglYzAB0IxX3Jkm4z/66bdB/D+GFy0oct5fGCMI1UHPjEAYOsazJDa8lBFNbjiWFeb/qiZtIx3vGM7KYPAZzyRf/zPbbQ8zy9xOmRuOl5nnIxgo0Okp3KO/RIPO4GZOSBA8f2lx1UtNwwrXAMpcNavtoqHVcjJ/9lcotXYQFrn5b299pSIRf2gVm8ZJ31SK6Z8cc14nKtvgnmsgClDzIXJ1o1RcDK+knVAySg==", `-----BEGIN RSA PRIVATE KEY-----
  174. MIIEpAIBAAKCAQEA5KOq1gRNyllLNWKQy8sGpZE3Q1ULLSmzZw+eaAhj9lvqn7Is
  175. T1duSYn08FfoOA2qMwtz+1O2l1mgzNoSVCyVpVabnTG+C9XKeZXAnJHd8aYA7l7S
  176. xhdmkte+iymYZ0ZBPzijo8938iugtVvqi9UgDmnY3u/NlQDqiL5BGqSxSTd/Sgmy
  177. 3zD8PYzEa3wD9vehQ5fZZ45vKIq8GNVh2Z8+IGO85FF1OsN7+b2yGJa/FmDDNn0+
  178. HP+mPfI+kYBqEVpo0Ztbc3UdxgFwGC8O1n8AQyriwHnSOtIiuBH62J/7qyC/3LEA
  179. ApRbDd9YszqzmODjQUddZKHmvc638VW+azc0EwIDAQABAoIBADZ/QGgUzInvsLp/
  180. zO2WbfYm39o/uhNAvk9RbLt1TIZbMFhyOpeKynHi3Swwd9xsfWX/U9zS/lGi/m31
  181. iKrhmaW4OA1G3vqpMcK7TBbFufYwUEaA+ZJX344euH8pIfdzyneMQ4z3Far2dS7l
  182. QsmjuilVV2kEFadveXewiYoVOWCu00w6bN8wy2SIHlQn+kIL6HQhWz12iKKflIKu
  183. eGRdzLHsKmBt6WbY1Wuhx7HU0fAKdlBDPxCHNlI+kybUYE9o5C2vJiaVM5wqJBgZ
  184. 8Dz8kt1QbLJ910JoLXkLVQ8uC8NJKQwFtqQjTGPnEq0+wbgz6Ij599rKZkwW/xq9
  185. l6KoUiECgYEA6Ah42tVdkNW047f03xVYXFH96RgorHRS36mR8Y+ONUq1fwKidovC
  186. WjwVujt4OPf3l1W6iyn/F6cu/bsmvPrSc3HTN0B1V31QK4OjgetxQ2PSbTldH02J
  187. NPzkt+v+cPxXpx/P5mgt7Weefw5txU547KubGrHUV5rBKFtIx9pj16MCgYEA/EF0
  188. o19+D24DZAPwlDS5VbEd7FStnwY4oQ5PqbuNOSbSJLMWU0AqzXcRokp8UTyCZ0X3
  189. ATkS1REq97kShCuR+npTR6a6DlY7sdpPI1SMLNajgB2tkx0EOzX+PfNIbHUd4jpJ
  190. I0ZMAHv/OOtkzQHDaeTWBTrzsWm6/nTiykfduNECgYEA46AMD4HpPECqKAs66e5i
  191. tI6q7JSKskObWVdcmQEfnSAhVOwcvPb2Ptda6UuV8S0xcwDi88rLOUUFUFzc79+P
  192. vTkY38cYVi/VChsluDpk7ptqv0PbGu5Rf+3n4pZdEjI7OvR2W64wAAn67uIUxc7p
  193. yiO/ET0K9rYWb6S9jXGtKMkCgYEA2kPAqoO7zZoBMQ7/oR0lp/HC1HRIbiqx4RlC
  194. 8Lgpb+QZPEwA6zPAVVvLVENi4d+bbcRp/xLlKpraNNJcJSSWAMbLPFoU7sbKjA87
  195. HnTPfRSTEA2d3Ibk3F7Rh8TzS3Ti0JZiJjVzGZAwu41iAMifzwaD8K6boUy80eNN
  196. QH2CaaECgYBUsLYvC/MiYg3w+LGOONuQongoVUXjGqnw2bjVa9RK7lwRdXPUqJ51
  197. MpVO98IkoLvGSI/0sGNP3GKNhC+eMGjJAVwFyEuOn+JsmMv9Y9uStIVi5tIHIhKw
  198. m7mp8il0kaftHdSxTbspG3tZ2fjIiFIZkLEOmRpd7ogWumgOajzUdA==
  199. -----END RSA PRIVATE KEY-----`, {
  200. // PublicFormat: "pkcs1-private",
  201. // outEncoding: "hex"
  202. options: {environment: "browser", encryptionScheme: 'pkcs1_oaep'},
  203. });
  204. console.log('decryptedWithPrivate');
  205. console.log(decryptedWithPrivate);
  206. (() => {
  207. let key = new NODERSA.NodeRSA({b: 1024});
  208. key.setOptions({encryptionScheme: 'pkcs1'})
  209. let text = `你好drpy node-ras`;
  210. let encrypted = key.encrypt(text, 'base64');
  211. console.log('encrypted: ', encrypted);
  212. const decrypted = key.decrypt(encrypted, 'utf8');
  213. console.log('decrypted: ', decrypted);
  214. })();
  215. let t2 = new Date().getTime();
  216. console.log('rsa_demo_test 测试耗时:' + (t2 - t1) + '毫秒');
  217. }
  218. /**
  219. * 执行预处理代码
  220. */
  221. function pre() {
  222. if (typeof (rule.预处理) === 'string' && rule.预处理 && rule.预处理.trim()) {
  223. let code = rule.预处理.trim();
  224. console.log("执行预处理代码:" + code);
  225. if (code.startsWith('js:')) {
  226. code = code.replace('js:', '');
  227. }
  228. try {
  229. // code里可以进行get 或者 post请求cookie并改变rule.headers 里的cookie
  230. // 直接操作 rule_fetch_params 这个变量 .headers.Cookie
  231. eval(code);
  232. } catch (e) {
  233. console.log('预处理执行失败:' + e.message);
  234. }
  235. }
  236. }
  237. let rule = {};
  238. let vercode = typeof (pdfl) === 'function' ? 'drpy2.1' : 'drpy2';
  239. const VERSION = vercode + ' 3.9.50beta26 20240605';
  240. /** 已知问题记录
  241. * 1.影魔的jinjia2引擎不支持 {{fl}}对象直接渲染 (有能力解决的话尽量解决下,支持对象直接渲染字符串转义,如果加了|safe就不转义)[影魔牛逼,最新的文件发现这问题已经解决了]
  242. * Array.prototype.append = Array.prototype.push; 这种js执行后有毛病,for in 循环列表会把属性给打印出来 (这个大毛病需要重点排除一下)
  243. * 2.import es6py.js但是里面的函数没有被装载进来.比如drpy规则报错setResult2 is undefiend(合并文件了可以不管了)
  244. * 3.无法重复导入cheerio(怎么解决drpy和parseTag里都需要导入cheerio的问题) 无法在副文件导入cheerio (现在是全部放在drpy一个文件里了,凑合解决?)
  245. * 4.有个错误不知道哪儿来的 executeScript: com.quickjs.JSObject$Undefined cannot be cast to java.lang.String 在 点击选集播放打印init_test_end后面打印(貌似不影响使用)
  246. * 5.需要实现 stringify 函数,比起JSON.strifngify函数,它会原封不动保留中文不会编码unicode
  247. * 6.base64Encode,base64Decode,md5函数还没有实现 (抄影魔代码实现了)
  248. * 7.eval(getCryptoJS());还没有实现 (可以空实现了,以后遇到能忽略)
  249. * done: jsp:{pdfa,pdfh,pd},json:{pdfa,pdfh,pd},jq:{pdfa,pdfh,pd}
  250. * 8.req函数不支持传递字符串的data参数 {'content-type':'text/plain'} 类型数据,因此无法直接调用alist的ocr接口
  251. * * 电脑看日志调试
  252. adb tcpip 5555
  253. adb connect 192.168.10.192
  254. adb devices -l
  255. adb logcat -c
  256. adb logcat | grep -i QuickJS
  257. adb logcat -c -b events
  258. adb logcat -c -b main -b events -b radio -b system
  259. adb logcat > 2.log DRPY:E | grep -i QuickJS
  260. * **/
  261. /*** 以下是内置变量和解析方法 **/
  262. const MOBILE_UA = 'Mozilla/5.0 (Linux; Android 11; Pixel 5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.91 Mobile Safari/537.36';
  263. 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';
  264. const UA = 'Mozilla/5.0';
  265. 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';
  266. 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';
  267. const RULE_CK = 'cookie'; // 源cookie的key值
  268. // const KEY = typeof(key)!=='undefined'&&key?key:'drpy_' + (rule.title || rule.host); // 源的唯一标识
  269. const CATE_EXCLUDE = '首页|留言|APP|下载|资讯|新闻|动态';
  270. const TAB_EXCLUDE = '猜你|喜欢|下载|剧情|榜|评论';
  271. const OCR_RETRY = 3;//ocr验证重试次数
  272. // const OCR_API = 'http://drpy.nokia.press:8028/ocr/drpy/text';//ocr在线识别接口
  273. const OCR_API = 'https://api.nn.ci/ocr/b64/text';//ocr在线识别接口
  274. if (typeof (MY_URL) === 'undefined') {
  275. var MY_URL; // 全局注入变量,pd函数需要
  276. }
  277. var HOST;
  278. var RKEY; // 源的唯一标识
  279. var fetch;
  280. var print;
  281. var log;
  282. var rule_fetch_params;
  283. var fetch_params; // 每个位置单独的
  284. var oheaders;
  285. // var play_url; // 二级详情页注入变量,为了适配js模式0 (不在这里定义了,直接二级里定义了个空字符串)
  286. var _pdfh;
  287. var _pdfa;
  288. var _pd;
  289. // const DOM_CHECK_ATTR = ['url', 'src', 'href', 'data-original', 'data-src'];
  290. const DOM_CHECK_ATTR = /(url|src|href|-original|-src|-play|-url|style)$/;
  291. // 过滤特殊链接,不走urlJoin
  292. const SPECIAL_URL = /^(ftp|magnet|thunder|ws):/;
  293. const NOADD_INDEX = /:eq|:lt|:gt|:first|:last|^body$|^#/; // 不自动加eq下标索引
  294. const URLJOIN_ATTR = /(url|src|href|-original|-src|-play|-url|style)$|^(data-|url-|src-)/; // 需要自动urljoin的属性
  295. const SELECT_REGEX = /:eq|:lt|:gt|#/g;
  296. const SELECT_REGEX_A = /:eq|:lt|:gt/g;
  297. // 增加$js工具,支持$js.toString(()=>{});
  298. const $js = {
  299. toString(func) {
  300. let strfun = func.toString();
  301. return strfun.replace(/^\(\)(\s+)?=>(\s+)?\{/, "js:").replace(/\}$/, '');
  302. }
  303. };
  304. function window_b64() {
  305. let b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  306. let base64DecodeChars = new Array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
  307. function btoa(str) {
  308. var out, i, len;
  309. var c1, c2, c3;
  310. len = str.length;
  311. i = 0;
  312. out = "";
  313. while (i < len) {
  314. c1 = str.charCodeAt(i++) & 0xff;
  315. if (i == len) {
  316. out += b64map.charAt(c1 >> 2);
  317. out += b64map.charAt((c1 & 0x3) << 4);
  318. out += "==";
  319. break;
  320. }
  321. c2 = str.charCodeAt(i++);
  322. if (i == len) {
  323. out += b64map.charAt(c1 >> 2);
  324. out += b64map.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  325. out += b64map.charAt((c2 & 0xF) << 2);
  326. out += "=";
  327. break;
  328. }
  329. c3 = str.charCodeAt(i++);
  330. out += b64map.charAt(c1 >> 2);
  331. out += b64map.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
  332. out += b64map.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
  333. out += b64map.charAt(c3 & 0x3F);
  334. }
  335. return out;
  336. }
  337. function atob(str) {
  338. var c1, c2, c3, c4;
  339. var i, len, out;
  340. len = str.length;
  341. i = 0;
  342. out = "";
  343. while (i < len) {
  344. do {
  345. c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  346. } while (i < len && c1 == -1);
  347. if (c1 == -1) break;
  348. do {
  349. c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
  350. } while (i < len && c2 == -1);
  351. if (c2 == -1) break;
  352. out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));
  353. do {
  354. c3 = str.charCodeAt(i++) & 0xff;
  355. if (c3 == 61) return out;
  356. c3 = base64DecodeChars[c3];
  357. } while (i < len && c3 == -1);
  358. if (c3 == -1) break;
  359. out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));
  360. do {
  361. c4 = str.charCodeAt(i++) & 0xff;
  362. if (c4 == 61) return out;
  363. c4 = base64DecodeChars[c4];
  364. } while (i < len && c4 == -1);
  365. if (c4 == -1) break;
  366. out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
  367. }
  368. return out;
  369. }
  370. return {
  371. atob,
  372. btoa
  373. }
  374. }
  375. /**
  376. es6py扩展
  377. */
  378. if (typeof atob != 'function' || typeof btoa != 'function') {
  379. var {atob, btoa} = window_b64();
  380. }
  381. if (typeof Object.assign != 'function') {
  382. Object.assign = function () {
  383. let target = arguments[0];
  384. for (let i = 1; i < arguments.length; i++) {
  385. let source = arguments[i];
  386. for (let key in source) {
  387. if (Object.prototype.hasOwnProperty.call(source, key)) {
  388. target[key] = source[key];
  389. }
  390. }
  391. }
  392. return target;
  393. };
  394. }
  395. if (!String.prototype.includes) {
  396. String.prototype.includes = function (search, start) {
  397. if (typeof start !== 'number') {
  398. start = 0;
  399. }
  400. if (start + search.length > this.length) {
  401. return false;
  402. } else {
  403. return this.indexOf(search, start) !== -1;
  404. }
  405. };
  406. }
  407. if (!Array.prototype.includes) {
  408. Object.defineProperty(Array.prototype, 'includes', {
  409. value: function (searchElement, fromIndex) {
  410. if (this == null) {//this是空或者未定义,抛出错误
  411. throw new TypeError('"this" is null or not defined');
  412. }
  413. var o = Object(this);//将this转变成对象
  414. var len = o.length >>> 0;//无符号右移0位,获取对象length属性,如果未定义就会变成0
  415. if (len === 0) {//length为0直接返回false未找到目标值
  416. return false;
  417. }
  418. var n = fromIndex | 0;//查找起始索引
  419. var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);//计算正确起始索引,因为有可能是负值
  420. while (k < len) {//从起始索引处开始循环
  421. if (o[k] === searchElement) {//如果某一位置与寻找目标相等,返回true,找到了
  422. return true;
  423. }
  424. k++;
  425. }
  426. return false;//未找到,返回false
  427. },
  428. enumerable: false
  429. });
  430. }
  431. if (typeof String.prototype.startsWith != 'function') {
  432. String.prototype.startsWith = function (prefix) {
  433. return this.slice(0, prefix.length) === prefix;
  434. };
  435. }
  436. if (typeof String.prototype.endsWith != 'function') {
  437. String.prototype.endsWith = function (suffix) {
  438. return this.indexOf(suffix, this.length - suffix.length) !== -1;
  439. };
  440. }
  441. Object.defineProperty(Object.prototype, 'myValues', {
  442. value: function (obj) {
  443. if (obj == null) {
  444. throw new TypeError("Cannot convert undefined or null to object");
  445. }
  446. var res = []
  447. for (var k in obj) {
  448. if (obj.hasOwnProperty(k)) {//需判断是否是本身的属性
  449. res.push(obj[k]);
  450. }
  451. }
  452. return res;
  453. },
  454. enumerable: false
  455. });
  456. if (typeof Object.prototype.values != 'function') {
  457. Object.defineProperty(Object.prototype, 'values', {
  458. value: function (obj) {
  459. if (obj == null) {
  460. throw new TypeError("Cannot convert undefined or null to object");
  461. }
  462. var res = []
  463. for (var k in obj) {
  464. if (obj.hasOwnProperty(k)) {//需判断是否是本身的属性
  465. res.push(obj[k]);
  466. }
  467. }
  468. return res;
  469. },
  470. enumerable: false
  471. });
  472. }
  473. if (typeof Array.prototype.join != 'function') {
  474. Object.defineProperty(Array.prototype, 'join', {
  475. value: function (emoji) {
  476. // emoji = emoji||',';
  477. emoji = emoji || '';
  478. let self = this;
  479. let str = "";
  480. let i = 0;
  481. if (!Array.isArray(self)) {
  482. throw String(self) + 'is not Array'
  483. }
  484. if (self.length === 0) {
  485. return ''
  486. }
  487. if (self.length === 1) {
  488. return String(self[0])
  489. }
  490. i = 1;
  491. str = this[0];
  492. for (; i < self.length; i++) {
  493. str += String(emoji) + String(self[i]);
  494. }
  495. return str;
  496. },
  497. enumerable: false
  498. });
  499. }
  500. if (typeof Array.prototype.toReversed != 'function') {
  501. Object.defineProperty(Array.prototype, 'toReversed', {
  502. value: function () {
  503. const clonedList = this.slice();
  504. // 倒序新数组
  505. const reversedList = clonedList.reverse();
  506. return reversedList;
  507. },
  508. enumerable: false
  509. });
  510. }
  511. Object.defineProperty(Array.prototype, 'append', {
  512. value: Array.prototype.push,
  513. enumerable: false
  514. });
  515. Object.defineProperty(String.prototype, 'strip', {
  516. value: String.prototype.trim,
  517. enumerable: false
  518. });
  519. Object.defineProperty(String.prototype, 'rstrip', {
  520. value: function (chars) {
  521. let regex = new RegExp(chars + "$");
  522. return this.replace(regex, "");
  523. },
  524. enumerable: false
  525. });
  526. function 是否正版(vipUrl) {
  527. let flag = new RegExp('qq\.com|iqiyi\.com|youku\.com|mgtv\.com|bilibili\.com|sohu\.com|ixigua\.com|pptv\.com|miguvideo\.com|le\.com|1905\.com|fun\.tv');
  528. return flag.test(vipUrl);
  529. }
  530. function urlDeal(vipUrl) {
  531. if (!vipUrl) {
  532. return ''
  533. }
  534. if (!是否正版(vipUrl)) {
  535. return vipUrl
  536. }
  537. if (!/miguvideo/.test(vipUrl)) {
  538. vipUrl = vipUrl.split('#')[0].split('?')[0];
  539. }
  540. return vipUrl
  541. }
  542. function setResult(d) {
  543. if (!Array.isArray(d)) {
  544. return []
  545. }
  546. VODS = [];
  547. // print(d);
  548. d.forEach(function (it) {
  549. let obj = {
  550. vod_id: it.url || '',
  551. vod_name: it.title || '',
  552. vod_remarks: it.desc || '',
  553. vod_content: it.content || '',
  554. vod_pic: it.pic_url || it.img || '',
  555. };
  556. let keys = Object.keys(it);
  557. if (keys.includes('tname')) {
  558. obj.type_name = it.tname || '';
  559. }
  560. if (keys.includes('tid')) {
  561. obj.type_id = it.tid || '';
  562. }
  563. if (keys.includes('year')) {
  564. obj.vod_year = it.year || '';
  565. }
  566. if (keys.includes('actor')) {
  567. obj.vod_actor = it.actor || '';
  568. }
  569. if (keys.includes('director')) {
  570. obj.vod_director = it.director || '';
  571. }
  572. if (keys.includes('area')) {
  573. obj.vod_area = it.area || '';
  574. }
  575. VODS.push(obj);
  576. });
  577. return VODS
  578. }
  579. function setResult2(res) {
  580. VODS = res.list || [];
  581. return VODS
  582. }
  583. function setHomeResult(res) {
  584. if (!res || typeof (res) !== 'object') {
  585. return []
  586. }
  587. return setResult(res.list);
  588. }
  589. // 猫了个咪
  590. function rc(js) {
  591. if (js === 'maomi_aes.js') {
  592. var a = CryptoJS.enc.Utf8.parse("625222f9149e961d");
  593. var t = CryptoJS.enc.Utf8.parse("5efdtf6060e2o330");
  594. return {
  595. De: function (word) {
  596. word = CryptoJS.enc.Hex.parse(word)
  597. return CryptoJS.AES.decrypt(CryptoJS.enc.Base64.stringify(word), a, {
  598. iv: t,
  599. mode: CryptoJS.mode.CBC,
  600. padding: CryptoJS.pad.Pkcs7
  601. }).toString(CryptoJS.enc.Utf8)
  602. },
  603. En: function (word) {
  604. // print(a);
  605. // print(word);
  606. var Encrypted = CryptoJS.AES.encrypt(word, a, {
  607. iv: t,
  608. mode: CryptoJS.mode.CBC,
  609. padding: CryptoJS.pad.Pkcs7
  610. });
  611. return Encrypted.ciphertext.toString();
  612. }
  613. };
  614. }
  615. return {};
  616. }
  617. // 千万不要用for in 推荐 forEach (for in 会打乱顺序)
  618. //猫函数
  619. function maoss(jxurl, ref, key) {
  620. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  621. eval(getCryptoJS());
  622. try {
  623. var getVideoInfo = function (text) {
  624. return CryptoJS.AES.decrypt(text, key, {iv: iv, padding: CryptoJS.pad.Pkcs7}).toString(CryptoJS.enc.Utf8);
  625. };
  626. var token_key = key == undefined ? 'dvyYRQlnPRCMdQSe' : key;
  627. if (ref) {
  628. var html = request(jxurl, {
  629. headers: {
  630. 'Referer': ref
  631. }
  632. });
  633. } else {
  634. var html = request(jxurl);
  635. }
  636. // print(html);
  637. if (html.indexOf('&btwaf=') != -1) {
  638. html = request(jxurl + '&btwaf' + html.match(/&btwaf(.*?)"/)[1], {
  639. headers: {
  640. 'Referer': ref
  641. }
  642. })
  643. }
  644. var token_iv = html.split('_token = "')[1].split('"')[0];
  645. var key = CryptoJS.enc.Utf8.parse(token_key);
  646. var iv = CryptoJS.enc.Utf8.parse(token_iv);
  647. // log("iv:"+iv);
  648. // log(html);
  649. // print(key);
  650. // print(iv);
  651. eval(html.match(/var config = {[\s\S]*?}/)[0] + '');
  652. // config.url = config.url.replace(/,/g,'');
  653. // print(config.url);
  654. if (!config.url.startsWith('http')) {
  655. //config.url = decodeURIComponent(AES(config.url, key, iv));
  656. config.url = CryptoJS.AES.decrypt(config.url, key, {
  657. iv: iv,
  658. padding: CryptoJS.pad.Pkcs7
  659. }).toString(CryptoJS.enc.Utf8)
  660. }
  661. return config.url;
  662. } catch (e) {
  663. return '';
  664. }
  665. }
  666. /**
  667. * 将base64编码进行url编译
  668. * @param str
  669. * @returns {string}
  670. */
  671. function urlencode(str) {
  672. str = (str + '').toString();
  673. return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A').replace(/%20/g, '+');
  674. }
  675. /**
  676. * url编码,同 encodeURI
  677. * @param str
  678. * @returns {string}
  679. */
  680. function encodeUrl(str) {
  681. if (typeof (encodeURI) == 'function') {
  682. return encodeURI(str)
  683. } else {
  684. str = (str + '').toString();
  685. return encodeURIComponent(str).replace(/%2F/g, '/').replace(/%3F/g, '?').replace(/%3A/g, ':').replace(/%40/g, '@').replace(/%3D/g, '=').replace(/%3A/g, ':').replace(/%2C/g, ',').replace(/%2B/g, '+').replace(/%24/g, '$');
  686. }
  687. }
  688. function base64Encode(text) {
  689. return CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(text));
  690. // return text
  691. }
  692. function base64Decode(text) {
  693. return CryptoJS.enc.Utf8.stringify(CryptoJS.enc.Base64.parse(text));
  694. // return text
  695. }
  696. function md5(text) {
  697. return CryptoJS.MD5(text).toString();
  698. }
  699. function uint8ArrayToBase64(uint8Array) {
  700. let binaryString = String.fromCharCode.apply(null, Array.from(uint8Array));
  701. return btoa(binaryString);
  702. }
  703. function Utf8ArrayToStr(array) {
  704. var out, i, len, c;
  705. var char2, char3;
  706. out = "";
  707. len = array.length;
  708. i = 0;
  709. while (i < len) {
  710. c = array[i++];
  711. switch (c >> 4) {
  712. case 0:
  713. case 1:
  714. case 2:
  715. case 3:
  716. case 4:
  717. case 5:
  718. case 6:
  719. case 7:
  720. out += String.fromCharCode(c);
  721. break;
  722. case 12:
  723. case 13:
  724. char2 = array[i++];
  725. out += String.fromCharCode(((c & 0x1f) << 6) | (char2 & 0x3f));
  726. break;
  727. case 14:
  728. char2 = array[i++];
  729. char3 = array[i++];
  730. out += String.fromCharCode(
  731. ((c & 0x0f) << 12) | ((char2 & 0x3f) << 6) | ((char3 & 0x3f) << 0)
  732. );
  733. break;
  734. }
  735. }
  736. return out;
  737. }
  738. /**
  739. * gzip压缩base64|压缩率80%+
  740. * @param str
  741. * @returns {string}
  742. */
  743. function gzip(str) {
  744. let arr = pako.gzip(str, {
  745. to: 'string'
  746. });
  747. return uint8ArrayToBase64(arr)
  748. }
  749. /**
  750. * gzip解压base64数据
  751. * @param b64Data
  752. * @returns {string}
  753. */
  754. function ungzip(b64Data) {
  755. let strData = atob(b64Data);
  756. const charData = strData.split('').map(function (x) {
  757. return x.charCodeAt(0);
  758. });
  759. const binData = new Uint8Array(charData);
  760. const data = pako.inflate(binData);
  761. return Utf8ArrayToStr(data);
  762. }
  763. /**
  764. * 字符串按指定编码
  765. * @param input
  766. * @param encoding
  767. * @returns {*}
  768. */
  769. function encodeStr(input, encoding) {
  770. encoding = encoding || 'gbk';
  771. if (encoding.startsWith('gb')) {
  772. const strTool = gbkTool();
  773. input = strTool.encode(input);
  774. }
  775. return input
  776. }
  777. /**
  778. * 字符串指定解码
  779. * @param input
  780. * @param encoding
  781. * @returns {*}
  782. */
  783. function decodeStr(input, encoding) {
  784. encoding = encoding || 'gbk';
  785. if (encoding.startsWith('gb')) {
  786. const strTool = gbkTool();
  787. input = strTool.decode(input);
  788. }
  789. return input
  790. }
  791. function getCryptoJS() {
  792. // return request('https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/libs/crypto-hiker.js');
  793. return 'console.log("CryptoJS已装载");'
  794. }
  795. // 封装的RSA加解密类
  796. const RSA = {
  797. decode: function (data, key, option) {
  798. option = option || {};
  799. if (typeof (JSEncrypt) === 'function') {
  800. let chunkSize = option.chunkSize || 117; // 默认分段长度为117
  801. let privateKey = this.getPrivateKey(key); // 获取私钥
  802. const decryptor = new JSEncrypt(); //创建解密对象实例
  803. decryptor.setPrivateKey(privateKey); //设置秘钥
  804. let uncrypted = '';
  805. // uncrypted = decryptor.decrypt(data);
  806. uncrypted = decryptor.decryptUnicodeLong(data);
  807. return uncrypted;
  808. } else {
  809. return false
  810. }
  811. },
  812. encode: function (data, key, option) {
  813. option = option || {};
  814. if (typeof (JSEncrypt) === 'function') {
  815. let chunkSize = option.chunkSize || 117; // 默认分段长度为117
  816. let publicKey = this.getPublicKey(key); // 获取公钥
  817. const encryptor = new JSEncrypt();
  818. encryptor.setPublicKey(publicKey); // 设置公钥
  819. let encrypted = ''; // 加密结果
  820. // const textLen = data.length; // 待加密文本长度
  821. // let offset = 0; // 分段偏移量
  822. // // 分段加密
  823. // while (offset < textLen) {
  824. // let chunk = data.slice(offset, chunkSize); // 提取分段数据
  825. // let enc = encryptor.encrypt(chunk); // 加密分段数据
  826. // encrypted += enc; // 连接加密结果
  827. // offset += chunkSize; // 更新偏移量
  828. // }
  829. encrypted = encryptor.encryptUnicodeLong(data);
  830. return encrypted
  831. } else {
  832. return false
  833. }
  834. },
  835. fixKey(key, prefix, endfix) {
  836. if (!key.includes(prefix)) {
  837. key = prefix + key;
  838. }
  839. if (!key.includes(endfix)) {
  840. key += endfix
  841. }
  842. return key
  843. },
  844. getPrivateKey(key) {
  845. let prefix = '-----BEGIN RSA PRIVATE KEY-----';
  846. let endfix = '-----END RSA PRIVATE KEY-----';
  847. return this.fixKey(key, prefix, endfix);
  848. },
  849. getPublicKey(key) {
  850. let prefix = '-----BEGIN PUBLIC KEY-----';
  851. let endfix = '-----END PUBLIC KEY-----';
  852. return this.fixKey(key, prefix, endfix);
  853. }
  854. };
  855. /**
  856. * 获取壳子返回的代理地址
  857. * @returns {string|*}
  858. */
  859. function getProxyUrl() {
  860. if (typeof (getProxy) === 'function') {//判断壳子里有getProxy函数就执行取返回结果。否则取默认的本地
  861. return getProxy(true)
  862. } else {
  863. return 'http://127.0.0.1:9978/proxy?do=js'
  864. }
  865. }
  866. /**
  867. * 根据正则处理原始m3u8里的广告ts片段,自动修复相对链接
  868. * @param m3u8_text m3u8原始文本,里面是最末级的只含ts片段的。不支持嵌套m3u8链接
  869. * @param m3u8_url m3u8原始地址
  870. * @param ad_remove 正则表达式如: reg:/video/adjump(.*?)ts
  871. * @returns {string|DocumentFragment|*|string}
  872. */
  873. function fixAdM3u8(m3u8_text, m3u8_url, ad_remove) {
  874. if ((!m3u8_text && !m3u8_url) || (!m3u8_text && m3u8_url && !m3u8_url.startsWith('http'))) {
  875. return ''
  876. }
  877. if (!m3u8_text) {
  878. log('m3u8_url:' + m3u8_url);
  879. m3u8_text = request(m3u8_url);
  880. }
  881. log('len(m3u8_text):' + m3u8_text.length);
  882. if (!ad_remove) {
  883. return m3u8_text
  884. }
  885. if (ad_remove.startsWith('reg:')) {
  886. ad_remove = ad_remove.slice(4)
  887. } else if (ad_remove.startsWith('js:')) {
  888. ad_remove = ad_remove.slice(3)
  889. }
  890. let m3u8_start = m3u8_text.slice(0, m3u8_text.indexOf('#EXTINF')).trim();
  891. let m3u8_body = m3u8_text.slice(m3u8_text.indexOf('#EXTINF'), m3u8_text.indexOf('#EXT-X-ENDLIST')).trim();
  892. let m3u8_end = m3u8_text.slice(m3u8_text.indexOf('#EXT-X-ENDLIST')).trim();
  893. let murls = [];
  894. let m3_body_list = m3u8_body.split('\n');
  895. let m3_len = m3_body_list.length;
  896. let i = 0;
  897. while (i < m3_len) {
  898. let mi = m3_body_list[i];
  899. let mi_1 = m3_body_list[i + 1];
  900. if (mi.startsWith('#EXTINF')) {
  901. murls.push([mi, mi_1].join('&'));
  902. i += 2
  903. } else if (mi.startsWith('#EXT-X-DISCONTINUITY')) {
  904. let mi_2 = m3_body_list[i + 2];
  905. murls.push([mi, mi_1, mi_2].join('&'));
  906. i += 3
  907. } else {
  908. break;
  909. }
  910. }
  911. let new_m3u8_body = [];
  912. for (let murl of murls) {
  913. if (ad_remove && new RegExp(ad_remove).test(murl)) {
  914. } else {
  915. let murl_list = murl.split('&');
  916. if (!murl_list[murl_list.length - 1].startsWith('http') && m3u8_url.startsWith('http')) {
  917. murl_list[murl_list.length - 1] = urljoin(m3u8_url, murl_list[murl_list.length - 1]);
  918. }
  919. murl_list.forEach((it) => {
  920. new_m3u8_body.push(it);
  921. });
  922. }
  923. }
  924. new_m3u8_body = new_m3u8_body.join('\n').trim();
  925. m3u8_text = [m3u8_start, new_m3u8_body, m3u8_end].join('\n').trim();
  926. return m3u8_text
  927. }
  928. /**
  929. * 智能对比去除广告。支持嵌套m3u8。只需要传入播放地址
  930. * @param m3u8_url m3u8播放地址
  931. * @param headers 自定义访问m3u8的请求头,可以不传
  932. * @returns {string}
  933. */
  934. function fixAdM3u8Ai(m3u8_url, headers) {
  935. let ts = new Date().getTime();
  936. let option = headers ? {headers: headers} : {};
  937. function b(s1, s2) {
  938. let i = 0;
  939. while (i < s1.length) {
  940. if (s1[i] !== s2[i]) {
  941. break
  942. }
  943. i++
  944. }
  945. return i;
  946. }
  947. function reverseString(str) {
  948. return str.split('').reverse().join('');
  949. }
  950. //log('播放的地址:' + m3u8_url);
  951. let m3u8 = request(m3u8_url, option);
  952. //log('m3u8处理前:' + m3u8);
  953. m3u8 = m3u8.trim().split('\n').map(it => it.startsWith('#') ? it : urljoin(m3u8_url, it)).join('\n');
  954. //log('m3u8处理后:============:' + m3u8);
  955. // 获取嵌套m3u8地址
  956. m3u8 = m3u8.replace(/\n\n/ig, '\n');//删除多余的换行符
  957. let last_url = m3u8.split('\n').slice(-1)[0];
  958. if (last_url.length < 5) {
  959. last_url = m3u8.split('\n').slice(-2)[0];
  960. }
  961. if (last_url.includes('.m3u8') && last_url !== m3u8_url) {
  962. m3u8_url = urljoin2(m3u8_url, last_url);
  963. log('嵌套的m3u8_url:' + m3u8_url);
  964. m3u8 = request(m3u8_url, option);
  965. }
  966. //log('----处理有广告的地址----');
  967. let s = m3u8.trim().split('\n').filter(it => it.trim()).join('\n');
  968. let ss = s.split('\n')
  969. //找出第一条播放地址
  970. let firststr = ss.find(x => !x.startsWith('#'));
  971. let maxl = 0;//最大相同字符
  972. let firststrlen = firststr.length;
  973. //log('字符串长度:' + firststrlen);
  974. let ml = Math.round(ss.length / 2).toString().length;//取数据的长度的位数
  975. //log('数据条数的长度:' + ml);
  976. //找出最后一条播放地址
  977. let maxc = 0;
  978. let laststr = ss.toReversed().find((x) => {
  979. if (!x.startsWith('#')) {
  980. let k = b(reverseString(firststr), reverseString(x));
  981. maxl = b(firststr, x);
  982. maxc++;
  983. if (firststrlen - maxl <= ml + k || maxc > 10) {
  984. return true
  985. }
  986. }
  987. return false
  988. });
  989. log('最后一条切片:' + laststr);
  990. //log('最小相同字符长度:' + maxl);
  991. let ad_urls = [];
  992. for (let i = 0; i < ss.length; i++) {
  993. let s = ss[i];
  994. if (!s.startsWith('#')) {
  995. if (b(firststr, s) < maxl) {
  996. ad_urls.push(s); // 广告地址加入列表
  997. ss.splice(i - 1, 2);
  998. i = i - 2;
  999. } else {
  1000. ss[i] = urljoin(m3u8_url, s);
  1001. }
  1002. } else {
  1003. ss[i] = s.replace(/URI=\"(.*)\"/, 'URI=\"' + urljoin(m3u8_url, '$1') + '\"');
  1004. }
  1005. }
  1006. log('处理的m3u8地址:' + m3u8_url);
  1007. log('----广告地址----');
  1008. log(ad_urls);
  1009. m3u8 = ss.join('\n');
  1010. //log('处理完成');
  1011. log('处理耗时:' + (new Date().getTime() - ts).toString());
  1012. return m3u8
  1013. }
  1014. /**
  1015. * 强制正序算法
  1016. * @param lists 待正序列表
  1017. * @param key 正序键
  1018. * @param option 单个元素处理函数
  1019. * @returns {*}
  1020. */
  1021. function forceOrder(lists, key, option) {
  1022. let start = Math.floor(lists.length / 2);
  1023. let end = Math.min(lists.length - 1, start + 1);
  1024. if (start >= end) {
  1025. return lists;
  1026. }
  1027. let first = lists[start];
  1028. let second = lists[end];
  1029. if (key) {
  1030. try {
  1031. first = first[key];
  1032. second = second[key];
  1033. } catch (e) {
  1034. }
  1035. }
  1036. if (option && typeof (option) === 'function') {
  1037. try {
  1038. first = option(first);
  1039. second = option(second);
  1040. } catch (e) {
  1041. }
  1042. }
  1043. first += '';
  1044. second += '';
  1045. // console.log(first,second);
  1046. if (first.match(/(\d+)/) && second.match(/(\d+)/)) {
  1047. let num1 = Number(first.match(/(\d+)/)[1]);
  1048. let num2 = Number(second.match(/(\d+)/)[1]);
  1049. if (num1 > num2) {
  1050. lists.reverse();
  1051. }
  1052. }
  1053. return lists
  1054. }
  1055. let VODS = [];// 一级或者搜索需要的数据列表
  1056. let VOD = {};// 二级的单个数据
  1057. let TABS = [];// 二级的自定义线路列表 如: TABS=['道长在线','道长在线2']
  1058. let LISTS = [];// 二级的自定义选集播放列表 如: LISTS=[['第1集$http://1.mp4','第2集$http://2.mp4'],['第3集$http://1.mp4','第4集$http://2.mp4']]
  1059. /**
  1060. * 获取链接的query请求转为js的object字典对象
  1061. * @param url
  1062. * @returns {{}}
  1063. */
  1064. function getQuery(url) {
  1065. try {
  1066. if (url.indexOf('?') > -1) {
  1067. url = url.slice(url.indexOf('?') + 1);
  1068. }
  1069. let arr = url.split("#")[0].split("&");
  1070. const resObj = {};
  1071. arr.forEach(item => {
  1072. let arr1 = item.split("=");
  1073. let key = arr1[0];
  1074. let value = arr1.slice(1).join('=');
  1075. resObj[key] = value;
  1076. });
  1077. return resObj;
  1078. } catch (err) {
  1079. log('getQuery发生错误:' + e.message)
  1080. return {};
  1081. }
  1082. }
  1083. /**
  1084. * url拼接
  1085. * @param fromPath 初始当前页面url
  1086. * @param nowPath 相对当前页面url
  1087. * @returns {*}
  1088. */
  1089. function urljoin(fromPath, nowPath) {
  1090. fromPath = fromPath || '';
  1091. nowPath = nowPath || '';
  1092. return joinUrl(fromPath, nowPath);
  1093. // try {
  1094. // // import Uri from './uri.min.js';
  1095. // // var Uri = require('./uri.min.js');
  1096. // // eval(request('https://cdn.bootcdn.net/ajax/libs/URI.js/1.19.11/URI.min.js'));
  1097. // // let new_uri = URI(nowPath, fromPath);
  1098. // let new_uri = Uri(nowPath, fromPath);
  1099. // new_uri = new_uri.toString();
  1100. // // console.log(new_uri);
  1101. // // return fromPath + nowPath
  1102. // return new_uri
  1103. // }
  1104. // catch (e) {
  1105. // console.log('urljoin发生错误:'+e.message);
  1106. // if(nowPath.startsWith('http')){
  1107. // return nowPath
  1108. // }if(nowPath.startsWith('/')){
  1109. // return getHome(fromPath)+nowPath
  1110. // }
  1111. // return fromPath+nowPath
  1112. // }
  1113. }
  1114. var urljoin2 = urljoin;
  1115. // 内置 pdfh,pdfa,pd
  1116. const defaultParser = {
  1117. pdfh: pdfh,
  1118. pdfa: pdfa,
  1119. pd: pd,
  1120. };
  1121. /**
  1122. * pdfh原版优化,能取style属性里的图片链接
  1123. * @param html 源码
  1124. * @param parse 解析表达式
  1125. * @returns {string|*}
  1126. */
  1127. function pdfh2(html, parse) {
  1128. let html2 = html;
  1129. try {
  1130. if (typeof (html) !== 'string') {
  1131. html2 = html.rr(html.ele).toString();
  1132. }
  1133. } catch (e) {
  1134. print('html对象转文本发生了错误:' + e.message);
  1135. }
  1136. let result = defaultParser.pdfh(html2, parse);
  1137. let option = parse.includes('&&') ? parse.split('&&').slice(-1)[0] : parse.split(' ').slice(-1)[0];
  1138. if (/style/.test(option.toLowerCase()) && /url\(/.test(result)) {
  1139. try {
  1140. result = result.match(/url\((.*?)\)/)[1];
  1141. // 2023/07/28新增 style取内部链接自动去除首尾单双引号
  1142. result = result.replace(/^['|"](.*)['|"]$/, "$1");
  1143. } catch (e) {
  1144. }
  1145. }
  1146. return result
  1147. }
  1148. /**
  1149. * pdfa原版优化,可以转换jq的html对象
  1150. * @param html
  1151. * @param parse
  1152. * @returns {*}
  1153. */
  1154. function pdfa2(html, parse) {
  1155. let html2 = html;
  1156. try {
  1157. if (typeof (html) !== 'string') {
  1158. html2 = html.rr(html.ele).toString();
  1159. }
  1160. } catch (e) {
  1161. print('html对象转文本发生了错误:' + e.message);
  1162. }
  1163. return defaultParser.pdfa(html2, parse);
  1164. }
  1165. /**
  1166. * pd原版方法重写-增加自动urljoin
  1167. * @param html
  1168. * @param parse
  1169. * @param uri
  1170. * @returns {*}
  1171. */
  1172. function pd2(html, parse, uri) {
  1173. let ret = pdfh2(html, parse);
  1174. if (typeof (uri) === 'undefined' || !uri) {
  1175. uri = '';
  1176. }
  1177. if (DOM_CHECK_ATTR.test(parse) && !SPECIAL_URL.test(ret)) {
  1178. if (/http/.test(ret)) {
  1179. ret = ret.slice(ret.indexOf('http'));
  1180. } else {
  1181. ret = urljoin(MY_URL, ret)
  1182. }
  1183. }
  1184. // MY_URL = getItem('MY_URL',MY_URL);
  1185. // console.log(`规则${RKEY}打印MY_URL:${MY_URL},uri:${uri}`);
  1186. return ret
  1187. }
  1188. const parseTags = {
  1189. jsp: {
  1190. pdfh: pdfh2,
  1191. pdfa: pdfa2,
  1192. pd: pd2,
  1193. },
  1194. json: {
  1195. pdfh(html, parse) {
  1196. if (!parse || !parse.trim()) {
  1197. return '';
  1198. }
  1199. if (typeof (html) === 'string') {
  1200. // print('jsonpath:pdfh字符串转dict');
  1201. html = JSON.parse(html);
  1202. }
  1203. parse = parse.trim();
  1204. if (!parse.startsWith('$.')) {
  1205. parse = '$.' + parse;
  1206. }
  1207. parse = parse.split('||');
  1208. for (let ps of parse) {
  1209. let ret = cheerio.jp(ps, html);
  1210. if (Array.isArray(ret)) {
  1211. ret = ret[0] || '';
  1212. } else {
  1213. ret = ret || ''
  1214. }
  1215. if (ret && typeof (ret) !== 'string') {
  1216. ret = ret.toString();
  1217. }
  1218. if (ret) {
  1219. return ret
  1220. }
  1221. }
  1222. return '';
  1223. },
  1224. pdfa(html, parse) {
  1225. if (!parse || !parse.trim()) {
  1226. return '';
  1227. }
  1228. if (typeof (html) === 'string') {
  1229. // print('jsonpath:pdfa字符串转dict');
  1230. html = JSON.parse(html);
  1231. }
  1232. parse = parse.trim()
  1233. if (!parse.startsWith('$.')) {
  1234. parse = '$.' + parse;
  1235. }
  1236. let ret = cheerio.jp(parse, html);
  1237. if (Array.isArray(ret) && Array.isArray(ret[0]) && ret.length === 1) {
  1238. return ret[0] || []
  1239. }
  1240. return ret || []
  1241. },
  1242. pd(html, parse) {
  1243. let ret = parseTags.json.pdfh(html, parse);
  1244. if (ret) {
  1245. return urljoin(MY_URL, ret);
  1246. }
  1247. return ret
  1248. },
  1249. },
  1250. jq: {
  1251. pdfh(html, parse) {
  1252. if (!html || !parse || !parse.trim()) {
  1253. return ''
  1254. }
  1255. parse = parse.trim();
  1256. let result = defaultParser.pdfh(html, parse);
  1257. // print(`pdfh解析${parse}=>${result}`);
  1258. return result;
  1259. },
  1260. pdfa(html, parse) {
  1261. if (!html || !parse || !parse.trim()) {
  1262. return [];
  1263. }
  1264. parse = parse.trim();
  1265. let result = defaultParser.pdfa(html, parse);
  1266. // print(result);
  1267. print(`pdfa解析${parse}=>${result.length}`);
  1268. return result;
  1269. },
  1270. pd(html, parse, base_url) {
  1271. if (!html || !parse || !parse.trim()) {
  1272. return ''
  1273. }
  1274. parse = parse.trim();
  1275. base_url = base_url || MY_URL;
  1276. return defaultParser.pd(html, parse, base_url);
  1277. },
  1278. },
  1279. getParse(p0) {//非js开头的情况自动获取解析标签
  1280. if (p0.startsWith('jsp:')) {
  1281. return this.jsp
  1282. } else if (p0.startsWith('json:')) {
  1283. return this.json
  1284. } else if (p0.startsWith('jq:')) {
  1285. return this.jq
  1286. } else {
  1287. return this.jq
  1288. }
  1289. }
  1290. };
  1291. const stringify = JSON.stringify;
  1292. const jsp = parseTags.jsp;
  1293. const jq = parseTags.jq;
  1294. /*** 后台需要实现的java方法并注入到js中 ***/
  1295. /**
  1296. * 读取本地文件->应用程序目录
  1297. * @param filePath
  1298. * @returns {string}
  1299. */
  1300. function readFile(filePath) {
  1301. filePath = filePath || './uri.min.js';
  1302. var fd = os.open(filePath);
  1303. var buffer = new ArrayBuffer(1024);
  1304. var len = os.read(fd, buffer, 0, 1024);
  1305. console.log(len);
  1306. let text = String.fromCharCode.apply(null, new Uint8Array(buffer));
  1307. console.log(text);
  1308. return text
  1309. }
  1310. /**
  1311. * 处理返回的json数据
  1312. * @param html
  1313. * @returns {*}
  1314. */
  1315. function dealJson(html) {
  1316. try {
  1317. // html = html.match(/[\w|\W|\s|\S]*?(\{[\w|\W|\s|\S]*\})/).group[1];
  1318. html = html.trim();
  1319. if (!((html.startsWith('{') && html.endsWith('}')) || (html.startsWith('[') && html.endsWith(']')))) {
  1320. html = '{' + html.match(/.*?\{(.*)\}/m)[1] + '}';
  1321. }
  1322. } catch (e) {
  1323. }
  1324. try {
  1325. html = JSON.parse(html);
  1326. } catch (e) {
  1327. }
  1328. // console.log(typeof(html));
  1329. return html;
  1330. }
  1331. /**
  1332. * 验证码识别逻辑,需要java实现(js没有bytes类型,无法调用后端的传递图片二进制获取验证码文本的接口)
  1333. * @type {{api: string, classification: (function(*=): string)}}
  1334. */
  1335. var OcrApi = {
  1336. api: OCR_API,
  1337. classification: function (img) { // img是byte类型,这里不方便搞啊
  1338. let code = '';
  1339. try {
  1340. // let html = request(this.api,{data:{img:img},headers:{'User-Agent':PC_UA},'method':'POST'},true);
  1341. // html = JSON.parse(html);
  1342. // code = html.url||'';
  1343. log('通过drpy_ocr验证码接口过验证...');
  1344. let html = '';
  1345. if (this.api.endsWith('drpy/text')) {
  1346. html = request(this.api, {data: {img: img}, headers: {'User-Agent': PC_UA}, 'method': 'POST'}, true);
  1347. } else {
  1348. html = post(this.api, {body: img});
  1349. }
  1350. code = html || '';
  1351. } catch (e) {
  1352. log(`OCR识别验证码发生错误:${e.message}`)
  1353. }
  1354. return code
  1355. }
  1356. };
  1357. /**
  1358. * 验证码识别,暂未实现
  1359. * @param url 验证码图片链接
  1360. * @returns {string} 验证成功后的cookie
  1361. */
  1362. function verifyCode(url) {
  1363. let cnt = 0;
  1364. let host = getHome(url);
  1365. let cookie = '';
  1366. while (cnt < OCR_RETRY) {
  1367. try {
  1368. // let obj = {headers:headers,timeout:timeout};
  1369. let yzm_url = `${host}/index.php/verify/index.html`;
  1370. console.log(`验证码链接:${yzm_url}`);
  1371. let hhtml = request(yzm_url, {withHeaders: true, toBase64: true}, true);
  1372. let json = JSON.parse(hhtml);
  1373. if (!cookie) {
  1374. // print(json);
  1375. let setCk = Object.keys(json).find(it => it.toLowerCase() === 'set-cookie');
  1376. // cookie = json['set-cookie']?json['set-cookie'].split(';')[0]:'';
  1377. cookie = setCk ? json[setCk].split(';')[0] : '';
  1378. }
  1379. // console.log(hhtml);
  1380. console.log('cookie:' + cookie);
  1381. let img = json.body;
  1382. // console.log(img);
  1383. let code = OcrApi.classification(img);
  1384. console.log(`第${cnt + 1}次验证码识别结果:${code}`);
  1385. let submit_url = `${host}/index.php/ajax/verify_check?type=search&verify=${code}`;
  1386. console.log(submit_url);
  1387. let html = request(submit_url, {headers: {Cookie: cookie}, 'method': 'POST'});
  1388. // console.log(html);
  1389. html = JSON.parse(html);
  1390. if (html.msg === 'ok') {
  1391. console.log(`第${cnt + 1}次验证码提交成功`);
  1392. return cookie // 需要返回cookie
  1393. } else if (html.msg !== 'ok' && cnt + 1 >= OCR_RETRY) {
  1394. cookie = ''; // 需要清空返回cookie
  1395. }
  1396. } catch (e) {
  1397. console.log(`第${cnt + 1}次验证码提交失败:${e.message}`);
  1398. if (cnt + 1 >= OCR_RETRY) {
  1399. cookie = '';
  1400. }
  1401. }
  1402. cnt += 1
  1403. }
  1404. return cookie
  1405. }
  1406. /**
  1407. * 存在数据库配置表里, key字段对应值value,没有就新增,有就更新,调用此方法会清除key对应的内存缓存
  1408. * @param k 键
  1409. * @param v 值
  1410. */
  1411. function setItem(k, v) {
  1412. local.set(RKEY, k, v);
  1413. console.log(`规则${RKEY}设置${k} => ${v}`)
  1414. }
  1415. /**
  1416. * 获取数据库配置表对应的key字段的value,没有这个key就返回value默认传参.需要有缓存,第一次获取后会存在内存里
  1417. * @param k 键
  1418. * @param v 值
  1419. * @returns {*}
  1420. */
  1421. function getItem(k, v) {
  1422. return local.get(RKEY, k) || v;
  1423. }
  1424. /**
  1425. * 删除数据库key对应的一条数据,并清除此key对应的内存缓存
  1426. * @param k
  1427. */
  1428. function clearItem(k) {
  1429. local.delete(RKEY, k);
  1430. }
  1431. /*** js自封装的方法 ***/
  1432. /**
  1433. * 获取链接的host(带http协议的完整链接)
  1434. * @param url 任意一个正常完整的Url,自动提取根
  1435. * @returns {string}
  1436. */
  1437. function getHome(url) {
  1438. if (!url) {
  1439. return ''
  1440. }
  1441. let tmp = url.split('//');
  1442. url = tmp[0] + '//' + tmp[1].split('/')[0];
  1443. try {
  1444. url = decodeURIComponent(url);
  1445. } catch (e) {
  1446. }
  1447. return url
  1448. }
  1449. /**
  1450. * get参数编译链接,类似python params字典自动拼接
  1451. * @param url 访问链接
  1452. * @param obj 参数字典
  1453. * @returns {*}
  1454. */
  1455. function buildUrl(url, obj) {
  1456. obj = obj || {};
  1457. if (url.indexOf('?') < 0) {
  1458. url += '?'
  1459. }
  1460. let param_list = [];
  1461. let keys = Object.keys(obj);
  1462. keys.forEach(it => {
  1463. param_list.push(it + '=' + obj[it])
  1464. });
  1465. let prs = param_list.join('&');
  1466. if (keys.length > 0 && !url.endsWith('?')) {
  1467. url += '&'
  1468. }
  1469. url += prs;
  1470. return url
  1471. }
  1472. /**
  1473. * 远程依赖执行函数
  1474. * @param url 远程js地址
  1475. */
  1476. function $require(url) {
  1477. eval(request(url));
  1478. }
  1479. /**
  1480. * 将obj所有key变小写
  1481. * @param obj
  1482. */
  1483. function keysToLowerCase(obj) {
  1484. return Object.keys(obj).reduce((result, key) => {
  1485. const newKey = key.toLowerCase();
  1486. result[newKey] = obj[key]; // 如果值也是对象,可以递归调用本函数
  1487. return result;
  1488. }, {});
  1489. }
  1490. /**
  1491. * 海阔网页请求函数完整封装
  1492. * @param url 请求链接
  1493. * @param obj 请求对象 {headers:{},method:'',timeout:5000,body:'',withHeaders:false}
  1494. * @param ocr_flag 标识此flag是用于请求ocr识别的,自动过滤content-type指定编码
  1495. * @returns {string|string|DocumentFragment|*}
  1496. */
  1497. function request(url, obj, ocr_flag) {
  1498. ocr_flag = ocr_flag || false;
  1499. if (typeof (obj) === 'undefined' || !obj || obj === {}) {
  1500. if (!fetch_params || !fetch_params.headers) {
  1501. let headers = {
  1502. 'User-Agent': MOBILE_UA,
  1503. };
  1504. if (rule.headers) {
  1505. Object.assign(headers, rule.headers);
  1506. }
  1507. if (!fetch_params) {
  1508. fetch_params = {};
  1509. }
  1510. fetch_params.headers = headers;
  1511. }
  1512. if (!fetch_params.headers.Referer) {
  1513. fetch_params.headers.Referer = getHome(url)
  1514. }
  1515. obj = fetch_params;
  1516. } else {
  1517. let headers = obj.headers || {};
  1518. let keys = Object.keys(headers).map(it => it.toLowerCase());
  1519. if (!keys.includes('user-agent')) {
  1520. headers['User-Agent'] = MOBILE_UA;
  1521. // fetch_params 里存在ua则优先,否则才默认手机UA
  1522. if (typeof (fetch_params) === 'object' && fetch_params && fetch_params.headers) {
  1523. let fetch_headers = keysToLowerCase(fetch_params.headers);
  1524. if (fetch_headers['user-agent']) {
  1525. headers['User-Agent'] = fetch_headers['user-agent'];
  1526. }
  1527. }
  1528. }
  1529. if (!keys.includes('referer')) {
  1530. headers['Referer'] = getHome(url);
  1531. }
  1532. obj.headers = headers;
  1533. }
  1534. if (rule.encoding && rule.encoding !== 'utf-8' && !ocr_flag) {
  1535. if (!obj.headers.hasOwnProperty('Content-Type') && !obj.headers.hasOwnProperty('content-type')) { // 手动指定了就不管
  1536. obj.headers["Content-Type"] = 'text/html; charset=' + rule.encoding;
  1537. }
  1538. }
  1539. if (typeof (obj.body) != 'undefined' && obj.body && typeof (obj.body) === 'string') {
  1540. // let data = {};
  1541. // obj.body.split('&').forEach(it=>{
  1542. // data[it.split('=')[0]] = it.split('=')[1]
  1543. // });
  1544. // obj.data = data;
  1545. // delete obj.body
  1546. // 传body加 "Content-Type":"application/x-www-form-urlencoded;" 即可post form
  1547. if (!obj.headers.hasOwnProperty('Content-Type') && !obj.headers.hasOwnProperty('content-type')) { // 手动指定了就不管
  1548. obj.headers["Content-Type"] = 'application/x-www-form-urlencoded; charset=' + rule.encoding;
  1549. }
  1550. } else if (typeof (obj.body) != 'undefined' && obj.body && typeof (obj.body) === 'object') {
  1551. obj.data = obj.body;
  1552. delete obj.body
  1553. }
  1554. if (!url) {
  1555. return obj.withHeaders ? '{}' : ''
  1556. }
  1557. if (obj.toBase64) { // 返回base64,用于请求图片
  1558. obj.buffer = 2;
  1559. delete obj.toBase64
  1560. }
  1561. if (obj.redirect === false) {
  1562. obj.redirect = 0;
  1563. }
  1564. console.log(JSON.stringify(obj.headers));
  1565. // console.log('request:'+url+' obj:'+JSON.stringify(obj));
  1566. console.log('request:' + url + `|method:${obj.method || 'GET'}|body:${obj.body || ''}`);
  1567. let res = req(url, obj);
  1568. let html = res.content || '';
  1569. // console.log(html);
  1570. if (obj.withHeaders) {
  1571. let htmlWithHeaders = res.headers;
  1572. htmlWithHeaders.body = html;
  1573. return JSON.stringify(htmlWithHeaders);
  1574. } else {
  1575. return html
  1576. }
  1577. }
  1578. /**
  1579. * 快捷post请求
  1580. * @param url 地址
  1581. * @param obj 对象
  1582. * @returns {string|DocumentFragment|*}
  1583. */
  1584. function post(url, obj) {
  1585. obj = obj || {};
  1586. obj.method = 'POST';
  1587. return request(url, obj);
  1588. }
  1589. /**
  1590. * 快捷获取特殊地址cookie|一般用作搜索过验证
  1591. * 用法 let {cookie,html} = reqCookie(url);
  1592. * @param url 能返回cookie的地址
  1593. * @param obj 常规请求参数
  1594. * @param all_cookie 返回全部cookie.默认false只返回第一个,一般是PhpSessionId
  1595. * @returns {{cookie: string, html: (*|string|DocumentFragment)}}
  1596. */
  1597. function reqCookie(url, obj, all_cookie) {
  1598. obj = obj || {};
  1599. obj.withHeaders = true;
  1600. all_cookie = all_cookie || false;
  1601. let html = request(url, obj);
  1602. let json = JSON.parse(html);
  1603. let setCk = Object.keys(json).find(it => it.toLowerCase() === 'set-cookie');
  1604. let cookie = setCk ? json[setCk] : '';
  1605. if (Array.isArray(cookie)) {
  1606. cookie = cookie.join(';')
  1607. }
  1608. if (!all_cookie) {
  1609. cookie = cookie.split(';')[0];
  1610. }
  1611. html = json.body;
  1612. return {
  1613. cookie,
  1614. html
  1615. }
  1616. }
  1617. fetch = request;
  1618. print = function (data) {
  1619. data = data || '';
  1620. if (typeof (data) == 'object' && Object.keys(data).length > 0) {
  1621. try {
  1622. data = JSON.stringify(data);
  1623. console.log(data);
  1624. } catch (e) {
  1625. // console.log('print:'+e.message);
  1626. console.log(typeof (data) + ':' + data.length);
  1627. return
  1628. }
  1629. } else if (typeof (data) == 'object' && Object.keys(data).length < 1) {
  1630. console.log('null object');
  1631. } else {
  1632. console.log(data);
  1633. }
  1634. }
  1635. log = print;
  1636. /**
  1637. * 检查宝塔验证并自动跳过获取正确源码
  1638. * @param html 之前获取的html
  1639. * @param url 之前的来源url
  1640. * @param obj 来源obj
  1641. * @returns {string|DocumentFragment|*}
  1642. */
  1643. function checkHtml(html, url, obj) {
  1644. if (/\?btwaf=/.test(html)) {
  1645. let btwaf = html.match(/btwaf(.*?)"/)[1];
  1646. url = url.split('#')[0] + '?btwaf' + btwaf;
  1647. print('宝塔验证访问链接:' + url);
  1648. html = request(url, obj);
  1649. }
  1650. return html
  1651. }
  1652. /**
  1653. * 带一次宝塔验证的源码获取
  1654. * @param url 请求链接
  1655. * @param obj 请求参数
  1656. * @returns {string|DocumentFragment}
  1657. */
  1658. function getCode(url, obj) {
  1659. let html = request(url, obj);
  1660. html = checkHtml(html, url, obj);
  1661. return html
  1662. }
  1663. /**
  1664. * 源rule专用的请求方法,自动注入cookie
  1665. * @param url 请求链接
  1666. * @returns {string|DocumentFragment}
  1667. */
  1668. function getHtml(url) {
  1669. let obj = {};
  1670. if (rule.headers) {
  1671. obj.headers = rule.headers;
  1672. }
  1673. let cookie = getItem(RULE_CK, '');
  1674. if (cookie) {
  1675. // log('有cookie:'+cookie);
  1676. if (obj.headers && !Object.keys(obj.headers).map(it => it.toLowerCase()).includes('cookie')) {
  1677. log('历史无cookie,新增过验证后的cookie');
  1678. obj.headers['Cookie'] = cookie;
  1679. } else if (obj.headers && obj.headers.cookie && obj.headers.cookie !== cookie) {
  1680. obj.headers['Cookie'] = cookie;
  1681. log('历史有小写过期的cookie,更新过验证后的cookie');
  1682. } else if (obj.headers && obj.headers.Cookie && obj.headers.Cookie !== cookie) {
  1683. obj.headers['Cookie'] = cookie;
  1684. log('历史有大写过期的cookie,更新过验证后的cookie');
  1685. } else if (!obj.headers) {
  1686. obj.headers = {Cookie: cookie};
  1687. log('历史无headers,更新过验证后的含cookie的headers');
  1688. }
  1689. }
  1690. let html = getCode(url, obj);
  1691. return html
  1692. }
  1693. /**
  1694. * 首页分类解析,筛选暂未实现
  1695. * @param homeObj 首页传参对象
  1696. * @returns {string}
  1697. */
  1698. function homeParse(homeObj) {
  1699. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1700. let classes = [];
  1701. if (homeObj.class_name && homeObj.class_url) {
  1702. let names = homeObj.class_name.split('&');
  1703. let urls = homeObj.class_url.split('&');
  1704. let cnt = Math.min(names.length, urls.length);
  1705. for (let i = 0; i < cnt; i++) {
  1706. classes.push({
  1707. 'type_id': urls[i],
  1708. 'type_name': names[i]
  1709. });
  1710. }
  1711. }
  1712. if (homeObj.class_parse) {
  1713. if (homeObj.class_parse.startsWith('js:')) {
  1714. var input = homeObj.MY_URL;
  1715. try {
  1716. eval(homeObj.class_parse.replace('js:', ''));
  1717. if (Array.isArray(input)) {
  1718. classes = input;
  1719. }
  1720. } catch (e) {
  1721. log('通过js动态获取分类发生了错误:' + e.message);
  1722. }
  1723. } else {
  1724. let p = homeObj.class_parse.split(';');
  1725. let p0 = p[0];
  1726. let _ps = parseTags.getParse(p0);
  1727. let is_json = p0.startsWith('json:');
  1728. _pdfa = _ps.pdfa;
  1729. _pdfh = _ps.pdfh;
  1730. _pd = _ps.pd;
  1731. MY_URL = rule.url;
  1732. if (is_json) {
  1733. try {
  1734. let cms_cate_url = homeObj.MY_URL.replace('ac=detail', 'ac=list');
  1735. let html = getHtml(cms_cate_url);
  1736. if (html) {
  1737. if (cms_cate_url === homeObj.MY_URL) {
  1738. homeHtmlCache = html;
  1739. }
  1740. let list = _pdfa(html, p0.replace('json:', ''));
  1741. if (list && list.length > 0) {
  1742. classes = list;
  1743. }
  1744. }
  1745. } catch (e) {
  1746. console.log(e.message);
  1747. }
  1748. } else if (p.length >= 3 && !is_json) { // 可以不写正则
  1749. try {
  1750. let html = getHtml(homeObj.MY_URL);
  1751. if (html) {
  1752. homeHtmlCache = html;
  1753. let list = _pdfa(html, p0);
  1754. if (list && list.length > 0) {
  1755. list.forEach((it, idex) => {
  1756. try {
  1757. let name = _pdfh(it, p[1]);
  1758. if (homeObj.cate_exclude && (new RegExp(homeObj.cate_exclude).test(name))) {
  1759. return;
  1760. }
  1761. // let url = pdfh(it, p[2]);
  1762. let url = _pd(it, p[2]);
  1763. if (p.length > 3 && p[3]) {
  1764. let exp = new RegExp(p[3]);
  1765. url = url.match(exp)[1];
  1766. }
  1767. classes.push({
  1768. 'type_id': url.trim(),
  1769. 'type_name': name.trim()
  1770. });
  1771. } catch (e) {
  1772. console.log(`分类列表定位第${idex}个元素正常报错:${e.message}`);
  1773. }
  1774. });
  1775. }
  1776. }
  1777. } catch (e) {
  1778. console.log(e.message);
  1779. }
  1780. }
  1781. }
  1782. }
  1783. // 排除分类
  1784. classes = classes.filter(it => !homeObj.cate_exclude || !(new RegExp(homeObj.cate_exclude).test(it.type_name)));
  1785. let resp = {
  1786. 'class': classes
  1787. };
  1788. if (homeObj.filter) {
  1789. resp.filters = homeObj.filter;
  1790. }
  1791. console.log(JSON.stringify(resp));
  1792. return JSON.stringify(resp);
  1793. }
  1794. /**
  1795. * 推荐和搜索单字段继承一级
  1796. * @param p 推荐或搜索的解析分割;列表
  1797. * @param pn 自身列表序号
  1798. * @param pp 一级解析分割;列表
  1799. * @param ppn 继承一级序号
  1800. * @returns {*}
  1801. */
  1802. function getPP(p, pn, pp, ppn) {
  1803. try {
  1804. let ps = p[pn] === '*' && pp.length > ppn ? pp[ppn] : p[pn]
  1805. return ps
  1806. } catch (e) {
  1807. return ''
  1808. }
  1809. }
  1810. /**
  1811. * 首页推荐列表解析
  1812. * @param homeVodObj
  1813. * @returns {string}
  1814. */
  1815. function homeVodParse(homeVodObj) {
  1816. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  1817. let d = [];
  1818. MY_URL = homeVodObj.homeUrl;
  1819. // setItem('MY_URL',MY_URL);
  1820. console.log(MY_URL);
  1821. let t1 = (new Date()).getTime();
  1822. let p = homeVodObj.推荐;
  1823. print('p:' + p);
  1824. if (p === '*' && rule.一级) {
  1825. p = rule.一级;
  1826. homeVodObj.double = false;
  1827. }
  1828. if (!p || typeof (p) !== 'string') {
  1829. return '{}'
  1830. }
  1831. p = p.trim();
  1832. let pp = rule.一级 ? rule.一级.split(';') : [];
  1833. if (p.startsWith('js:')) {
  1834. const TYPE = 'home';
  1835. var input = MY_URL;
  1836. HOST = rule.host;
  1837. eval(p.replace('js:', ''));
  1838. d = VODS;
  1839. } else {
  1840. p = p.split(';');
  1841. if (!homeVodObj.double && p.length < 5) {
  1842. return '{}'
  1843. } else if (homeVodObj.double && p.length < 6) {
  1844. return '{}'
  1845. }
  1846. let p0 = getPP(p, 0, pp, 0)
  1847. let _ps = parseTags.getParse(p0);
  1848. _pdfa = _ps.pdfa;
  1849. _pdfh = _ps.pdfh;
  1850. _pd = _ps.pd;
  1851. let is_json = p0.startsWith('json:');
  1852. p0 = p0.replace(/^(jsp:|json:|jq:)/, '');
  1853. // print(p[0]);
  1854. let html = homeHtmlCache || getHtml(MY_URL);
  1855. homeHtmlCache = undefined;
  1856. if (is_json) {
  1857. // print('是json,开始处理');
  1858. html = dealJson(html);
  1859. }
  1860. try {
  1861. console.log('double:' + homeVodObj.double);
  1862. if (homeVodObj.double) {
  1863. let items = _pdfa(html, p0);
  1864. // console.log(items.length);
  1865. let p1 = getPP(p, 1, pp, 0);
  1866. let p2 = getPP(p, 2, pp, 1);
  1867. let p3 = getPP(p, 3, pp, 2);
  1868. let p4 = getPP(p, 4, pp, 3);
  1869. let p5 = getPP(p, 5, pp, 4);
  1870. let p6 = getPP(p, 6, pp, 5);
  1871. for (let item of items) {
  1872. // console.log(p[1]);
  1873. let items2 = _pdfa(item, p1);
  1874. // console.log(items2.length);
  1875. for (let item2 of items2) {
  1876. try {
  1877. let title = _pdfh(item2, p2);
  1878. let img = '';
  1879. try {
  1880. img = _pd(item2, p3);
  1881. } catch (e) {
  1882. }
  1883. let desc = '';
  1884. try {
  1885. desc = _pdfh(item2, p4);
  1886. } catch (e) {
  1887. }
  1888. let links = [];
  1889. for (let _p5 of p5.split('+')) {
  1890. let link = !homeVodObj.detailUrl ? _pd(item2, _p5, MY_URL) : _pdfh(item2, _p5);
  1891. links.push(link);
  1892. }
  1893. let content;
  1894. if (p.length > 6 && p[6]) {
  1895. content = _pdfh(item2, p6);
  1896. } else {
  1897. content = '';
  1898. }
  1899. let vid = links.join('$');
  1900. if (rule.二级 === '*') {
  1901. vid = vid + '@@' + title + '@@' + img;
  1902. }
  1903. let vod = {
  1904. vod_name: title,
  1905. vod_pic: img,
  1906. vod_remarks: desc,
  1907. vod_content: content,
  1908. vod_id: vid
  1909. };
  1910. // print(vod);
  1911. d.push(vod);
  1912. } catch (e) {
  1913. console.log('首页列表双层定位处理发生错误:' + e.message);
  1914. }
  1915. }
  1916. }
  1917. } else {
  1918. let items = _pdfa(html, p0);
  1919. let p1 = getPP(p, 1, pp, 1);
  1920. let p2 = getPP(p, 2, pp, 2);
  1921. let p3 = getPP(p, 3, pp, 3);
  1922. let p4 = getPP(p, 4, pp, 4);
  1923. let p5 = getPP(p, 5, pp, 5);
  1924. for (let item of items) {
  1925. try {
  1926. let title = _pdfh(item, p1);
  1927. let img = '';
  1928. try {
  1929. img = _pd(item, p2, MY_URL);
  1930. } catch (e) {
  1931. }
  1932. let desc = '';
  1933. try {
  1934. desc = _pdfh(item, p3);
  1935. } catch (e) {
  1936. }
  1937. let links = [];
  1938. for (let _p5 of p4.split('+')) {
  1939. let link = !homeVodObj.detailUrl ? _pd(item, _p5, MY_URL) : _pdfh(item, _p5);
  1940. links.push(link);
  1941. }
  1942. let content;
  1943. if (p.length > 5 && p[5]) {
  1944. content = _pdfh(item, p5);
  1945. } else {
  1946. content = ''
  1947. }
  1948. let vid = links.join('$');
  1949. if (rule.二级 === '*') {
  1950. vid = vid + '@@' + title + '@@' + img;
  1951. }
  1952. let vod = {
  1953. vod_name: title,
  1954. vod_pic: img,
  1955. vod_remarks: desc,
  1956. vod_content: content,
  1957. vod_id: vid
  1958. };
  1959. d.push(vod);
  1960. } catch (e) {
  1961. console.log('首页列表单层定位处理发生错误:' + e.message);
  1962. }
  1963. }
  1964. }
  1965. } catch (e) {
  1966. }
  1967. }
  1968. let t2 = (new Date()).getTime();
  1969. console.log('加载首页推荐耗时:' + (t2 - t1) + '毫秒');
  1970. // console.log(JSON.stringify(d));
  1971. if (rule.图片替换) {
  1972. if (rule.图片替换.startsWith('js:')) {
  1973. d.forEach(it => {
  1974. try {
  1975. var input = it.vod_pic;
  1976. eval(rule.图片替换.trim().replace('js:', ''));
  1977. it.vod_pic = input;
  1978. } catch (e) {
  1979. log(`图片:${it.vod_pic}替换错误:${e.message}`);
  1980. }
  1981. });
  1982. } else if (rule.图片替换.includes('=>')) {
  1983. let replace_from = rule.图片替换.split('=>')[0];
  1984. let replace_to = rule.图片替换.split('=>')[1];
  1985. d.forEach(it => {
  1986. if (it.vod_pic && it.vod_pic.startsWith('http')) {
  1987. it.vod_pic = it.vod_pic.replace(replace_from, replace_to);
  1988. }
  1989. });
  1990. }
  1991. }
  1992. if (rule.图片来源) {
  1993. d.forEach(it => {
  1994. if (it.vod_pic && it.vod_pic.startsWith('http')) {
  1995. it.vod_pic = it.vod_pic + rule.图片来源;
  1996. }
  1997. });
  1998. }
  1999. if (d.length > 0) {
  2000. print(d.slice(0, 2));
  2001. }
  2002. return JSON.stringify({
  2003. list: d
  2004. })
  2005. }
  2006. /**
  2007. * 一级分类页数据解析
  2008. * @param cateObj
  2009. * @returns {string}
  2010. */
  2011. function categoryParse(cateObj) {
  2012. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  2013. let p = cateObj.一级;
  2014. if (!p || typeof (p) !== 'string') {
  2015. return '{}'
  2016. }
  2017. let d = [];
  2018. // let url = cateObj.url.replaceAll('fyclass', cateObj.tid).replaceAll('fypage', cateObj.pg);
  2019. let url = cateObj.url.replaceAll('fyclass', cateObj.tid);
  2020. if (cateObj.pg === 1 && url.includes('[') && url.includes(']')) {
  2021. url = url.split('[')[1].split(']')[0];
  2022. } else if (cateObj.pg > 1 && url.includes('[') && url.includes(']')) {
  2023. url = url.split('[')[0];
  2024. }
  2025. if (rule.filter_url) {
  2026. if (!/fyfilter/.test(url)) {
  2027. if (!url.endsWith('&') && !rule.filter_url.startsWith('&')) {
  2028. url += '&'
  2029. }
  2030. url += rule.filter_url;
  2031. } else {
  2032. url = url.replace('fyfilter', rule.filter_url);
  2033. }
  2034. // filter_url支持fyclass
  2035. url = url.replaceAll('fyclass', cateObj.tid);
  2036. // console.log('filter:'+cateObj.filter);
  2037. let fl = cateObj.filter ? cateObj.extend : {};
  2038. // 自动合并 不同分类对应的默认筛选
  2039. if (rule.filter_def && typeof (rule.filter_def) === 'object') {
  2040. try {
  2041. if (Object.keys(rule.filter_def).length > 0 && rule.filter_def.hasOwnProperty(cateObj.tid)) {
  2042. let self_fl_def = rule.filter_def[cateObj.tid];
  2043. if (self_fl_def && typeof (self_fl_def) === 'object') {
  2044. // 引用传递转值传递,避免污染self变量
  2045. let fl_def = JSON.parse(JSON.stringify(self_fl_def));
  2046. fl = Object.assign(fl_def, fl);
  2047. }
  2048. }
  2049. } catch (e) {
  2050. print('合并不同分类对应的默认筛选出错:' + e.message);
  2051. }
  2052. }
  2053. let new_url;
  2054. new_url = cheerio.jinja2(url, {fl: fl});
  2055. // console.log('jinjia2执行后的new_url类型为:'+typeof(new_url));
  2056. url = new_url;
  2057. }
  2058. if (/fypage/.test(url)) {
  2059. if (url.includes('(') && url.includes(')')) {
  2060. let url_rep = url.match(/.*?\((.*)\)/)[1];
  2061. // console.log(url_rep);
  2062. let cnt_page = url_rep.replaceAll('fypage', cateObj.pg);
  2063. // console.log(cnt_page);
  2064. let cnt_pg = eval(cnt_page);
  2065. // console.log(cnt_pg);
  2066. url = url.replaceAll(url_rep, cnt_pg).replaceAll('(', '').replaceAll(')', '');
  2067. } else {
  2068. url = url.replaceAll('fypage', cateObj.pg);
  2069. }
  2070. }
  2071. MY_URL = url;
  2072. // setItem('MY_URL',MY_URL);
  2073. console.log(MY_URL);
  2074. p = p.trim();
  2075. const MY_CATE = cateObj.tid;
  2076. if (p.startsWith('js:')) {
  2077. var MY_FL = cateObj.extend;
  2078. const TYPE = 'cate';
  2079. var input = MY_URL;
  2080. const MY_PAGE = cateObj.pg;
  2081. var desc = '';
  2082. eval(p.trim().replace('js:', ''));
  2083. d = VODS;
  2084. } else {
  2085. p = p.split(';');
  2086. if (p.length < 5) {
  2087. return '{}'
  2088. }
  2089. let _ps = parseTags.getParse(p[0]);
  2090. _pdfa = _ps.pdfa;
  2091. _pdfh = _ps.pdfh;
  2092. _pd = _ps.pd;
  2093. let is_json = p[0].startsWith('json:');
  2094. p[0] = p[0].replace(/^(jsp:|json:|jq:)/, '');
  2095. try {
  2096. let html = getHtml(MY_URL);
  2097. if (html) {
  2098. if (is_json) {
  2099. html = dealJson(html);
  2100. }
  2101. let list = _pdfa(html, p[0]);
  2102. list.forEach(it => {
  2103. let links = p[4].split('+').map(p4 => {
  2104. return !rule.detailUrl ? _pd(it, p4, MY_URL) : _pdfh(it, p4);
  2105. });
  2106. let link = links.join('$');
  2107. let vod_id = rule.detailUrl ? MY_CATE + '$' + link : link;
  2108. let vod_name = _pdfh(it, p[1]).replace(/\n|\t/g, '').trim();
  2109. let vod_pic = _pd(it, p[2], MY_URL);
  2110. if (rule.二级 === '*') {
  2111. vod_id = vod_id + '@@' + vod_name + '@@' + vod_pic;
  2112. }
  2113. d.push({
  2114. 'vod_id': vod_id,
  2115. 'vod_name': vod_name,
  2116. 'vod_pic': vod_pic,
  2117. 'vod_remarks': _pdfh(it, p[3]).replace(/\n|\t/g, '').trim(),
  2118. });
  2119. });
  2120. }
  2121. } catch (e) {
  2122. console.log(e.message);
  2123. }
  2124. }
  2125. if (rule.图片替换) {
  2126. if (rule.图片替换.startsWith('js:')) {
  2127. d.forEach(it => {
  2128. try {
  2129. var input = it.vod_pic;
  2130. eval(rule.图片替换.trim().replace('js:', ''));
  2131. it.vod_pic = input;
  2132. } catch (e) {
  2133. log(`图片:${it.vod_pic}替换错误:${e.message}`);
  2134. }
  2135. });
  2136. } else if (rule.图片替换.includes('=>')) {
  2137. let replace_from = rule.图片替换.split('=>')[0];
  2138. let replace_to = rule.图片替换.split('=>')[1];
  2139. d.forEach(it => {
  2140. if (it.vod_pic && it.vod_pic.startsWith('http')) {
  2141. it.vod_pic = it.vod_pic.replace(replace_from, replace_to);
  2142. }
  2143. });
  2144. }
  2145. }
  2146. if (rule.图片来源) {
  2147. d.forEach(it => {
  2148. if (it.vod_pic && it.vod_pic.startsWith('http')) {
  2149. it.vod_pic = it.vod_pic + rule.图片来源;
  2150. }
  2151. });
  2152. }
  2153. // print(d);
  2154. if (d.length > 0) {
  2155. print(d.slice(0, 2));
  2156. }
  2157. let pagecount = 0;
  2158. if (rule.pagecount && typeof (rule.pagecount) === 'object' && rule.pagecount.hasOwnProperty(MY_CATE)) {
  2159. print(`MY_CATE:${MY_CATE},pagecount:${JSON.stringify(rule.pagecount)}`);
  2160. pagecount = parseInt(rule.pagecount[MY_CATE]);
  2161. }
  2162. let nodata = {
  2163. list: [{
  2164. vod_name: '无数据,防无限请求',
  2165. vod_id: 'no_data',
  2166. vod_remarks: '不要点,会崩的',
  2167. vod_pic: 'https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/404.jpg'
  2168. }],
  2169. total: 1, pagecount: 1, page: 1, limit: 1
  2170. };
  2171. let vod = d.length < 1 ? JSON.stringify(nodata) : JSON.stringify({
  2172. 'page': parseInt(cateObj.pg),
  2173. 'pagecount': pagecount || 999,
  2174. 'limit': 20,
  2175. 'total': 999,
  2176. 'list': d,
  2177. });
  2178. // print(vod);
  2179. return vod
  2180. }
  2181. /**
  2182. * 搜索列表数据解析
  2183. * @param searchObj
  2184. * @returns {string}
  2185. */
  2186. function searchParse(searchObj) {
  2187. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  2188. let d = [];
  2189. if (!searchObj.searchUrl) {
  2190. return '{}'
  2191. }
  2192. let p = searchObj.搜索 === '*' && rule.一级 ? rule.一级 : searchObj.搜索;
  2193. if (!p || typeof (p) !== 'string') {
  2194. return '{}'
  2195. }
  2196. p = p.trim();
  2197. let pp = rule.一级 ? rule.一级.split(';') : [];
  2198. let url = searchObj.searchUrl.replaceAll('**', searchObj.wd);
  2199. if (searchObj.pg === 1 && url.includes('[') && url.includes(']') && !url.includes('#')) {
  2200. url = url.split('[')[1].split(']')[0];
  2201. } else if (searchObj.pg > 1 && url.includes('[') && url.includes(']') && !url.includes('#')) {
  2202. url = url.split('[')[0];
  2203. }
  2204. if (/fypage/.test(url)) {
  2205. if (url.includes('(') && url.includes(')')) {
  2206. let url_rep = url.match(/.*?\((.*)\)/)[1];
  2207. // console.log(url_rep);
  2208. let cnt_page = url_rep.replaceAll('fypage', searchObj.pg);
  2209. // console.log(cnt_page);
  2210. let cnt_pg = eval(cnt_page);
  2211. // console.log(cnt_pg);
  2212. url = url.replaceAll(url_rep, cnt_pg).replaceAll('(', '').replaceAll(')', '');
  2213. } else {
  2214. url = url.replaceAll('fypage', searchObj.pg);
  2215. }
  2216. }
  2217. MY_URL = url;
  2218. console.log(MY_URL);
  2219. // log(searchObj.搜索);
  2220. // setItem('MY_URL',MY_URL);
  2221. if (p.startsWith('js:')) {
  2222. const TYPE = 'search';
  2223. const MY_PAGE = searchObj.pg;
  2224. const KEY = searchObj.wd;
  2225. var input = MY_URL;
  2226. var detailUrl = rule.detailUrl || '';
  2227. eval(p.trim().replace('js:', ''));
  2228. d = VODS;
  2229. } else {
  2230. p = p.split(';');
  2231. if (p.length < 5) {
  2232. return '{}'
  2233. }
  2234. let p0 = getPP(p, 0, pp, 0);
  2235. let _ps = parseTags.getParse(p0);
  2236. _pdfa = _ps.pdfa;
  2237. _pdfh = _ps.pdfh;
  2238. _pd = _ps.pd;
  2239. let is_json = p0.startsWith('json:');
  2240. p0 = p0.replace(/^(jsp:|json:|jq:)/, '');
  2241. // print('1381 p0:'+p0);
  2242. try {
  2243. let req_method = MY_URL.split(';').length > 1 ? MY_URL.split(';')[1].toLowerCase() : 'get';
  2244. let html;
  2245. if (req_method === 'post') {
  2246. let rurls = MY_URL.split(';')[0].split('#')
  2247. let rurl = rurls[0]
  2248. let params = rurls.length > 1 ? rurls[1] : '';
  2249. print(`post=》rurl:${rurl},params:${params}`);
  2250. // let new_dict = {};
  2251. // let new_tmp = params.split('&');
  2252. // new_tmp.forEach(i=>{
  2253. // new_dict[i.split('=')[0]] = i.split('=')[1];
  2254. // });
  2255. // html = post(rurl,{body:new_dict});
  2256. let _fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  2257. let postData = {body: params};
  2258. Object.assign(_fetch_params, postData);
  2259. html = post(rurl, _fetch_params);
  2260. } else if (req_method === 'postjson') {
  2261. let rurls = MY_URL.split(';')[0].split('#')
  2262. let rurl = rurls[0]
  2263. let params = rurls.length > 1 ? rurls[1] : '';
  2264. print(`postjson-》rurl:${rurl},params:${params}`);
  2265. try {
  2266. params = JSON.parse(params);
  2267. } catch (e) {
  2268. params = '{}'
  2269. }
  2270. let _fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  2271. let postData = {body: params};
  2272. Object.assign(_fetch_params, postData);
  2273. html = post(rurl, _fetch_params);
  2274. } else {
  2275. html = getHtml(MY_URL);
  2276. }
  2277. if (html) {
  2278. if (/系统安全验证|输入验证码/.test(html)) {
  2279. let cookie = verifyCode(MY_URL);
  2280. if (cookie) {
  2281. console.log(`本次成功过验证,cookie:${cookie}`);
  2282. setItem(RULE_CK, cookie);
  2283. } else {
  2284. console.log(`本次自动过搜索验证失败,cookie:${cookie}`);
  2285. }
  2286. // obj.headers['Cookie'] = cookie;
  2287. html = getHtml(MY_URL);
  2288. }
  2289. if (!html.includes(searchObj.wd)) {
  2290. console.log('搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码');
  2291. console.log(html);
  2292. }
  2293. if (is_json) {
  2294. // console.log(html);
  2295. html = dealJson(html);
  2296. // console.log(JSON.stringify(html));
  2297. }
  2298. // console.log(html);
  2299. let list = _pdfa(html, p0);
  2300. // print(list.length);
  2301. // print(list);
  2302. let p1 = getPP(p, 1, pp, 1);
  2303. let p2 = getPP(p, 2, pp, 2);
  2304. let p3 = getPP(p, 3, pp, 3);
  2305. let p4 = getPP(p, 4, pp, 4);
  2306. let p5 = getPP(p, 5, pp, 5);
  2307. list.forEach(it => {
  2308. let links = p4.split('+').map(_p4 => {
  2309. return !rule.detailUrl ? _pd(it, _p4, MY_URL) : _pdfh(it, _p4)
  2310. });
  2311. let link = links.join('$');
  2312. let content;
  2313. if (p.length > 5 && p[5]) {
  2314. content = _pdfh(it, p5);
  2315. } else {
  2316. content = '';
  2317. }
  2318. let vod_id = link;
  2319. let vod_name = _pdfh(it, p1).replace(/\n|\t/g, '').trim();
  2320. let vod_pic = _pd(it, p2, MY_URL);
  2321. if (rule.二级 === '*') {
  2322. vod_id = vod_id + '@@' + vod_name + '@@' + vod_pic;
  2323. }
  2324. let ob = {
  2325. 'vod_id': vod_id,
  2326. 'vod_name': vod_name,
  2327. 'vod_pic': vod_pic,
  2328. 'vod_remarks': _pdfh(it, p3).replace(/\n|\t/g, '').trim(),
  2329. 'vod_content': content.replace(/\n|\t/g, '').trim(),
  2330. };
  2331. d.push(ob);
  2332. });
  2333. }
  2334. } catch (e) {
  2335. print('搜索发生错误:' + e.message);
  2336. return '{}'
  2337. }
  2338. }
  2339. if (rule.图片替换) {
  2340. if (rule.图片替换.startsWith('js:')) {
  2341. d.forEach(it => {
  2342. try {
  2343. var input = it.vod_pic;
  2344. eval(rule.图片替换.trim().replace('js:', ''));
  2345. it.vod_pic = input;
  2346. } catch (e) {
  2347. log(`图片:${it.vod_pic}替换错误:${e.message}`);
  2348. }
  2349. });
  2350. } else if (rule.图片替换.includes('=>')) {
  2351. let replace_from = rule.图片替换.split('=>')[0];
  2352. let replace_to = rule.图片替换.split('=>')[1];
  2353. d.forEach(it => {
  2354. if (it.vod_pic && it.vod_pic.startsWith('http')) {
  2355. it.vod_pic = it.vod_pic.replace(replace_from, replace_to);
  2356. }
  2357. });
  2358. }
  2359. }
  2360. if (rule.图片来源) {
  2361. d.forEach(it => {
  2362. if (it.vod_pic && it.vod_pic.startsWith('http')) {
  2363. it.vod_pic = it.vod_pic + rule.图片来源;
  2364. }
  2365. });
  2366. }
  2367. // print(d);
  2368. return JSON.stringify({
  2369. 'page': parseInt(searchObj.pg),
  2370. 'pagecount': 10,
  2371. 'limit': 20,
  2372. 'total': 100,
  2373. 'list': d,
  2374. });
  2375. }
  2376. /**
  2377. * 二级详情页数据解析
  2378. * @param detailObj
  2379. * @returns {string}
  2380. */
  2381. function detailParse(detailObj) {
  2382. let t1 = (new Date()).getTime();
  2383. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  2384. let orId = detailObj.orId;
  2385. let vod_name = '片名';
  2386. let vod_pic = '';
  2387. let vod_id = orId;
  2388. if (rule.二级 === '*') {
  2389. // vod_id = orId.split('@@')[0]; // 千万不能分割
  2390. let extra = orId.split('@@');
  2391. vod_name = extra.length > 1 ? extra[1] : vod_name;
  2392. vod_pic = extra.length > 2 ? extra[2] : vod_pic;
  2393. }
  2394. // print(vod_pic);
  2395. let vod = {
  2396. vod_id: vod_id, //"id",
  2397. vod_name: vod_name,
  2398. vod_pic: vod_pic,
  2399. type_name: "类型",
  2400. vod_year: "年份",
  2401. vod_area: "地区",
  2402. vod_remarks: "更新信息",
  2403. vod_actor: "主演",
  2404. vod_director: "导演",
  2405. vod_content: "简介"
  2406. };
  2407. let p = detailObj.二级;
  2408. let url = detailObj.url;
  2409. let detailUrl = detailObj.detailUrl;
  2410. let fyclass = detailObj.fyclass;
  2411. let tab_exclude = detailObj.tab_exclude;
  2412. let html = detailObj.html || '';
  2413. MY_URL = url;
  2414. if (detailObj.二级访问前) {
  2415. try {
  2416. print(`尝试在二级访问前执行代码:${detailObj.二级访问前}`);
  2417. eval(detailObj.二级访问前.trim().replace('js:', ''));
  2418. } catch (e) {
  2419. print(`二级访问前执行代码出现错误:${e.message}`)
  2420. }
  2421. }
  2422. // console.log(MY_URL);
  2423. // setItem('MY_URL',MY_URL);
  2424. if (p === '*') {
  2425. vod.vod_play_from = '道长在线';
  2426. vod.vod_remarks = detailUrl;
  2427. vod.vod_actor = '没有二级,只有一级链接直接嗅探播放';
  2428. vod.vod_content = MY_URL;
  2429. vod.vod_play_url = '嗅探播放$' + MY_URL.split('@@')[0];
  2430. } else if (typeof (p) === 'string' && p.trim().startsWith('js:')) {
  2431. const TYPE = 'detail';
  2432. var input = MY_URL;
  2433. var play_url = '';
  2434. eval(p.trim().replace('js:', ''));
  2435. vod = VOD;
  2436. console.log(JSON.stringify(vod));
  2437. } else if (p && typeof (p) === 'object') {
  2438. let tt1 = (new Date()).getTime();
  2439. if (!html) {
  2440. html = getHtml(MY_URL);
  2441. }
  2442. print(`二级${MY_URL}仅获取源码耗时:${(new Date()).getTime() - tt1}毫秒`);
  2443. let _ps;
  2444. if (p.is_json) {
  2445. print('二级是json');
  2446. _ps = parseTags.json;
  2447. html = dealJson(html);
  2448. } else if (p.is_jsp) {
  2449. print('二级是jsp');
  2450. _ps = parseTags.jsp;
  2451. } else if (p.is_jq) {
  2452. print('二级是jq');
  2453. _ps = parseTags.jq;
  2454. } else {
  2455. print('二级默认jq');
  2456. _ps = parseTags.jq;
  2457. // print('二级默认jsp');
  2458. // _ps = parseTags.jsp;
  2459. }
  2460. let tt2 = (new Date()).getTime();
  2461. print(`二级${MY_URL}获取并装载源码耗时:${tt2 - tt1}毫秒`);
  2462. _pdfa = _ps.pdfa;
  2463. _pdfh = _ps.pdfh;
  2464. _pd = _ps.pd;
  2465. if (p.title) {
  2466. let p1 = p.title.split(';');
  2467. vod.vod_name = _pdfh(html, p1[0]).replace(/\n|\t/g, '').trim();
  2468. let type_name = p1.length > 1 ? _pdfh(html, p1[1]).replace(/\n|\t/g, '').replace(/ /g, '').trim() : '';
  2469. vod.type_name = type_name || vod.type_name;
  2470. }
  2471. if (p.desc) {
  2472. try {
  2473. let p1 = p.desc.split(';');
  2474. vod.vod_remarks = _pdfh(html, p1[0]).replace(/\n|\t/g, '').trim();
  2475. vod.vod_year = p1.length > 1 ? _pdfh(html, p1[1]).replace(/\n|\t/g, '').trim() : '';
  2476. vod.vod_area = p1.length > 2 ? _pdfh(html, p1[2]).replace(/\n|\t/g, '').trim() : '';
  2477. // vod.vod_actor = p1.length > 3 ? _pdfh(html, p1[3]).replaceAll('\n', ' ').trim():'';
  2478. vod.vod_actor = p1.length > 3 ? _pdfh(html, p1[3]).replace(/\n|\t/g, '').trim() : '';
  2479. vod.vod_director = p1.length > 4 ? _pdfh(html, p1[4]).replace(/\n|\t/g, '').trim() : '';
  2480. } catch (e) {
  2481. }
  2482. }
  2483. if (p.content) {
  2484. try {
  2485. let p1 = p.content.split(';');
  2486. vod.vod_content = _pdfh(html, p1[0]).replace(/\n|\t/g, '').trim();
  2487. } catch (e) {
  2488. }
  2489. }
  2490. if (p.img) {
  2491. try {
  2492. let p1 = p.img.split(';');
  2493. vod.vod_pic = _pd(html, p1[0], MY_URL);
  2494. } catch (e) {
  2495. }
  2496. }
  2497. let vod_play_from = '$$$';
  2498. let playFrom = [];
  2499. if (p.重定向 && p.重定向.startsWith('js:')) {
  2500. print('开始执行重定向代码:' + p.重定向);
  2501. html = eval(p.重定向.replace('js:', ''));
  2502. }
  2503. // console.log(2);
  2504. if (p.tabs) {
  2505. if (p.tabs.startsWith('js:')) {
  2506. print('开始执行tabs代码:' + p.tabs);
  2507. var input = MY_URL;
  2508. eval(p.tabs.replace('js:', ''));
  2509. playFrom = TABS;
  2510. } else {
  2511. let p_tab = p.tabs.split(';')[0];
  2512. // console.log(p_tab);
  2513. let vHeader = _pdfa(html, p_tab);
  2514. console.log(vHeader.length);
  2515. let tab_text = p.tab_text || 'body&&Text';
  2516. // print('tab_text:'+tab_text);
  2517. let new_map = {};
  2518. for (let v of vHeader) {
  2519. let v_title = _pdfh(v, tab_text).trim();
  2520. if (!v_title) {
  2521. v_title = '线路空'
  2522. }
  2523. console.log(v_title);
  2524. if (tab_exclude && (new RegExp(tab_exclude)).test(v_title)) {
  2525. continue;
  2526. }
  2527. if (!new_map.hasOwnProperty(v_title)) {
  2528. new_map[v_title] = 1;
  2529. } else {
  2530. new_map[v_title] += 1;
  2531. }
  2532. if (new_map[v_title] > 1) {
  2533. v_title += Number(new_map[v_title] - 1);
  2534. }
  2535. playFrom.push(v_title);
  2536. }
  2537. }
  2538. console.log(JSON.stringify(playFrom));
  2539. } else {
  2540. playFrom = ['道长在线']
  2541. }
  2542. vod.vod_play_from = playFrom.join(vod_play_from);
  2543. // console.log(3);
  2544. let vod_play_url = '$$$';
  2545. let vod_tab_list = [];
  2546. if (p.lists) {
  2547. if (p.lists.startsWith('js:')) {
  2548. print('开始执行lists代码:' + p.lists);
  2549. try {
  2550. var input = MY_URL;
  2551. var play_url = '';
  2552. eval(p.lists.replace('js:', ''));
  2553. for (let i in LISTS) {
  2554. if (LISTS.hasOwnProperty(i)) {
  2555. // print(i);
  2556. try {
  2557. LISTS[i] = LISTS[i].map(it => it.split('$').slice(0, 2).join('$'));
  2558. } catch (e) {
  2559. print('格式化LISTS发生错误:' + e.message);
  2560. }
  2561. }
  2562. }
  2563. vod_play_url = LISTS.map(it => it.join('#')).join(vod_play_url);
  2564. } catch (e) {
  2565. print('js执行lists: 发生错误:' + e.message);
  2566. }
  2567. } else {
  2568. let list_text = p.list_text || 'body&&Text';
  2569. let list_url = p.list_url || 'a&&href';
  2570. let list_url_prefix = p.list_url_prefix || '';
  2571. // print('list_text:'+list_text);
  2572. // print('list_url:'+list_url);
  2573. // print('list_parse:'+p.lists);
  2574. let is_tab_js = p.tabs.trim().startsWith('js:');
  2575. for (let i = 0; i < playFrom.length; i++) {
  2576. let tab_name = playFrom[i];
  2577. let tab_ext = p.tabs.split(';').length > 1 && !is_tab_js ? p.tabs.split(';')[1] : '';
  2578. let p1 = p.lists.replaceAll('#idv', tab_name).replaceAll('#id', i);
  2579. tab_ext = tab_ext.replaceAll('#idv', tab_name).replaceAll('#id', i);
  2580. let tabName = tab_ext ? _pdfh(html, tab_ext) : tab_name;
  2581. console.log(tabName);
  2582. // print('tab_ext:'+tab_ext);
  2583. let new_vod_list = [];
  2584. let tt1 = (new Date()).getTime();
  2585. // print('pdfl:'+typeof (pdfl));
  2586. if (typeof (pdfl) === 'function') {
  2587. new_vod_list = pdfl(html, p1, list_text, list_url, MY_URL);
  2588. if (list_url_prefix) {
  2589. new_vod_list = new_vod_list.map(it => it.split('$')[0] + '$' + list_url_prefix + it.split('$').slice(1).join('$'));
  2590. }
  2591. } else {
  2592. let vodList = [];
  2593. try {
  2594. vodList = _pdfa(html, p1);
  2595. console.log('len(vodList):' + vodList.length);
  2596. } catch (e) {
  2597. // console.log(e.message);
  2598. }
  2599. for (let i = 0; i < vodList.length; i++) {
  2600. let it = vodList[i];
  2601. new_vod_list.push(_pdfh(it, list_text).trim() + '$' + list_url_prefix + _pd(it, list_url, MY_URL));
  2602. }
  2603. }
  2604. if (new_vod_list.length > 0) {
  2605. new_vod_list = forceOrder(new_vod_list, '', x => x.split('$')[0]);
  2606. console.log(`drpy影响性能代码共计列表数循环次数:${new_vod_list.length},耗时:${(new Date()).getTime() - tt1}毫秒`);
  2607. }
  2608. // print(new_vod_list);
  2609. let vlist = new_vod_list.join('#');
  2610. vod_tab_list.push(vlist);
  2611. }
  2612. vod_play_url = vod_tab_list.join(vod_play_url);
  2613. }
  2614. }
  2615. vod.vod_play_url = vod_play_url;
  2616. }
  2617. if (rule.图片替换 && rule.图片替换.includes('=>')) {
  2618. let replace_from = rule.图片替换.split('=>')[0];
  2619. let replace_to = rule.图片替换.split('=>')[1];
  2620. vod.vod_pic = vod.vod_pic.replace(replace_from, replace_to);
  2621. }
  2622. if (rule.图片来源 && vod.vod_pic && vod.vod_pic.startsWith('http')) {
  2623. vod.vod_pic = vod.vod_pic + rule.图片来源;
  2624. }
  2625. if (!vod.vod_id || (vod_id.includes('$') && vod.vod_id !== vod_id)) {
  2626. vod.vod_id = vod_id;
  2627. }
  2628. let t2 = (new Date()).getTime();
  2629. console.log(`加载二级界面${MY_URL}耗时:${t2 - t1}毫秒`);
  2630. // print(vod);
  2631. try {
  2632. vod = vodDeal(vod);
  2633. } catch (e) {
  2634. console.log(`vodDeal发生错误:${e.message}`);
  2635. }
  2636. // print(vod);
  2637. return JSON.stringify({
  2638. list: [vod]
  2639. })
  2640. }
  2641. /**
  2642. * 获取二级待返回的播放线路没处理时的索引关系
  2643. * @param vod
  2644. * @returns {{}}
  2645. */
  2646. function get_tab_index(vod) {
  2647. let obj = {};
  2648. vod.vod_play_from.split('$$$').forEach((it, index) => {
  2649. obj[it] = index;
  2650. });
  2651. return obj
  2652. }
  2653. /**
  2654. * 处理待返回的vod数据|线路去除,排序,重命名
  2655. * @param vod
  2656. * @returns {*}
  2657. */
  2658. function vodDeal(vod) {
  2659. let vod_play_from = vod.vod_play_from.split('$$$');
  2660. let vod_play_url = vod.vod_play_url.split('$$$');
  2661. // 移除指定线路后的列表
  2662. let tab_removed_list = vod_play_from;
  2663. // 排序后的线路列表
  2664. let tab_ordered_list = vod_play_from;
  2665. // 线路重命名后的列表
  2666. let tab_renamed_list = vod_play_from;
  2667. // 定义实际要返回线路
  2668. let tab_list = vod_play_from;
  2669. // 选集列表根据线路排序
  2670. let play_ordered_list = vod_play_url;
  2671. // 判断有移除线路或者线路排序
  2672. if ((rule.tab_remove && rule.tab_remove.length > 0) || (rule.tab_order && rule.tab_order.length > 0)) {
  2673. // 获取原来线路的索引下标
  2674. let tab_index_dict = get_tab_index(vod);
  2675. if (rule.tab_remove && rule.tab_remove.length > 0) {
  2676. tab_removed_list = vod_play_from.filter(it => !rule.tab_remove.includes(it));
  2677. tab_list = tab_removed_list;
  2678. }
  2679. if (rule.tab_order && rule.tab_order.length > 0) {
  2680. let tab_order = rule.tab_order;
  2681. tab_ordered_list = tab_removed_list.sort((a, b) => {
  2682. return (tab_order.indexOf(a) === -1 ? 9999 : tab_order.indexOf(a)) - (tab_order.indexOf(b) === -1 ? 9999 : tab_order.indexOf(b))
  2683. });
  2684. tab_list = tab_ordered_list;
  2685. }
  2686. play_ordered_list = tab_list.map(it => vod_play_url[tab_index_dict[it]]);
  2687. }
  2688. if (rule.tab_rename && typeof (rule.tab_rename) === 'object' & Object.keys(rule.tab_rename).length > 0) {
  2689. tab_renamed_list = tab_list.map(it => rule.tab_rename[it] || it);
  2690. tab_list = tab_renamed_list;
  2691. }
  2692. vod.vod_play_from = tab_list.join('$$$');
  2693. vod.vod_play_url = play_ordered_list.join('$$$');
  2694. return vod
  2695. }
  2696. /**
  2697. * 判断是否需要解析
  2698. * @param url
  2699. * @returns {number|number}
  2700. */
  2701. function tellIsJx(url) {
  2702. try {
  2703. let is_vip = !/\.(m3u8|mp4|m4a)$/.test(url.split('?')[0]) && 是否正版(url);
  2704. return is_vip ? 1 : 0
  2705. } catch (e) {
  2706. return 1
  2707. }
  2708. }
  2709. /**
  2710. * 选集播放点击事件解析
  2711. * @param playObj
  2712. * @returns {string}
  2713. */
  2714. function playParse(playObj) {
  2715. fetch_params = JSON.parse(JSON.stringify(rule_fetch_params));
  2716. MY_URL = playObj.url;
  2717. var MY_FLAG = playObj.flag;
  2718. if (!/http/.test(MY_URL)) {
  2719. try {
  2720. MY_URL = base64Decode(MY_URL);
  2721. } catch (e) {
  2722. }
  2723. }
  2724. MY_URL = decodeURIComponent(MY_URL);
  2725. var input = MY_URL;//注入给免嗅js
  2726. var flag = MY_FLAG;//注入播放线路名称给免嗅js
  2727. let common_play = {
  2728. parse: SPECIAL_URL.test(input) || /^(push:)/.test(input) ? 0 : 1,
  2729. url: input,
  2730. flag: flag,
  2731. // url:urlencode(input),
  2732. jx: tellIsJx(input)
  2733. };
  2734. let lazy_play;
  2735. if (!rule.play_parse || !rule.lazy) {
  2736. lazy_play = common_play;
  2737. } else if (rule.play_parse && rule.lazy && typeof (rule.lazy) === 'string') {
  2738. try {
  2739. let lazy_code = rule.lazy.trim();
  2740. if (lazy_code.startsWith('js:')) {
  2741. lazy_code = lazy_code.replace('js:', '').trim();
  2742. }
  2743. print('开始执行js免嗅=>' + lazy_code);
  2744. eval(lazy_code);
  2745. lazy_play = typeof (input) === 'object' ? input : {
  2746. parse: 1,
  2747. jx: tellIsJx(input),
  2748. url: input
  2749. };
  2750. } catch (e) {
  2751. print('js免嗅错误:' + e.message);
  2752. lazy_play = common_play;
  2753. }
  2754. } else {
  2755. lazy_play = common_play;
  2756. }
  2757. // print('play_json:'+typeof(rule.play_json));
  2758. // console.log(Array.isArray(rule.play_json));
  2759. if (Array.isArray(rule.play_json) && rule.play_json.length > 0) { // 数组情况判断长度大于0
  2760. let web_url = lazy_play.url;
  2761. for (let pjson of rule.play_json) {
  2762. if (pjson.re && (pjson.re === '*' || web_url.match(new RegExp(pjson.re)))) {
  2763. if (pjson.json && typeof (pjson.json) === 'object') {
  2764. let base_json = pjson.json;
  2765. // print('开始合并:');
  2766. // print(base_json);
  2767. lazy_play = Object.assign(lazy_play, base_json);
  2768. break;
  2769. }
  2770. }
  2771. }
  2772. } else if (rule.play_json && !Array.isArray(rule.play_json)) { // 其他情况 非[] 判断true/false
  2773. let base_json = {
  2774. jx: 1,
  2775. parse: 1,
  2776. };
  2777. lazy_play = Object.assign(lazy_play, base_json);
  2778. } else if (!rule.play_json) { // 不解析传0
  2779. let base_json = {
  2780. jx: 0,
  2781. parse: 1,
  2782. };
  2783. lazy_play = Object.assign(lazy_play, base_json);
  2784. }
  2785. console.log(JSON.stringify(lazy_play));
  2786. return JSON.stringify(lazy_play);
  2787. }
  2788. /**
  2789. * 本地代理解析规则
  2790. * @param params
  2791. */
  2792. function proxyParse(proxyObj) {
  2793. var input = proxyObj.params;
  2794. if (proxyObj.proxy_rule) {
  2795. log('准备执行本地代理规则:\n' + proxyObj.proxy_rule);
  2796. try {
  2797. eval(proxyObj.proxy_rule);
  2798. if (input && input !== proxyObj.params && Array.isArray(input) && input.length === 3) {
  2799. return input
  2800. } else {
  2801. return [404, 'text/plain', 'Not Found']
  2802. }
  2803. } catch (e) {
  2804. return [500, 'text/plain', '代理规则错误:' + e.message]
  2805. }
  2806. } else {
  2807. return [404, 'text/plain', 'Not Found']
  2808. }
  2809. }
  2810. /**
  2811. * 辅助嗅探解析规则
  2812. * @param isVideoObj
  2813. * @returns {boolean}
  2814. */
  2815. function isVideoParse(isVideoObj) {
  2816. var input = isVideoObj.url;
  2817. if (!isVideoObj.t) { // t为假代表默认传的正则字符串
  2818. let re_matcher = new RegExp(isVideoObj.isVideo, 'i'); // /g匹配多个,/i不区分大小写,/m匹配多行
  2819. return re_matcher.test(input);
  2820. } else {
  2821. // 执行js
  2822. try {
  2823. eval(isVideoObj.isVideo);
  2824. if (typeof (input) === 'boolean') {
  2825. return input
  2826. } else {
  2827. return false
  2828. }
  2829. } catch (e) {
  2830. log('执行嗅探规则发生错误:' + e.message);
  2831. return false
  2832. }
  2833. }
  2834. }
  2835. /**
  2836. * 获取加密前的原始的js源文本
  2837. * @param js_code
  2838. */
  2839. function getOriginalJs(js_code) {
  2840. let current_match = /var rule|[\u4E00-\u9FA5]+|function|let |var |const |\(|\)|"|'/;
  2841. if (current_match.test(js_code)) {
  2842. return js_code
  2843. }
  2844. let rsa_private_key = 'MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCqin/jUpqM6+fgYP/oMqj9zcdHMM0mEZXLeTyixIJWP53lzJV2N2E3OP6BBpUmq2O1a9aLnTIbADBaTulTNiOnVGoNG58umBnupnbmmF8iARbDp2mTzdMMeEgLdrfXS6Y3VvazKYALP8EhEQykQVarexR78vRq7ltY3quXx7cgI0ROfZz5Sw3UOLQJ+VoWmwIxu9AMEZLVzFDQN93hzuzs3tNyHK6xspBGB7zGbwCg+TKi0JeqPDrXxYUpAz1cQ/MO+Da0WgvkXnvrry8NQROHejdLVOAslgr6vYthH9bKbsGyNY3H+P12kcxo9RAcVveONnZbcMyxjtF5dWblaernAgMBAAECggEAGdEHlSEPFmAr5PKqKrtoi6tYDHXdyHKHC5tZy4YV+Pp+a6gxxAiUJejx1hRqBcWSPYeKne35BM9dgn5JofgjI5SKzVsuGL6bxl3ayAOu+xXRHWM9f0t8NHoM5fdd0zC3g88dX3fb01geY2QSVtcxSJpEOpNH3twgZe6naT2pgiq1S4okpkpldJPo5GYWGKMCHSLnKGyhwS76gF8bTPLoay9Jxk70uv6BDUMlA4ICENjmsYtd3oirWwLwYMEJbSFMlyJvB7hjOjR/4RpT4FPnlSsIpuRtkCYXD4jdhxGlvpXREw97UF2wwnEUnfgiZJ2FT/MWmvGGoaV/CfboLsLZuQKBgQDTNZdJrs8dbijynHZuuRwvXvwC03GDpEJO6c1tbZ1s9wjRyOZjBbQFRjDgFeWs9/T1aNBLUrgsQL9c9nzgUziXjr1Nmu52I0Mwxi13Km/q3mT+aQfdgNdu6ojsI5apQQHnN/9yMhF6sNHg63YOpH+b+1bGRCtr1XubuLlumKKscwKBgQDOtQ2lQjMtwsqJmyiyRLiUOChtvQ5XI7B2mhKCGi8kZ+WEAbNQcmThPesVzW+puER6D4Ar4hgsh9gCeuTaOzbRfZ+RLn3Aksu2WJEzfs6UrGvm6DU1INn0z/tPYRAwPX7sxoZZGxqML/z+/yQdf2DREoPdClcDa2Lmf1KpHdB+vQKBgBXFCVHz7a8n4pqXG/HvrIMJdEpKRwH9lUQS/zSPPtGzaLpOzchZFyQQBwuh1imM6Te+VPHeldMh3VeUpGxux39/m+160adlnRBS7O7CdgSsZZZ/dusS06HAFNraFDZf1/VgJTk9BeYygX+AZYu+0tReBKSs9BjKSVJUqPBIVUQXAoGBAJcZ7J6oVMcXxHxwqoAeEhtvLcaCU9BJK36XQ/5M67ceJ72mjJC6/plUbNukMAMNyyi62gO6I9exearecRpB/OGIhjNXm99Ar59dAM9228X8gGfryLFMkWcO/fNZzb6lxXmJ6b2LPY3KqpMwqRLTAU/zy+ax30eFoWdDHYa4X6e1AoGAfa8asVGOJ8GL9dlWufEeFkDEDKO9ww5GdnpN+wqLwePWqeJhWCHad7bge6SnlylJp5aZXl1+YaBTtOskC4Whq9TP2J+dNIgxsaF5EFZQJr8Xv+lY9lu0CruYOh9nTNF9x3nubxJgaSid/7yRPfAGnsJRiknB5bsrCvgsFQFjJVs=';
  2845. let decode_content = '';
  2846. function aes_decrypt(data) {
  2847. let key = CryptoJS.enc.Hex.parse("686A64686E780A0A0A0A0A0A0A0A0A0A");
  2848. let iv = CryptoJS.enc.Hex.parse("647A797964730A0A0A0A0A0A0A0A0A0A");
  2849. let encrypted = CryptoJS.AES.decrypt({
  2850. ciphertext: CryptoJS.enc.Base64.parse(data)
  2851. }, key, {
  2852. iv: iv,
  2853. mode: CryptoJS.mode.CBC,
  2854. padding: CryptoJS.pad.Pkcs7
  2855. }).toString(CryptoJS.enc.Utf8);
  2856. return encrypted;
  2857. }
  2858. let error_log = false;
  2859. function logger(text) {
  2860. if (error_log) {
  2861. log(text);
  2862. }
  2863. }
  2864. let decode_funcs = [
  2865. (text) => {
  2866. try {
  2867. return ungzip(text)
  2868. } catch (e) {
  2869. logger('非gzip加密');
  2870. return ''
  2871. }
  2872. },
  2873. (text) => {
  2874. try {
  2875. return base64Decode(text)
  2876. } catch (e) {
  2877. logger('非b64加密');
  2878. return ''
  2879. }
  2880. },
  2881. (text) => {
  2882. try {
  2883. return aes_decrypt(text)
  2884. } catch (e) {
  2885. logger('非aes加密');
  2886. return ''
  2887. }
  2888. },
  2889. (text) => {
  2890. try {
  2891. return RSA.decode(text, rsa_private_key, null)
  2892. } catch (e) {
  2893. logger('非rsa加密');
  2894. return ''
  2895. }
  2896. },
  2897. // (text)=>{try {return NODERSA.decryptRSAWithPrivateKey(text, RSA.getPrivateKey(rsa_private_key).replace(/RSA /g,''), {options: {environment: "browser", encryptionScheme: 'pkcs1',b:'1024'}});} catch (e) {log(e.message);return ''}},
  2898. ]
  2899. let func_index = 0
  2900. while (!current_match.test(decode_content)) {
  2901. decode_content = decode_funcs[func_index](js_code);
  2902. func_index++;
  2903. if (func_index >= decode_funcs.length) {
  2904. break;
  2905. }
  2906. }
  2907. return decode_content
  2908. }
  2909. /**
  2910. * 执行main函数
  2911. * 示例 function main(text){return gzip(text)}
  2912. * @param main_func_code
  2913. * @param arg
  2914. */
  2915. function runMain(main_func_code, arg) {
  2916. let mainFunc = function () {
  2917. return ''
  2918. };
  2919. try {
  2920. eval(main_func_code + '\nmainFunc=main;');
  2921. return mainFunc(arg);
  2922. } catch (e) {
  2923. log(`执行main_funct发生了错误:${e.message}`);
  2924. return ''
  2925. }
  2926. }
  2927. /**
  2928. * js源预处理特定返回对象中的函数
  2929. * @param ext
  2930. */
  2931. function init(ext) {
  2932. console.log('init');
  2933. // init前重置rule和fetch_params
  2934. rule = {};
  2935. rule_fetch_params = {};
  2936. fetch_params = null;
  2937. try {
  2938. // make shared jsContext happy muban不能import,不然会造成换源继承后变量被篡改
  2939. // if (typeof (globalThis.mubanJs) === 'undefined') {
  2940. // let mubanJs = request('https://ghproxy.net/https://raw.githubusercontent.com/hjdhnx/dr_py/main/js/模板.js', { 'User-Agent': MOBILE_UA });
  2941. // mubanJs = mubanJs.replace('export default', '(function() {return muban;}()) // export default');
  2942. // // console.log(mubanJs);
  2943. // globalThis.mubanJs = mubanJs;
  2944. // }
  2945. // let muban = eval(globalThis.mubanJs);
  2946. let muban = 模板.getMubans();
  2947. // print(typeof (muban));
  2948. // print(muban);
  2949. if (typeof ext == 'object') {
  2950. rule = ext;
  2951. } else if (typeof ext == 'string') {
  2952. if (ext.startsWith('http') || ext.startsWith('file://')) {
  2953. let query = getQuery(ext); // 获取链接传参
  2954. let js = request(ext, {'method': 'GET'});
  2955. if (js) {
  2956. js = getOriginalJs(js);
  2957. // eval(js.replace('var rule', 'rule'));
  2958. // eval("(function(){'use strict';"+js.replace('var rule', 'rule')+"})()");
  2959. eval("(function(){" + js.replace('var rule', 'rule') + "})()");
  2960. }
  2961. if (query.type === 'url' && query.params) { // 指定type是链接并且传了params支持简写如 ./xx.json
  2962. rule.params = urljoin(ext, query.params);
  2963. } else if (query.params) { // 没指定type直接视为字符串
  2964. rule.params = query.params;
  2965. }
  2966. } else {
  2967. ext = getOriginalJs(ext);
  2968. // eval(ext.replace('var rule', 'rule'));
  2969. // eval("(function(){'use strict';"+ext.replace('var rule', 'rule')+"})()");
  2970. eval("(function(){" + ext.replace('var rule', 'rule') + "})()");
  2971. }
  2972. }
  2973. if (rule.模板 && muban.hasOwnProperty(rule.模板)) {
  2974. print('继承模板:' + rule.模板);
  2975. rule = Object.assign(muban[rule.模板], rule);
  2976. }
  2977. /** 处理一下 rule规则关键字段没传递的情况 **/
  2978. let rule_cate_excludes = (rule.cate_exclude || '').split('|').filter(it => it.trim());
  2979. let rule_tab_excludes = (rule.tab_exclude || '').split('|').filter(it => it.trim());
  2980. rule_cate_excludes = rule_cate_excludes.concat(CATE_EXCLUDE.split('|').filter(it => it.trim()));
  2981. rule_tab_excludes = rule_tab_excludes.concat(TAB_EXCLUDE.split('|').filter(it => it.trim()));
  2982. rule.cate_exclude = rule_cate_excludes.join('|');
  2983. rule.tab_exclude = rule_tab_excludes.join('|');
  2984. rule.host = (rule.host || '').rstrip('/');
  2985. HOST = rule.host;
  2986. if (rule.hostJs) {
  2987. console.log(`检测到hostJs,准备执行...`);
  2988. try {
  2989. eval(rule.hostJs);
  2990. rule.host = HOST.rstrip('/');
  2991. } catch (e) {
  2992. console.log(`执行${rule.hostJs}获取host发生错误:` + e.message);
  2993. }
  2994. }
  2995. rule.类型 = rule.类型 || '影视'; // 影视|听书|漫画|小说
  2996. rule.url = rule.url || '';
  2997. rule.double = rule.double || false;
  2998. rule.homeUrl = rule.homeUrl || '';
  2999. rule.detailUrl = rule.detailUrl || '';
  3000. rule.searchUrl = rule.searchUrl || '';
  3001. rule.homeUrl = rule.host && rule.homeUrl ? urljoin(rule.host, rule.homeUrl) : (rule.homeUrl || rule.host);
  3002. rule.homeUrl = cheerio.jinja2(rule.homeUrl, {rule: rule});
  3003. rule.detailUrl = rule.host && rule.detailUrl ? urljoin(rule.host, rule.detailUrl) : rule.detailUrl;
  3004. rule.二级访问前 = rule.二级访问前 || '';
  3005. if (rule.url.includes('[') && rule.url.includes(']')) {
  3006. let u1 = rule.url.split('[')[0]
  3007. let u2 = rule.url.split('[')[1].split(']')[0]
  3008. rule.url = rule.host && rule.url ? urljoin(rule.host, u1) + '[' + urljoin(rule.host, u2) + ']' : rule.url;
  3009. } else {
  3010. rule.url = rule.host && rule.url ? urljoin(rule.host, rule.url) : rule.url;
  3011. }
  3012. if (rule.searchUrl.includes('[') && rule.searchUrl.includes(']') && !rule.searchUrl.includes('#')) {
  3013. let u1 = rule.searchUrl.split('[')[0]
  3014. let u2 = rule.searchUrl.split('[')[1].split(']')[0]
  3015. rule.searchUrl = rule.host && rule.searchUrl ? urljoin(rule.host, u1) + '[' + urljoin(rule.host, u2) + ']' : rule.searchUrl;
  3016. } else {
  3017. rule.searchUrl = rule.host && rule.searchUrl ? urljoin(rule.host, rule.searchUrl) : rule.searchUrl;
  3018. }
  3019. rule.timeout = rule.timeout || 5000;
  3020. rule.encoding = rule.编码 || rule.encoding || 'utf-8';
  3021. rule.search_encoding = rule.搜索编码 || rule.search_encoding || '';
  3022. rule.图片来源 = rule.图片来源 || '';
  3023. rule.图片替换 = rule.图片替换 || '';
  3024. rule.play_json = rule.hasOwnProperty('play_json') ? rule.play_json : [];
  3025. rule.pagecount = rule.hasOwnProperty('pagecount') ? rule.pagecount : {};
  3026. rule.proxy_rule = rule.hasOwnProperty('proxy_rule') ? rule.proxy_rule : '';
  3027. if (!rule.hasOwnProperty('sniffer')) { // 默认关闭辅助嗅探
  3028. rule.sniffer = false;
  3029. }
  3030. rule.sniffer = rule.hasOwnProperty('sniffer') ? rule.sniffer : '';
  3031. rule.sniffer = !!(rule.sniffer && rule.sniffer !== '0' && rule.sniffer !== 'false');
  3032. rule.isVideo = rule.hasOwnProperty('isVideo') ? rule.isVideo : '';
  3033. if (rule.sniffer && !rule.isVideo) { // 默认辅助嗅探自动增强嗅探规则
  3034. rule.isVideo = 'http((?!http).){12,}?\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)\\?.*|http((?!http).){12,}\\.(m3u8|mp4|flv|avi|mkv|rm|wmv|mpg|m4a|mp3)|http((?!http).)*?video/tos*|http((?!http).)*?obj/tos*';
  3035. }
  3036. rule.tab_remove = rule.hasOwnProperty('tab_remove') ? rule.tab_remove : [];
  3037. rule.tab_order = rule.hasOwnProperty('tab_order') ? rule.tab_order : [];
  3038. rule.tab_rename = rule.hasOwnProperty('tab_rename') ? rule.tab_rename : {};
  3039. if (rule.headers && typeof (rule.headers) === 'object') {
  3040. try {
  3041. let header_keys = Object.keys(rule.headers);
  3042. for (let k of header_keys) {
  3043. if (k.toLowerCase() === 'user-agent') {
  3044. let v = rule.headers[k];
  3045. console.log(v);
  3046. if (['MOBILE_UA', 'PC_UA', 'UC_UA', 'IOS_UA', 'UA'].includes(v)) {
  3047. rule.headers[k] = eval(v);
  3048. }
  3049. } else if (k.toLowerCase() === 'cookie') {
  3050. let v = rule.headers[k];
  3051. if (v && v.startsWith('http')) {
  3052. console.log(v);
  3053. try {
  3054. v = fetch(v);
  3055. console.log(v);
  3056. rule.headers[k] = v;
  3057. } catch (e) {
  3058. console.log(`从${v}获取cookie发生错误:` + e.message);
  3059. }
  3060. }
  3061. }
  3062. }
  3063. } catch (e) {
  3064. console.log('处理headers发生错误:' + e.message);
  3065. }
  3066. }
  3067. // print(rule.headers);
  3068. rule_fetch_params = {'headers': rule.headers || false, 'timeout': rule.timeout, 'encoding': rule.encoding};
  3069. oheaders = rule.headers || {};
  3070. RKEY = typeof (key) !== 'undefined' && key ? key : 'drpy_' + (rule.title || rule.host);
  3071. pre(); // 预处理
  3072. init_test();
  3073. } catch (e) {
  3074. console.log('init_test发生错误:' + e.message);
  3075. }
  3076. }
  3077. let homeHtmlCache = undefined;
  3078. /**
  3079. * js源获取首页分类和筛选特定返回对象中的函数
  3080. * @param filter 筛选条件字典对象
  3081. * @returns {string}
  3082. */
  3083. function home(filter) {
  3084. console.log("home");
  3085. if (typeof (rule.filter) === 'string' && rule.filter.trim().length > 0) {
  3086. try {
  3087. let filter_json = ungzip(rule.filter.trim());
  3088. rule.filter = JSON.parse(filter_json);
  3089. } catch (e) {
  3090. rule.filter = {};
  3091. }
  3092. }
  3093. let homeObj = {
  3094. filter: rule.filter || false,
  3095. MY_URL: rule.homeUrl,
  3096. class_name: rule.class_name || '',
  3097. class_url: rule.class_url || '',
  3098. class_parse: rule.class_parse || '',
  3099. cate_exclude: rule.cate_exclude,
  3100. };
  3101. return homeParse(homeObj);
  3102. }
  3103. /**
  3104. * js源获取首页推荐数据列表特定返回对象中的函数
  3105. * @param params
  3106. * @returns {string}
  3107. */
  3108. function homeVod(params) {
  3109. console.log("homeVod");
  3110. let homeVodObj = {
  3111. 推荐: rule.推荐,
  3112. double: rule.double,
  3113. homeUrl: rule.homeUrl,
  3114. detailUrl: rule.detailUrl
  3115. };
  3116. return homeVodParse(homeVodObj)
  3117. // return "{}";
  3118. }
  3119. /**
  3120. * js源获取分类页一级数据列表特定返回对象中的函数
  3121. * @param tid 分类id
  3122. * @param pg 页数
  3123. * @param filter 当前选中的筛选条件
  3124. * @param extend 扩展
  3125. * @returns {string}
  3126. */
  3127. function category(tid, pg, filter, extend) {
  3128. let cateObj = {
  3129. url: rule.url,
  3130. 一级: rule.一级,
  3131. tid: tid,
  3132. pg: parseInt(pg),
  3133. filter: filter,
  3134. extend: extend
  3135. };
  3136. // console.log(JSON.stringify(extend));
  3137. return categoryParse(cateObj)
  3138. }
  3139. /**
  3140. * js源获取二级详情页数据特定返回对象中的函数
  3141. * @param vod_url 一级列表中的vod_id或者是带分类的自拼接 vod_id 如 fyclass$vod_id
  3142. * @returns {string}
  3143. */
  3144. function detail(vod_url) {
  3145. let orId = vod_url;
  3146. let fyclass = '';
  3147. log('orId:' + orId);
  3148. if (vod_url.indexOf('$') > -1) {
  3149. let tmp = vod_url.split('$');
  3150. fyclass = tmp[0];
  3151. vod_url = tmp[1];
  3152. }
  3153. let detailUrl = vod_url.split('@@')[0];
  3154. let url;
  3155. if (!detailUrl.startsWith('http') && !detailUrl.includes('/')) {
  3156. url = rule.detailUrl.replaceAll('fyid', detailUrl).replaceAll('fyclass', fyclass);
  3157. } else if (detailUrl.includes('/')) {
  3158. url = urljoin(rule.homeUrl, detailUrl);
  3159. } else {
  3160. url = detailUrl
  3161. }
  3162. let detailObj = {
  3163. orId: orId,
  3164. url: url,
  3165. 二级: rule.二级,
  3166. 二级访问前: rule.二级访问前,
  3167. detailUrl: detailUrl,
  3168. fyclass: fyclass,
  3169. tab_exclude: rule.tab_exclude,
  3170. }
  3171. return detailParse(detailObj)
  3172. }
  3173. /**
  3174. * js源选集按钮播放点击事件特定返回对象中的函数
  3175. * @param flag 线路名
  3176. * @param id 播放按钮的链接
  3177. * @param flags 全局配置的flags是否需要解析的标识列表
  3178. * @returns {string}
  3179. */
  3180. function play(flag, id, flags) {
  3181. let playObj = {
  3182. url: id,
  3183. flag: flag,
  3184. flags: flags
  3185. }
  3186. return playParse(playObj);
  3187. }
  3188. /**
  3189. * js源搜索返回的数据列表特定返回对象中的函数
  3190. * @param wd 搜索关键字
  3191. * @param quick 是否来自快速搜索
  3192. * @returns {string}
  3193. */
  3194. function search(wd, quick, pg) {
  3195. if (rule.search_encoding) {
  3196. if (rule.search_encoding.toLowerCase() !== 'utf-8') {
  3197. // 按搜索编码进行编码
  3198. wd = encodeStr(wd, rule.search_encoding);
  3199. }
  3200. } else if (rule.encoding && rule.encoding.toLowerCase() !== 'utf-8') {
  3201. // 按全局编码进行编码
  3202. wd = encodeStr(wd, rule.encoding);
  3203. }
  3204. let searchObj = {
  3205. searchUrl: rule.searchUrl,
  3206. 搜索: rule.搜索,
  3207. wd: wd,
  3208. //pg: pg,
  3209. pg: pg || 1,
  3210. quick: quick,
  3211. };
  3212. // console.log(JSON.stringify(searchObj));
  3213. return searchParse(searchObj)
  3214. }
  3215. /**
  3216. * js源本地代理返回的数据列表特定返回对象中的函数
  3217. * @param params 代理链接参数比如 /proxy?do=js&url=https://wwww.baidu.com => params就是 {do:'js','url':'https://wwww.baidu.com'}
  3218. * @returns {*}
  3219. */
  3220. function proxy(params) {
  3221. if (rule.proxy_rule && rule.proxy_rule.trim()) {
  3222. rule.proxy_rule = rule.proxy_rule.trim();
  3223. }
  3224. if (rule.proxy_rule.startsWith('js:')) {
  3225. rule.proxy_rule = rule.proxy_rule.replace('js:', '');
  3226. }
  3227. let proxyObj = {
  3228. params: params,
  3229. proxy_rule: rule.proxy_rule
  3230. };
  3231. return proxyParse(proxyObj)
  3232. }
  3233. /**
  3234. * 是否启用辅助嗅探功能,启用后可以根据isVideo函数进行手动识别为视频的链接地址。默认为false
  3235. * @returns {*|boolean|boolean}
  3236. */
  3237. function sniffer() {
  3238. let enable_sniffer = rule.sniffer || false;
  3239. if (enable_sniffer) {
  3240. // log('准备执行辅助嗅探代理规则:\n'+rule.isVideo);
  3241. log('开始执行辅助嗅探代理规则...');
  3242. }
  3243. return enable_sniffer
  3244. }
  3245. /**
  3246. * 启用辅助嗅探功能后根据次函数返回的值识别地址是否为视频,返回true/false
  3247. * @param url
  3248. */
  3249. function isVideo(url) {
  3250. let t = 0;
  3251. let is_video;
  3252. if (rule.isVideo && rule.isVideo.trim()) {
  3253. is_video = rule.isVideo.trim();
  3254. }
  3255. if (is_video.startsWith('js:')) {
  3256. is_video = is_video.replace('js:', '');
  3257. t = 1;
  3258. }
  3259. let isVideoObj = {
  3260. url: url,
  3261. isVideo: is_video,
  3262. t: t,
  3263. };
  3264. let result = isVideoParse(isVideoObj);
  3265. if (result) {
  3266. log('成功执行辅助嗅探规则并检测到视频地址:\n' + rule.isVideo);
  3267. }
  3268. return result
  3269. }
  3270. /**
  3271. * 获取规则
  3272. * @returns {{}}
  3273. */
  3274. function getRule(key) {
  3275. return key ? rule[key] || '' : rule
  3276. }
  3277. function DRPY() {//导出函数
  3278. return {
  3279. runMain: runMain,
  3280. getRule: getRule,
  3281. init: init,
  3282. home: home,
  3283. homeVod: homeVod,
  3284. category: category,
  3285. detail: detail,
  3286. play: play,
  3287. search: search,
  3288. proxy: proxy,
  3289. sniffer: sniffer,
  3290. isVideo: isVideo,
  3291. fixAdM3u8Ai: fixAdM3u8Ai,
  3292. }
  3293. }
  3294. /**
  3295. * 导出函数无法简写成下面的形式:
  3296. export default {
  3297. ...DRPY,
  3298. DRPY
  3299. }
  3300. */
  3301. // 导出函数对象
  3302. export default {
  3303. runMain,
  3304. getRule,
  3305. init,
  3306. home,
  3307. homeVod,
  3308. category,
  3309. detail,
  3310. play,
  3311. search,
  3312. proxy,
  3313. sniffer,
  3314. isVideo,
  3315. fixAdM3u8Ai,
  3316. DRPY,
  3317. }