drpy2.min.js 104 KB

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