drpy2.min.js 99 KB

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