drpy2.js 154 KB

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