drpy2.js 152 KB

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