drpy2.min.js 108 KB

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