drpy2.min.js 106 KB

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