drpy2.js 157 KB

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