drpy2.min.js 102 KB

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