drpy2.js 156 KB

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