drpy2.js 151 KB

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