drpy2.js.bak 151 KB

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