react-native-consumet 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/android/src/androidTest/java/com/consumet/TestSupport.kt +12 -6
  2. package/android/src/androidTest/java/com/consumet/WebViewContractTest.kt +30 -2
  3. package/android/src/main/java/com/consumet/HttpRequestModule.kt +27 -13
  4. package/ios/Consumet.mm +42 -19
  5. package/lib/commonjs/NativeConsumet.ts +13 -8
  6. package/lib/commonjs/extension-registry.json +33 -62
  7. package/lib/commonjs/extension-registry.json.sig +1 -1
  8. package/lib/commonjs/extractors/gofile.js +47 -10
  9. package/lib/commonjs/extractors/gofile.js.map +1 -1
  10. package/lib/commonjs/extractors/hubcloud.js +49 -42
  11. package/lib/commonjs/extractors/hubcloud.js.map +1 -1
  12. package/lib/commonjs/index.js +14 -0
  13. package/lib/commonjs/index.js.map +1 -1
  14. package/lib/commonjs/models/index.js +9 -1
  15. package/lib/commonjs/models/index.js.map +1 -1
  16. package/lib/commonjs/models/meta-error.js +6 -3
  17. package/lib/commonjs/models/meta-error.js.map +1 -1
  18. package/lib/commonjs/models/provider-error.js +54 -0
  19. package/lib/commonjs/models/provider-error.js.map +1 -0
  20. package/lib/commonjs/models/types.js.map +1 -1
  21. package/lib/commonjs/providers/anime/anikoto/create-anikoto.js +88 -23
  22. package/lib/commonjs/providers/anime/anikoto/create-anikoto.js.map +1 -1
  23. package/lib/commonjs/providers/anime/{hianime.js → anikoto/hianime.js} +4 -4
  24. package/lib/commonjs/providers/anime/anikoto/hianime.js.map +1 -0
  25. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js +110 -18
  26. package/lib/commonjs/providers/anime/animepahe/create-animepahe.js.map +1 -1
  27. package/lib/commonjs/providers/anime/index.js +1 -9
  28. package/lib/commonjs/providers/anime/index.js.map +1 -1
  29. package/lib/commonjs/providers/anime/reanime/create-reanime.js +6 -2
  30. package/lib/commonjs/providers/anime/reanime/create-reanime.js.map +1 -1
  31. package/lib/commonjs/providers/common/concurrency.js +38 -0
  32. package/lib/commonjs/providers/common/concurrency.js.map +1 -0
  33. package/lib/commonjs/providers/common/errors.js +77 -0
  34. package/lib/commonjs/providers/common/errors.js.map +1 -0
  35. package/lib/commonjs/providers/common/servers.js +9 -3
  36. package/lib/commonjs/providers/common/servers.js.map +1 -1
  37. package/lib/commonjs/providers/common/ttl-cache.js +59 -0
  38. package/lib/commonjs/providers/common/ttl-cache.js.map +1 -0
  39. package/lib/commonjs/providers/manga/asurascans.js +29 -7
  40. package/lib/commonjs/providers/manga/asurascans.js.map +1 -1
  41. package/lib/commonjs/providers/meta/anilist-media.js +23 -13
  42. package/lib/commonjs/providers/meta/anilist-media.js.map +1 -1
  43. package/lib/commonjs/providers/meta/anilist.js +25 -14
  44. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  45. package/lib/commonjs/providers/meta/mal.js +3 -3
  46. package/lib/commonjs/providers/meta/mal.js.map +1 -1
  47. package/lib/commonjs/providers/meta/shared.js +7 -2
  48. package/lib/commonjs/providers/meta/shared.js.map +1 -1
  49. package/lib/commonjs/providers/meta/tmdb.js +151 -45
  50. package/lib/commonjs/providers/meta/tmdb.js.map +1 -1
  51. package/lib/commonjs/providers/movies/index.js +0 -4
  52. package/lib/commonjs/providers/movies/index.js.map +1 -1
  53. package/lib/commonjs/providers/movies/multimovies/create-multimovies.js +2 -1
  54. package/lib/commonjs/providers/movies/multimovies/create-multimovies.js.map +1 -1
  55. package/lib/commonjs/providers/movies/multistream/create-multistream.js +1 -1
  56. package/lib/commonjs/providers/movies/multistream/create-multistream.js.map +1 -1
  57. package/lib/commonjs/providers/movies/netflixmirror/create-netflixmirror.js +44 -11
  58. package/lib/commonjs/providers/movies/netflixmirror/create-netflixmirror.js.map +1 -1
  59. package/lib/commonjs/providers/movies/site-paths.js +3 -2
  60. package/lib/commonjs/providers/movies/site-paths.js.map +1 -1
  61. package/lib/commonjs/providers/movies/vegamovies/create-vegamovies.js +95 -44
  62. package/lib/commonjs/providers/movies/vegamovies/create-vegamovies.js.map +1 -1
  63. package/lib/commonjs/providers/provider-class.js +1 -1
  64. package/lib/commonjs/utils/ExtractorManager.js +90 -11
  65. package/lib/commonjs/utils/ExtractorManager.js.map +1 -1
  66. package/lib/commonjs/utils/ProviderManager.js +54 -18
  67. package/lib/commonjs/utils/ProviderManager.js.map +1 -1
  68. package/lib/commonjs/utils/extension-modules.js +136 -24
  69. package/lib/commonjs/utils/extension-modules.js.map +1 -1
  70. package/lib/commonjs/utils/registry-schema.js +3 -2
  71. package/lib/commonjs/utils/registry-schema.js.map +1 -1
  72. package/lib/commonjs/utils/tmdb.js +53 -8
  73. package/lib/commonjs/utils/tmdb.js.map +1 -1
  74. package/lib/module/NativeConsumet.ts +13 -8
  75. package/lib/module/extension-registry.json +33 -62
  76. package/lib/module/extension-registry.json.sig +1 -1
  77. package/lib/module/extractors/gofile.js +47 -10
  78. package/lib/module/extractors/gofile.js.map +1 -1
  79. package/lib/module/extractors/hubcloud.js +49 -42
  80. package/lib/module/extractors/hubcloud.js.map +1 -1
  81. package/lib/module/index.js +2 -2
  82. package/lib/module/index.js.map +1 -1
  83. package/lib/module/models/index.js +1 -0
  84. package/lib/module/models/index.js.map +1 -1
  85. package/lib/module/models/meta-error.js +7 -3
  86. package/lib/module/models/meta-error.js.map +1 -1
  87. package/lib/module/models/provider-error.js +49 -0
  88. package/lib/module/models/provider-error.js.map +1 -0
  89. package/lib/module/models/types.js.map +1 -1
  90. package/lib/module/providers/anime/anikoto/create-anikoto.js +89 -23
  91. package/lib/module/providers/anime/anikoto/create-anikoto.js.map +1 -1
  92. package/lib/module/providers/anime/{hianime.js → anikoto/hianime.js} +4 -4
  93. package/lib/module/providers/anime/anikoto/hianime.js.map +1 -0
  94. package/lib/module/providers/anime/animepahe/create-animepahe.js +111 -18
  95. package/lib/module/providers/anime/animepahe/create-animepahe.js.map +1 -1
  96. package/lib/module/providers/anime/index.js +1 -9
  97. package/lib/module/providers/anime/index.js.map +1 -1
  98. package/lib/module/providers/anime/reanime/create-reanime.js +6 -2
  99. package/lib/module/providers/anime/reanime/create-reanime.js.map +1 -1
  100. package/lib/module/providers/common/concurrency.js +34 -0
  101. package/lib/module/providers/common/concurrency.js.map +1 -0
  102. package/lib/module/providers/common/errors.js +70 -0
  103. package/lib/module/providers/common/errors.js.map +1 -0
  104. package/lib/module/providers/common/servers.js +10 -3
  105. package/lib/module/providers/common/servers.js.map +1 -1
  106. package/lib/module/providers/common/ttl-cache.js +54 -0
  107. package/lib/module/providers/common/ttl-cache.js.map +1 -0
  108. package/lib/module/providers/manga/asurascans.js +29 -7
  109. package/lib/module/providers/manga/asurascans.js.map +1 -1
  110. package/lib/module/providers/meta/anilist-media.js +23 -13
  111. package/lib/module/providers/meta/anilist-media.js.map +1 -1
  112. package/lib/module/providers/meta/anilist.js +26 -15
  113. package/lib/module/providers/meta/anilist.js.map +1 -1
  114. package/lib/module/providers/meta/mal.js +3 -3
  115. package/lib/module/providers/meta/mal.js.map +1 -1
  116. package/lib/module/providers/meta/shared.js +8 -3
  117. package/lib/module/providers/meta/shared.js.map +1 -1
  118. package/lib/module/providers/meta/tmdb.js +153 -47
  119. package/lib/module/providers/meta/tmdb.js.map +1 -1
  120. package/lib/module/providers/movies/index.js +0 -4
  121. package/lib/module/providers/movies/index.js.map +1 -1
  122. package/lib/module/providers/movies/multimovies/create-multimovies.js +2 -1
  123. package/lib/module/providers/movies/multimovies/create-multimovies.js.map +1 -1
  124. package/lib/module/providers/movies/multistream/create-multistream.js +1 -1
  125. package/lib/module/providers/movies/multistream/create-multistream.js.map +1 -1
  126. package/lib/module/providers/movies/netflixmirror/create-netflixmirror.js +44 -11
  127. package/lib/module/providers/movies/netflixmirror/create-netflixmirror.js.map +1 -1
  128. package/lib/module/providers/movies/site-paths.js +3 -2
  129. package/lib/module/providers/movies/site-paths.js.map +1 -1
  130. package/lib/module/providers/movies/vegamovies/create-vegamovies.js +95 -44
  131. package/lib/module/providers/movies/vegamovies/create-vegamovies.js.map +1 -1
  132. package/lib/module/providers/provider-class.js +1 -1
  133. package/lib/module/utils/ExtractorManager.js +89 -11
  134. package/lib/module/utils/ExtractorManager.js.map +1 -1
  135. package/lib/module/utils/ProviderManager.js +54 -18
  136. package/lib/module/utils/ProviderManager.js.map +1 -1
  137. package/lib/module/utils/extension-modules.js +136 -24
  138. package/lib/module/utils/extension-modules.js.map +1 -1
  139. package/lib/module/utils/registry-schema.js +3 -2
  140. package/lib/module/utils/registry-schema.js.map +1 -1
  141. package/lib/module/utils/tmdb.js +51 -7
  142. package/lib/module/utils/tmdb.js.map +1 -1
  143. package/lib/typescript/commonjs/src/NativeConsumet.d.ts +13 -8
  144. package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
  145. package/lib/typescript/commonjs/src/extractors/gofile.d.ts.map +1 -1
  146. package/lib/typescript/commonjs/src/extractors/hubcloud.d.ts.map +1 -1
  147. package/lib/typescript/commonjs/src/index.d.ts +4 -3
  148. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  149. package/lib/typescript/commonjs/src/models/extension-manifest.d.ts +2 -0
  150. package/lib/typescript/commonjs/src/models/extension-manifest.d.ts.map +1 -1
  151. package/lib/typescript/commonjs/src/models/index.d.ts +1 -0
  152. package/lib/typescript/commonjs/src/models/index.d.ts.map +1 -1
  153. package/lib/typescript/commonjs/src/models/meta-error.d.ts +4 -1
  154. package/lib/typescript/commonjs/src/models/meta-error.d.ts.map +1 -1
  155. package/lib/typescript/commonjs/src/models/provider-error.d.ts +32 -0
  156. package/lib/typescript/commonjs/src/models/provider-error.d.ts.map +1 -0
  157. package/lib/typescript/commonjs/src/models/types.d.ts +27 -0
  158. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  159. package/lib/typescript/commonjs/src/providers/anime/anikoto/create-anikoto.d.ts.map +1 -1
  160. package/lib/typescript/{module/src/providers/anime → commonjs/src/providers/anime/anikoto}/hianime.d.ts +2 -2
  161. package/lib/typescript/commonjs/src/providers/anime/anikoto/hianime.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  163. package/lib/typescript/commonjs/src/providers/anime/index.d.ts +0 -6
  164. package/lib/typescript/commonjs/src/providers/anime/index.d.ts.map +1 -1
  165. package/lib/typescript/commonjs/src/providers/anime/reanime/create-reanime.d.ts.map +1 -1
  166. package/lib/typescript/commonjs/src/providers/common/concurrency.d.ts +8 -0
  167. package/lib/typescript/commonjs/src/providers/common/concurrency.d.ts.map +1 -0
  168. package/lib/typescript/commonjs/src/providers/common/errors.d.ts +36 -0
  169. package/lib/typescript/commonjs/src/providers/common/errors.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/src/providers/common/servers.d.ts +2 -1
  171. package/lib/typescript/commonjs/src/providers/common/servers.d.ts.map +1 -1
  172. package/lib/typescript/commonjs/src/providers/common/ttl-cache.d.ts +21 -0
  173. package/lib/typescript/commonjs/src/providers/common/ttl-cache.d.ts.map +1 -0
  174. package/lib/typescript/commonjs/src/providers/manga/asurascans.d.ts.map +1 -1
  175. package/lib/typescript/commonjs/src/providers/meta/anilist-media.d.ts +19 -7
  176. package/lib/typescript/commonjs/src/providers/meta/anilist-media.d.ts.map +1 -1
  177. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts +14 -7
  178. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  179. package/lib/typescript/commonjs/src/providers/meta/mal.d.ts +1 -1
  180. package/lib/typescript/commonjs/src/providers/meta/shared.d.ts +4 -1
  181. package/lib/typescript/commonjs/src/providers/meta/shared.d.ts.map +1 -1
  182. package/lib/typescript/commonjs/src/providers/meta/tmdb.d.ts +65 -6
  183. package/lib/typescript/commonjs/src/providers/meta/tmdb.d.ts.map +1 -1
  184. package/lib/typescript/commonjs/src/providers/movies/index.d.ts +0 -3
  185. package/lib/typescript/commonjs/src/providers/movies/index.d.ts.map +1 -1
  186. package/lib/typescript/commonjs/src/providers/movies/multimovies/create-multimovies.d.ts.map +1 -1
  187. package/lib/typescript/commonjs/src/providers/movies/netflixmirror/create-netflixmirror.d.ts.map +1 -1
  188. package/lib/typescript/commonjs/src/providers/movies/site-paths.d.ts +3 -2
  189. package/lib/typescript/commonjs/src/providers/movies/site-paths.d.ts.map +1 -1
  190. package/lib/typescript/commonjs/src/providers/movies/vegamovies/create-vegamovies.d.ts.map +1 -1
  191. package/lib/typescript/commonjs/src/providers/provider-class.d.ts +1 -1
  192. package/lib/typescript/commonjs/src/utils/ExtractorManager.d.ts +29 -1
  193. package/lib/typescript/commonjs/src/utils/ExtractorManager.d.ts.map +1 -1
  194. package/lib/typescript/commonjs/src/utils/ProviderManager.d.ts +19 -5
  195. package/lib/typescript/commonjs/src/utils/ProviderManager.d.ts.map +1 -1
  196. package/lib/typescript/commonjs/src/utils/extension-modules.d.ts +33 -8
  197. package/lib/typescript/commonjs/src/utils/extension-modules.d.ts.map +1 -1
  198. package/lib/typescript/commonjs/src/utils/registry-schema.d.ts +1 -1
  199. package/lib/typescript/commonjs/src/utils/registry-schema.d.ts.map +1 -1
  200. package/lib/typescript/commonjs/src/utils/tmdb.d.ts +18 -3
  201. package/lib/typescript/commonjs/src/utils/tmdb.d.ts.map +1 -1
  202. package/lib/typescript/module/src/NativeConsumet.d.ts +13 -8
  203. package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
  204. package/lib/typescript/module/src/extractors/gofile.d.ts.map +1 -1
  205. package/lib/typescript/module/src/extractors/hubcloud.d.ts.map +1 -1
  206. package/lib/typescript/module/src/index.d.ts +4 -3
  207. package/lib/typescript/module/src/index.d.ts.map +1 -1
  208. package/lib/typescript/module/src/models/extension-manifest.d.ts +2 -0
  209. package/lib/typescript/module/src/models/extension-manifest.d.ts.map +1 -1
  210. package/lib/typescript/module/src/models/index.d.ts +1 -0
  211. package/lib/typescript/module/src/models/index.d.ts.map +1 -1
  212. package/lib/typescript/module/src/models/meta-error.d.ts +4 -1
  213. package/lib/typescript/module/src/models/meta-error.d.ts.map +1 -1
  214. package/lib/typescript/module/src/models/provider-error.d.ts +32 -0
  215. package/lib/typescript/module/src/models/provider-error.d.ts.map +1 -0
  216. package/lib/typescript/module/src/models/types.d.ts +27 -0
  217. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  218. package/lib/typescript/module/src/providers/anime/anikoto/create-anikoto.d.ts.map +1 -1
  219. package/lib/typescript/{commonjs/src/providers/anime → module/src/providers/anime/anikoto}/hianime.d.ts +2 -2
  220. package/lib/typescript/module/src/providers/anime/anikoto/hianime.d.ts.map +1 -0
  221. package/lib/typescript/module/src/providers/anime/animepahe/create-animepahe.d.ts.map +1 -1
  222. package/lib/typescript/module/src/providers/anime/index.d.ts +0 -6
  223. package/lib/typescript/module/src/providers/anime/index.d.ts.map +1 -1
  224. package/lib/typescript/module/src/providers/anime/reanime/create-reanime.d.ts.map +1 -1
  225. package/lib/typescript/module/src/providers/common/concurrency.d.ts +8 -0
  226. package/lib/typescript/module/src/providers/common/concurrency.d.ts.map +1 -0
  227. package/lib/typescript/module/src/providers/common/errors.d.ts +36 -0
  228. package/lib/typescript/module/src/providers/common/errors.d.ts.map +1 -0
  229. package/lib/typescript/module/src/providers/common/servers.d.ts +2 -1
  230. package/lib/typescript/module/src/providers/common/servers.d.ts.map +1 -1
  231. package/lib/typescript/module/src/providers/common/ttl-cache.d.ts +21 -0
  232. package/lib/typescript/module/src/providers/common/ttl-cache.d.ts.map +1 -0
  233. package/lib/typescript/module/src/providers/manga/asurascans.d.ts.map +1 -1
  234. package/lib/typescript/module/src/providers/meta/anilist-media.d.ts +19 -7
  235. package/lib/typescript/module/src/providers/meta/anilist-media.d.ts.map +1 -1
  236. package/lib/typescript/module/src/providers/meta/anilist.d.ts +14 -7
  237. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  238. package/lib/typescript/module/src/providers/meta/mal.d.ts +1 -1
  239. package/lib/typescript/module/src/providers/meta/shared.d.ts +4 -1
  240. package/lib/typescript/module/src/providers/meta/shared.d.ts.map +1 -1
  241. package/lib/typescript/module/src/providers/meta/tmdb.d.ts +65 -6
  242. package/lib/typescript/module/src/providers/meta/tmdb.d.ts.map +1 -1
  243. package/lib/typescript/module/src/providers/movies/index.d.ts +0 -3
  244. package/lib/typescript/module/src/providers/movies/index.d.ts.map +1 -1
  245. package/lib/typescript/module/src/providers/movies/multimovies/create-multimovies.d.ts.map +1 -1
  246. package/lib/typescript/module/src/providers/movies/netflixmirror/create-netflixmirror.d.ts.map +1 -1
  247. package/lib/typescript/module/src/providers/movies/site-paths.d.ts +3 -2
  248. package/lib/typescript/module/src/providers/movies/site-paths.d.ts.map +1 -1
  249. package/lib/typescript/module/src/providers/movies/vegamovies/create-vegamovies.d.ts.map +1 -1
  250. package/lib/typescript/module/src/providers/provider-class.d.ts +1 -1
  251. package/lib/typescript/module/src/utils/ExtractorManager.d.ts +29 -1
  252. package/lib/typescript/module/src/utils/ExtractorManager.d.ts.map +1 -1
  253. package/lib/typescript/module/src/utils/ProviderManager.d.ts +19 -5
  254. package/lib/typescript/module/src/utils/ProviderManager.d.ts.map +1 -1
  255. package/lib/typescript/module/src/utils/extension-modules.d.ts +33 -8
  256. package/lib/typescript/module/src/utils/extension-modules.d.ts.map +1 -1
  257. package/lib/typescript/module/src/utils/registry-schema.d.ts +1 -1
  258. package/lib/typescript/module/src/utils/registry-schema.d.ts.map +1 -1
  259. package/lib/typescript/module/src/utils/tmdb.d.ts +18 -3
  260. package/lib/typescript/module/src/utils/tmdb.d.ts.map +1 -1
  261. package/package.json +1 -1
  262. package/src/NativeConsumet.ts +13 -8
  263. package/src/extension-registry.json +33 -62
  264. package/src/extension-registry.json.sig +1 -1
  265. package/src/extractors/gofile.ts +52 -11
  266. package/src/extractors/hubcloud.ts +62 -49
  267. package/src/index.tsx +4 -1
  268. package/src/models/extension-manifest.ts +3 -0
  269. package/src/models/index.ts +1 -0
  270. package/src/models/meta-error.ts +7 -3
  271. package/src/models/provider-error.ts +57 -0
  272. package/src/models/types.ts +23 -0
  273. package/src/providers/anime/anikoto/create-anikoto.ts +73 -25
  274. package/src/providers/anime/{hianime.ts → anikoto/hianime.ts} +5 -5
  275. package/src/providers/anime/animepahe/create-animepahe.ts +101 -19
  276. package/src/providers/anime/index.ts +0 -8
  277. package/src/providers/anime/reanime/create-reanime.ts +8 -1
  278. package/src/providers/common/concurrency.ts +32 -0
  279. package/src/providers/common/errors.ts +84 -0
  280. package/src/providers/common/servers.ts +7 -3
  281. package/src/providers/common/ttl-cache.ts +65 -0
  282. package/src/providers/manga/asurascans.ts +31 -7
  283. package/src/providers/meta/anilist-media.ts +20 -15
  284. package/src/providers/meta/anilist.ts +23 -13
  285. package/src/providers/meta/mal.ts +3 -3
  286. package/src/providers/meta/shared.ts +10 -3
  287. package/src/providers/meta/tmdb.ts +173 -38
  288. package/src/providers/movies/index.ts +0 -4
  289. package/src/providers/movies/multimovies/create-multimovies.ts +1 -0
  290. package/src/providers/movies/multistream/create-multistream.ts +1 -1
  291. package/src/providers/movies/netflixmirror/create-netflixmirror.ts +49 -11
  292. package/src/providers/movies/site-paths.ts +3 -2
  293. package/src/providers/movies/vegamovies/create-vegamovies.ts +93 -42
  294. package/src/providers/provider-class.ts +1 -1
  295. package/src/utils/ExtractorManager.ts +97 -11
  296. package/src/utils/ProviderManager.ts +74 -22
  297. package/src/utils/extension-modules.ts +145 -32
  298. package/src/utils/registry-schema.ts +2 -1
  299. package/src/utils/tmdb.ts +53 -7
  300. package/lib/commonjs/providers/anime/anineko/anineko.js +0 -11
  301. package/lib/commonjs/providers/anime/anineko/anineko.js.map +0 -1
  302. package/lib/commonjs/providers/anime/anineko/create-anineko.js +0 -358
  303. package/lib/commonjs/providers/anime/anineko/create-anineko.js.map +0 -1
  304. package/lib/commonjs/providers/anime/hianime.js.map +0 -1
  305. package/lib/commonjs/providers/anime/zoro/create-zoro.js +0 -362
  306. package/lib/commonjs/providers/anime/zoro/create-zoro.js.map +0 -1
  307. package/lib/commonjs/providers/anime/zoro/zoro.js +0 -11
  308. package/lib/commonjs/providers/anime/zoro/zoro.js.map +0 -1
  309. package/lib/commonjs/providers/movies/himovies/create-himovies.js +0 -231
  310. package/lib/commonjs/providers/movies/himovies/create-himovies.js.map +0 -1
  311. package/lib/commonjs/providers/movies/himovies/himovies.js +0 -11
  312. package/lib/commonjs/providers/movies/himovies/himovies.js.map +0 -1
  313. package/lib/module/providers/anime/anineko/anineko.js +0 -7
  314. package/lib/module/providers/anime/anineko/anineko.js.map +0 -1
  315. package/lib/module/providers/anime/anineko/create-anineko.js +0 -354
  316. package/lib/module/providers/anime/anineko/create-anineko.js.map +0 -1
  317. package/lib/module/providers/anime/hianime.js.map +0 -1
  318. package/lib/module/providers/anime/zoro/create-zoro.js +0 -358
  319. package/lib/module/providers/anime/zoro/create-zoro.js.map +0 -1
  320. package/lib/module/providers/anime/zoro/zoro.js +0 -7
  321. package/lib/module/providers/anime/zoro/zoro.js.map +0 -1
  322. package/lib/module/providers/movies/himovies/create-himovies.js +0 -227
  323. package/lib/module/providers/movies/himovies/create-himovies.js.map +0 -1
  324. package/lib/module/providers/movies/himovies/himovies.js +0 -7
  325. package/lib/module/providers/movies/himovies/himovies.js.map +0 -1
  326. package/lib/typescript/commonjs/src/providers/anime/anineko/anineko.d.ts +0 -5
  327. package/lib/typescript/commonjs/src/providers/anime/anineko/anineko.d.ts.map +0 -1
  328. package/lib/typescript/commonjs/src/providers/anime/anineko/create-anineko.d.ts +0 -52
  329. package/lib/typescript/commonjs/src/providers/anime/anineko/create-anineko.d.ts.map +0 -1
  330. package/lib/typescript/commonjs/src/providers/anime/hianime.d.ts.map +0 -1
  331. package/lib/typescript/commonjs/src/providers/anime/zoro/create-zoro.d.ts +0 -49
  332. package/lib/typescript/commonjs/src/providers/anime/zoro/create-zoro.d.ts.map +0 -1
  333. package/lib/typescript/commonjs/src/providers/anime/zoro/zoro.d.ts +0 -5
  334. package/lib/typescript/commonjs/src/providers/anime/zoro/zoro.d.ts.map +0 -1
  335. package/lib/typescript/commonjs/src/providers/movies/himovies/create-himovies.d.ts +0 -28
  336. package/lib/typescript/commonjs/src/providers/movies/himovies/create-himovies.d.ts.map +0 -1
  337. package/lib/typescript/commonjs/src/providers/movies/himovies/himovies.d.ts +0 -5
  338. package/lib/typescript/commonjs/src/providers/movies/himovies/himovies.d.ts.map +0 -1
  339. package/lib/typescript/module/src/providers/anime/anineko/anineko.d.ts +0 -5
  340. package/lib/typescript/module/src/providers/anime/anineko/anineko.d.ts.map +0 -1
  341. package/lib/typescript/module/src/providers/anime/anineko/create-anineko.d.ts +0 -52
  342. package/lib/typescript/module/src/providers/anime/anineko/create-anineko.d.ts.map +0 -1
  343. package/lib/typescript/module/src/providers/anime/hianime.d.ts.map +0 -1
  344. package/lib/typescript/module/src/providers/anime/zoro/create-zoro.d.ts +0 -49
  345. package/lib/typescript/module/src/providers/anime/zoro/create-zoro.d.ts.map +0 -1
  346. package/lib/typescript/module/src/providers/anime/zoro/zoro.d.ts +0 -5
  347. package/lib/typescript/module/src/providers/anime/zoro/zoro.d.ts.map +0 -1
  348. package/lib/typescript/module/src/providers/movies/himovies/create-himovies.d.ts +0 -28
  349. package/lib/typescript/module/src/providers/movies/himovies/create-himovies.d.ts.map +0 -1
  350. package/lib/typescript/module/src/providers/movies/himovies/himovies.d.ts +0 -5
  351. package/lib/typescript/module/src/providers/movies/himovies/himovies.d.ts.map +0 -1
  352. package/src/providers/anime/anineko/anineko.ts +0 -6
  353. package/src/providers/anime/anineko/create-anineko.ts +0 -394
  354. package/src/providers/anime/zoro/create-zoro.ts +0 -398
  355. package/src/providers/anime/zoro/zoro.ts +0 -6
  356. package/src/providers/movies/himovies/create-himovies.ts +0 -252
  357. package/src/providers/movies/himovies/himovies.ts +0 -6
@@ -12,10 +12,67 @@ import {
12
12
  type IAnimeEpisode,
13
13
  type ProviderCapabilities,
14
14
  } from '../../../models';
15
+ import { mapLimit } from '../../common/concurrency';
15
16
  import { toMediaStatus } from '../../common/media-status';
16
17
  import { serverName, serversNamed } from '../../common/servers';
18
+ import { PAGE_TTL_MS, ttlCache } from '../../common/ttl-cache';
17
19
  import { webViewJson } from '../helpers';
18
20
 
21
+ // Kept at the top level, so they outlive one provider instance (apps build one per query).
22
+
23
+ /** Each base URL's challenge load (see ensureChallengePassed). */
24
+ const challenges = new Map<string, Promise<void>>();
25
+
26
+ /**
27
+ * The origins a WebView load came back from, so the WebView holds their Cloudflare clearance, with
28
+ * when the first of those loads came back. Loads to an origin run in parallel only while it is
29
+ * cleared: otherwise they go one at a time, so Cloudflare never has several challenges to solve at
30
+ * once. A clearance doesn't last for ever, so an origin counts as cleared for CLEARANCE_MS; the
31
+ * next load after that goes alone again.
32
+ */
33
+ const CLEARANCE_MS = 15 * 60 * 1000;
34
+ const clearedOrigins = new Map<string, number>();
35
+ const originOf = (url: string): string =>
36
+ (String(url).match(/^[a-z][a-z\d+.-]*:\/\/[^/?#]*/i) || [String(url)])[0]!.toLowerCase();
37
+ const originCleared = (origin: string): boolean => {
38
+ const since = clearedOrigins.get(origin);
39
+ return since !== undefined && Date.now() - since < CLEARANCE_MS;
40
+ };
41
+ const isCleared = (url: string): boolean => originCleared(originOf(url));
42
+ const markCleared = (url: string): void => {
43
+ const origin = originOf(url);
44
+ if (!originCleared(origin)) clearedOrigins.set(origin, Date.now());
45
+ };
46
+
47
+ /**
48
+ * `load` of each item, `limit` at a time, as mapLimit runs them (results in item order, failing as
49
+ * a loop would). On an origin that isn't cleared, the first item loads alone: the others on it wait
50
+ * for that load and start once it worked (it clears the origin), or fail with it.
51
+ */
52
+ function mapCleared<T, R>(items: T[], limit: number, urlOf: (item: T) => string, load: (item: T) => Promise<R>) {
53
+ const firstLoads = new Map<string, Promise<R>>();
54
+ return mapLimit(items, limit, async (item) => {
55
+ const origin = originOf(urlOf(item));
56
+ if (!originCleared(origin)) {
57
+ const first = firstLoads.get(origin);
58
+ if (!first) {
59
+ const loading = load(item);
60
+ firstLoads.set(origin, loading);
61
+ return loading;
62
+ }
63
+ await first;
64
+ }
65
+ return load(item);
66
+ });
67
+ }
68
+
69
+ /** An episode's `/play/` page by URL, so servers, then sources, load it once. */
70
+ const playPages = ttlCache<string>({
71
+ ttlMs: PAGE_TTL_MS,
72
+ maxEntries: 16,
73
+ keep: (html) => html.includes('resolutionMenu'),
74
+ });
75
+
19
76
  export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
20
77
  const { load, extractors, enums, createCustomBaseUrl, PolyURL, NativeConsumet } = ctx;
21
78
  const { Kwik } = extractors;
@@ -39,7 +96,6 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
39
96
  // the hidden WebView, which waits past the challenge. No User-Agent is sent: the WebView keeps
40
97
  // its own, which the cf_clearance cookie it earns is bound to.
41
98
 
42
- let challenge: Promise<void> | undefined;
43
99
  /**
44
100
  * Loads the site once so the WebView holds a clearance before the first API call. Searches
45
101
  * running at once share the one load; a failed load is tried again by the next search. A passed
@@ -47,14 +103,16 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
47
103
  * itself, so an expired clearance only makes that request slower.
48
104
  */
49
105
  const ensureChallengePassed = (): Promise<void> => {
106
+ let challenge = challenges.get(baseUrl);
50
107
  if (!challenge) {
51
108
  challenge = makeGetRequestWithWebView(baseUrl, {}).then(
52
- () => undefined,
109
+ () => markCleared(baseUrl),
53
110
  (err: unknown) => {
54
- challenge = undefined;
111
+ challenges.delete(baseUrl);
55
112
  throw err;
56
113
  }
57
114
  );
115
+ challenges.set(baseUrl, challenge);
58
116
  }
59
117
  return challenge;
60
118
  };
@@ -78,12 +136,16 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
78
136
  if (attempt < 3 && String((err as Error)?.message ?? err).includes('QUIC')) continue;
79
137
  throw err;
80
138
  }
139
+ let parsed: T;
81
140
  try {
82
- return parse(html);
141
+ parsed = parse(html);
83
142
  } catch (err) {
84
143
  if (attempt >= 3) throw err;
85
144
  await new Promise((resolve) => setTimeout(resolve, 800));
145
+ continue;
86
146
  }
147
+ markCleared(url);
148
+ return parsed;
87
149
  }
88
150
  };
89
151
 
@@ -138,7 +200,15 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
138
200
  * pages is the info's `episodePages`.
139
201
  */
140
202
  const fetchAnimeInfo = async (id: string, episodePage: number = -1): Promise<IAnimeInfo> => {
141
- const $ = await webViewPage(`${baseUrl}/anime/${id}`);
203
+ const firstEpisodes = () => fetchEpisodePage(id, episodePage < 0 ? 1 : episodePage);
204
+ // Once the site is cleared, the first page of episodes loads with the anime page; before, after
205
+ // it (see clearedOrigins).
206
+ const together = isCleared(baseUrl);
207
+ const animePage = webViewPage(`${baseUrl}/anime/${id}`);
208
+ const firstLoad = together ? firstEpisodes() : undefined;
209
+ // Its error is thrown below, after the anime page's.
210
+ firstLoad?.catch(() => undefined);
211
+ const $ = await animePage;
142
212
  const animeInfo: IAnimeInfo = { id, title: $('div.title-wrapper > h1 > span').first().text() };
143
213
 
144
214
  animeInfo.image = $('div.anime-poster a').attr('href');
@@ -178,17 +248,19 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
178
248
  .map((el) => ({ ...relatedCard(el), relationType: $(el).find('h4 > span').text().trim() }));
179
249
 
180
250
  animeInfo.episodes = [];
251
+ const firstPage = await (firstLoad || firstEpisodes());
181
252
  if (episodePage < 0) {
182
- const firstPage = await fetchEpisodePage(id, 1);
183
253
  animeInfo.episodePages = firstPage.last_page;
184
254
  animeInfo.episodes.push(...firstPage.data.map((item: any) => mapEpisode(id, item)));
185
- for (let i = 2; i <= firstPage.last_page; i++) {
186
- animeInfo.episodes.push(...(await fetchEpisodePage(id, i)).data.map((item: any) => mapEpisode(id, item)));
187
- }
188
- } else {
189
- animeInfo.episodes.push(
190
- ...(await fetchEpisodePage(id, episodePage)).data.map((item: any) => mapEpisode(id, item))
255
+ // The site is cleared by now: the other pages load three at a time, joined in page order.
256
+ const pages: number[] = [];
257
+ for (let i = 2; i <= firstPage.last_page; i++) pages.push(i);
258
+ const rest = await mapLimit(pages, 3, async (page) =>
259
+ (await fetchEpisodePage(id, page)).data.map((item: any) => mapEpisode(id, item))
191
260
  );
261
+ for (const episodes of rest) animeInfo.episodes.push(...episodes);
262
+ } else {
263
+ animeInfo.episodes.push(...firstPage.data.map((item: any) => mapEpisode(id, item)));
192
264
  }
193
265
 
194
266
  return animeInfo;
@@ -196,13 +268,14 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
196
268
 
197
269
  /** The episode's Kwik players, one per fansub and resolution, with the button's label. */
198
270
  const fetchPlayers = async (episodeId: string, subOrDub: SubOrDub) => {
199
- const $ = await webViewPage(`${baseUrl}/play/${episodeId}`);
271
+ const url = `${baseUrl}/play/${episodeId}`;
272
+ const $ = load(await playPages.get(url, () => webViewGet(url, { Referer: baseUrl }, (html) => html)));
200
273
  const players = $('div#resolutionMenu > button')
201
274
  .toArray()
202
275
  .map((el) => ({
203
276
  name: serverName('kwik', `${$(el).attr('data-fansub')}-${$(el).attr('data-resolution')}`),
204
277
  url: $(el).attr('data-src')!,
205
- label: $(el).text(),
278
+ label: $(el).text().replace(/\s+/g, ' ').trim(),
206
279
  isDub: $(el).attr('data-audio') === 'eng',
207
280
  }))
208
281
  .filter((player) =>
@@ -230,13 +303,22 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
230
303
  const { players, downloads } = await fetchPlayers(episodeId, subOrDub);
231
304
 
232
305
  const iSource: ISource = { sources: [], download: downloads };
233
- for (const player of serversNamed(players, server)) {
306
+ const named = serversNamed(players, server);
307
+ const loadPlayer = async (player: (typeof named)[number]): Promise<Pick<ISource, 'headers' | 'sources'>> => {
234
308
  const res = await Kwik(ctx).extract(new PolyURL(player.url), `${baseUrl}/`);
235
- // Every player is on Kwik, so they all want the same headers.
236
- iSource.headers = res.headers;
309
+ markCleared(player.url);
310
+ const sources: ISource['sources'] = [];
237
311
  for (const source of res.sources) {
238
- iSource.sources.push({ ...source, quality: (player.label.match(/(\d{3,4})p/) || [])[0] });
312
+ sources.push({ ...source, quality: (player.label.match(/(\d{3,4})p/) || [])[0] });
239
313
  }
314
+ return { headers: res.headers, sources };
315
+ };
316
+ // Three at a time, but one alone on Kwik until it is cleared (see clearedOrigins).
317
+ const loaded = await mapCleared(named, 3, (player) => player.url, loadPlayer);
318
+ for (const { headers, sources } of loaded) {
319
+ // Every player is on Kwik, so they all want the same headers.
320
+ iSource.headers = headers;
321
+ iSource.sources.push(...sources);
240
322
  }
241
323
  return iSource;
242
324
  };
@@ -246,7 +328,7 @@ export function createAnimePahe(ctx: ProviderContext, customBaseURL?: string) {
246
328
  subOrDub: SubOrDub = SubOrDubEnum.SUB
247
329
  ): Promise<IEpisodeServer[]> => {
248
330
  const { players } = await fetchPlayers(episodeId, subOrDub);
249
- return players.map(({ name, url }) => ({ name, url }));
331
+ return players.map(({ name, url, label, isDub }) => ({ name, url, label, isDub }));
250
332
  };
251
333
 
252
334
  return {
@@ -1,23 +1,15 @@
1
1
  import { AnimePahe } from './animepahe/animepahe';
2
2
  import { createAnimePahe } from './animepahe/create-animepahe';
3
- import { Zoro } from './zoro/zoro';
4
- import { createZoro } from './zoro/create-zoro';
5
3
  import { AniKoto } from './anikoto/anikoto';
6
4
  import { createAniKoto } from './anikoto/create-anikoto';
7
5
  import { ReAnime } from './reanime/reanime';
8
6
  import { createReanime } from './reanime/create-reanime';
9
- import { AniNeko } from './anineko/anineko';
10
- import { createAniNeko } from './anineko/create-anineko';
11
7
 
12
8
  export const ANIME = {
13
9
  AnimePahe,
14
10
  createAnimePahe,
15
- Zoro,
16
- createZoro,
17
11
  AniKoto,
18
12
  createAniKoto,
19
13
  ReAnime,
20
14
  createReanime,
21
- AniNeko,
22
- createAniNeko,
23
15
  };
@@ -89,7 +89,12 @@ export function createReanime(ctx: ProviderContext, customBaseURL?: string) {
89
89
  seen.add(name);
90
90
  // Only the active server ("bg-primary") has its URL on the page, in the iframe.
91
91
  const url = $(btn).hasClass('bg-primary') ? iframeSrc : '';
92
- servers.push({ name: serverName('flixcloud', name), url });
92
+ servers.push({
93
+ name: serverName('flixcloud', name),
94
+ url,
95
+ label: name,
96
+ isDub: subOrDub === SubOrDubEnum.DUB,
97
+ });
93
98
  });
94
99
  }
95
100
  });
@@ -207,6 +212,8 @@ export function createReanime(ctx: ProviderContext, customBaseURL?: string) {
207
212
  name: serverName('flixcloud', l.serverName),
208
213
  // The site asks FlixCloud for the dub with &a=1.
209
214
  url: isDub ? `${l.dataLink}&a=1` : l.dataLink,
215
+ label: l.serverName,
216
+ isDub,
210
217
  }));
211
218
  }
212
219
 
@@ -0,0 +1,32 @@
1
+ /**
2
+ * `fn` over `items` with at most `limit` calls running at once, results in `items` order. It fails
3
+ * as a sequential loop would: after the first failure no new call starts, the running ones finish,
4
+ * and it rejects with the error of the lowest index that failed (every lower index had already
5
+ * started). No rejection is left unhandled.
6
+ */
7
+ export function mapLimit<T, R>(
8
+ items: readonly T[],
9
+ limit: number,
10
+ fn: (item: T, index: number) => Promise<R>
11
+ ): Promise<R[]> {
12
+ const results: R[] = new Array(items.length);
13
+ const errors: { index: number; error: unknown }[] = [];
14
+ let next = 0;
15
+
16
+ const worker = async (): Promise<void> => {
17
+ while (next < items.length && errors.length === 0) {
18
+ const index = next++;
19
+ try {
20
+ results[index] = await fn(items[index] as T, index);
21
+ } catch (error) {
22
+ errors.push({ index, error });
23
+ }
24
+ }
25
+ };
26
+
27
+ const workers = Math.min(Math.max(1, Math.floor(limit) || 1), items.length);
28
+ return Promise.all(Array.from({ length: workers }, worker)).then(() => {
29
+ if (errors.length) throw errors.reduce((first, e) => (e.index < first.index ? e : first)).error;
30
+ return results;
31
+ });
32
+ }
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Why a provider or extractor failed, so apps can word it and offer the right fix:
3
+ * - `network`: the site couldn't be reached (offline, DNS, a timeout, a gateway error)
4
+ * - `blocked`: the site refused the request (401, 403, 429, 451, or Cloudflare's 503)
5
+ * - `not-found`: the site has no such title, episode, chapter or server
6
+ * - `parse`: the site answered, but not with what the code expects (a changed page or API)
7
+ */
8
+ export type ProviderErrorKind = 'network' | 'blocked' | 'not-found' | 'parse';
9
+
10
+ /** A provider failure as registry bundles throw it: a plain Error with ProviderError's fields. */
11
+ export type TaggedProviderError = Error & {
12
+ name: 'ProviderError';
13
+ kind: ProviderErrorKind;
14
+ provider?: string;
15
+ status?: number;
16
+ cause?: unknown;
17
+ };
18
+
19
+ // axios codes, plus the native WebView request's TIMEOUT
20
+ const NETWORK_CODES = new Set([
21
+ 'ERR_NETWORK',
22
+ 'ECONNABORTED',
23
+ 'ETIMEDOUT',
24
+ 'ECONNRESET',
25
+ 'ECONNREFUSED',
26
+ 'ENOTFOUND',
27
+ 'EAI_AGAIN',
28
+ 'TIMEOUT',
29
+ ]);
30
+ const BLOCKED_STATUSES = new Set([401, 403, 429, 451, 503]);
31
+ const GATEWAY_STATUSES = new Set([502, 504, 520, 521, 522, 523, 524]);
32
+
33
+ /** The HTTP status of a failed request: axios's `response.status`, or a `status` the error carries. */
34
+ export function errorStatus(error: unknown): number | undefined {
35
+ const failure = error as { status?: unknown; response?: { status?: unknown } } | null | undefined;
36
+ const status = failure?.response?.status ?? failure?.status;
37
+ return typeof status === 'number' ? status : undefined;
38
+ }
39
+
40
+ /** Whether `error` is a ProviderError: an instance, or a tagged plain Error from a registry bundle. */
41
+ export function isProviderError(error: unknown): error is TaggedProviderError {
42
+ const failure = error as { name?: unknown; kind?: unknown } | null | undefined;
43
+ return failure?.name === 'ProviderError' && typeof failure.kind === 'string';
44
+ }
45
+
46
+ /**
47
+ * The kind of failure `error` is: its own kind when it is a ProviderError, else read from its HTTP
48
+ * status or network error code, else from its `cause` (a MetaError's). Anything else is `parse`.
49
+ */
50
+ export function errorKind(error: unknown, depth = 0): ProviderErrorKind {
51
+ if (isProviderError(error)) return error.kind;
52
+ const status = errorStatus(error);
53
+ if (status !== undefined) {
54
+ if (status === 404 || status === 410) return 'not-found';
55
+ if (BLOCKED_STATUSES.has(status)) return 'blocked';
56
+ if (GATEWAY_STATUSES.has(status)) return 'network';
57
+ return 'parse';
58
+ }
59
+ const failure = error as { code?: unknown; message?: unknown; cause?: unknown } | null | undefined;
60
+ if (typeof failure?.code === 'string' && NETWORK_CODES.has(failure.code)) return 'network';
61
+ // React Native's fetch rejects with this TypeError when there's no connection
62
+ if (failure?.message === 'Network request failed') return 'network';
63
+ if (failure?.cause !== undefined && depth < 4) return errorKind(failure.cause, depth + 1);
64
+ return 'parse';
65
+ }
66
+
67
+ /**
68
+ * A ProviderError as a plain Error, so registry bundles can throw one without importing anything
69
+ * from the host library (an app on an older library would have no class to construct). Without a
70
+ * `kind`, it is read from `cause` (see errorKind), or is `parse` when there is no cause.
71
+ */
72
+ export function providerError(
73
+ message: string,
74
+ options: { kind?: ProviderErrorKind; provider?: string; cause?: unknown } = {}
75
+ ): TaggedProviderError {
76
+ const { cause, provider } = options;
77
+ return Object.assign(new Error(message), {
78
+ name: 'ProviderError' as const,
79
+ kind: options.kind ?? (cause === undefined ? 'parse' : errorKind(cause)),
80
+ provider,
81
+ status: errorStatus(cause),
82
+ cause,
83
+ });
84
+ }
@@ -1,4 +1,5 @@
1
1
  import type { IEpisodeServer } from '../../models';
2
+ import { providerError } from './errors';
2
3
 
3
4
  /**
4
5
  * The name of an episode server: the name of the extractor (or file host) that reads it, then the
@@ -17,15 +18,18 @@ export function serverName(extractor: string, label: string = ''): string {
17
18
  /**
18
19
  * The servers `server` names: those whose name starts with it, case-insensitively (server names
19
20
  * start with the name of the extractor that reads them, the rule ExtractorManager resolves them
20
- * by). Every server when `server` is omitted. Throws when there is none, or none matches.
21
+ * by). Every server when `server` is omitted. Throws a `not-found` ProviderError when there is none,
22
+ * or none matches.
21
23
  */
22
24
  export function serversNamed<T extends IEpisodeServer>(servers: readonly T[], server?: string): T[] {
23
- if (!servers.length) throw new Error('No servers found for this episode');
25
+ if (!servers.length) throw providerError('No servers found for this episode', { kind: 'not-found' });
24
26
  if (!server) return [...servers];
25
27
  const wanted = server.toLowerCase();
26
28
  const matches = servers.filter((candidate) => candidate.name.toLowerCase().startsWith(wanted));
27
29
  if (!matches.length) {
28
- throw new Error(`Server '${server}' not found; available: ${servers.map((s) => s.name).join(', ')}`);
30
+ throw providerError(`Server '${server}' not found; available: ${servers.map((s) => s.name).join(', ')}`, {
31
+ kind: 'not-found',
32
+ });
29
33
  }
30
34
  return matches;
31
35
  }
@@ -0,0 +1,65 @@
1
+ /** How long a provider keeps a page it loaded, so the next call (servers, then sources) reuses it. */
2
+ export const PAGE_TTL_MS = 5 * 60 * 1000;
3
+
4
+ export interface TtlCacheOptions<V> {
5
+ /** How long a loaded value stays, counted from when its load fulfils. */
6
+ ttlMs: number;
7
+ /** The most entries kept; the least recently used goes first. */
8
+ maxEntries: number;
9
+ /** A value it returns false for is handed back but not kept (e.g. an error page). */
10
+ keep?: (value: V) => boolean;
11
+ now?: () => number;
12
+ }
13
+
14
+ /**
15
+ * Values by key, loaded once: callers asking for the same key share one load, a rejected load is
16
+ * forgotten (the next call tries again), and a value lives `ttlMs`. Keep plain values (HTML text,
17
+ * URLs) and parse them on each call, so no caller can change what another one reads.
18
+ */
19
+ export function ttlCache<V>(options: TtlCacheOptions<V>) {
20
+ const now = options.now || Date.now;
21
+ const entries = new Map<string, { value: Promise<V>; expires: number }>();
22
+
23
+ const evict = () => {
24
+ const time = now();
25
+ entries.forEach((entry, key) => {
26
+ if (entry.expires <= time) entries.delete(key);
27
+ });
28
+ while (entries.size > options.maxEntries) entries.delete(entries.keys().next().value as string);
29
+ };
30
+
31
+ return {
32
+ get(key: string, load: () => Promise<V>): Promise<V> {
33
+ const cached = entries.get(key);
34
+ if (cached && cached.expires > now()) {
35
+ // Most recently used last, so eviction drops the oldest.
36
+ entries.delete(key);
37
+ entries.set(key, cached);
38
+ return cached.value;
39
+ }
40
+ let value: Promise<V>;
41
+ try {
42
+ value = load();
43
+ } catch (error) {
44
+ value = Promise.reject(error);
45
+ }
46
+ const entry = { value, expires: Infinity };
47
+ entries.set(key, entry);
48
+ evict();
49
+ entry.value.then(
50
+ (loaded) => {
51
+ if (entries.get(key) !== entry) return;
52
+ if (options.keep && !options.keep(loaded)) entries.delete(key);
53
+ else entry.expires = now() + options.ttlMs;
54
+ },
55
+ () => {
56
+ if (entries.get(key) === entry) entries.delete(key);
57
+ }
58
+ );
59
+ return entry.value;
60
+ },
61
+ delete(key: string): void {
62
+ entries.delete(key);
63
+ },
64
+ };
65
+ }
@@ -10,6 +10,7 @@ import {
10
10
  import { createProviderContext } from '../../utils/create-provider-context';
11
11
  import { toMediaStatus } from '../common/media-status';
12
12
  import { absoluteUrl, chapterTitle, finishChapters, plainText, toIsoDate } from './shared';
13
+ import { providerError } from '../common/errors';
13
14
 
14
15
  /** The JSON API behind asurascans.com (the site's own pages call it). */
15
16
  const API_URL = 'https://api.asurascans.com/api';
@@ -88,7 +89,11 @@ export class AsuraScans extends MangaParser {
88
89
  ]);
89
90
  // A 200 without the JSON the API normally sends (a challenge or error page) has no series.
90
91
  const series = detail?.series;
91
- if (!series?.slug) throw new Error(`AsuraScans: the API sent no series for "${mangaId}"`);
92
+ if (!series?.slug)
93
+ throw providerError(`AsuraScans: the API sent no series for "${mangaId}"`, {
94
+ kind: 'not-found',
95
+ provider: 'AsuraScans',
96
+ });
92
97
  const seriesUrl = absoluteUrl(series.public_url, this.baseUrl);
93
98
  const genres = (series.genres ?? []).map((genre) => genre.name?.trim()).filter(Boolean);
94
99
  const authors = names(series.author);
@@ -122,20 +127,36 @@ export class AsuraScans extends MangaParser {
122
127
  /** @param chapterId chapter id from `fetchMangaInfo` (`<slug>/chapter/<number>`) */
123
128
  override fetchChapterPages = async (chapterId: string): Promise<IMangaChapterPage[]> => {
124
129
  const match = /^\/?(?:(?:series|comics)\/)?([^/]+)\/chapters?\/([^/?#]+)\/?$/.exec(chapterId);
125
- if (!match) throw new Error(`AsuraScans: invalid chapter id "${chapterId}"`);
130
+ if (!match)
131
+ throw providerError(`AsuraScans: invalid chapter id "${chapterId}"`, {
132
+ kind: 'not-found',
133
+ provider: 'AsuraScans',
134
+ });
126
135
  const [, slug, number] = match;
127
136
  const read = await this.api<{ data?: ApiChapterRead }>(
128
137
  `/series/${encodeURIComponent(slug!)}/chapters/${encodeURIComponent(number!)}`
129
138
  );
130
139
  const data = read?.data;
131
- if (!data) throw new Error(`AsuraScans: the API sent no chapter for "${chapterId}"`);
132
- if (data.access_gate) throw new Error(`AsuraScans: chapter needs ${data.access_gate} on the site`);
140
+ if (!data)
141
+ throw providerError(`AsuraScans: the API sent no chapter for "${chapterId}"`, {
142
+ kind: 'not-found',
143
+ provider: 'AsuraScans',
144
+ });
145
+ if (data.access_gate)
146
+ throw providerError(`AsuraScans: chapter needs ${data.access_gate} on the site`, {
147
+ kind: 'blocked',
148
+ provider: 'AsuraScans',
149
+ });
133
150
  if (data.is_locked) {
134
151
  const until = data.unlock_time ? ` until ${data.unlock_time}` : '';
135
- throw new Error(`AsuraScans: chapter is in early access${until}`);
152
+ throw providerError(`AsuraScans: chapter is in early access${until}`, {
153
+ kind: 'blocked',
154
+ provider: 'AsuraScans',
155
+ });
136
156
  }
137
157
  const pages = (data.chapter?.pages ?? []).filter((page) => page?.url);
138
- if (pages.length === 0) throw new Error('AsuraScans: chapter has no pages');
158
+ if (pages.length === 0)
159
+ throw providerError('AsuraScans: chapter has no pages', { kind: 'not-found', provider: 'AsuraScans' });
139
160
  return pages.map(
140
161
  (page, index): IMangaChapterPage => ({ page: index + 1, img: absoluteUrl(page.url, this.baseUrl)! })
141
162
  );
@@ -149,7 +170,10 @@ export class AsuraScans extends MangaParser {
149
170
  } catch (err) {
150
171
  const response = (err as { response?: { status?: number; data?: { error?: unknown } } }).response;
151
172
  const reason = typeof response?.data?.error === 'string' ? response.data.error : (err as Error).message;
152
- throw new Error(`AsuraScans: ${reason}${response?.status ? ` (${response.status})` : ''}`);
173
+ throw providerError(`AsuraScans: ${reason}${response?.status ? ` (${response.status})` : ''}`, {
174
+ provider: 'AsuraScans',
175
+ cause: err,
176
+ });
153
177
  }
154
178
  }
155
179
 
@@ -13,16 +13,16 @@ const TRAILER = 'trailer { id site thumbnail }';
13
13
  const NAME = 'name { first middle last full native userPreferred }';
14
14
 
15
15
  /** What mapMediaResult reads. */
16
- const RESULT_FIELDS = `id idMal status(version: 2) ${TITLE} bannerImage ${COVER} description genres averageScore format seasonYear`;
16
+ const RESULT_FIELDS = `id idMal status(version: 2) ${TITLE} bannerImage ${COVER} description genres averageScore format season seasonYear duration chapters volumes ${NEXT_AIRING}`;
17
17
  /** What mapBrowseResult reads. */
18
- const BROWSE_FIELDS = `${RESULT_FIELDS} ${TRAILER} episodes ${NEXT_AIRING} duration`;
18
+ const BROWSE_FIELDS = `${RESULT_FIELDS} ${TRAILER} episodes`;
19
19
  /** What mapMediaNode reads. */
20
20
  const NODE_FIELDS = `id idMal ${TITLE} status(version: 2) episodes chapters ${COVER} bannerImage format meanScore`;
21
21
 
22
- export const ADVANCED_SEARCH_QUERY = `query ($page: Int, $id: Int, $type: MediaType, $isAdult: Boolean = false, $search: String, $format: [MediaFormat], $status: MediaStatus, $size: Int, $countryOfOrigin: CountryCode, $source: MediaSource, $season: MediaSeason, $seasonYear: Int, $year: String, $onList: Boolean, $yearLesser: FuzzyDateInt, $yearGreater: FuzzyDateInt, $episodeLesser: Int, $episodeGreater: Int, $durationLesser: Int, $durationGreater: Int, $chapterLesser: Int, $chapterGreater: Int, $volumeLesser: Int, $volumeGreater: Int, $licensedBy: [String], $isLicensed: Boolean, $genres: [String], $excludedGenres: [String], $tags: [String], $excludedTags: [String], $minimumTagRank: Int, $sort: [MediaSort] = [POPULARITY_DESC, SCORE_DESC]) { Page(page: $page, perPage: $size) { ${PAGE_INFO} media(id: $id, type: $type, season: $season, format_in: $format, status: $status, countryOfOrigin: $countryOfOrigin, source: $source, search: $search, onList: $onList, seasonYear: $seasonYear, startDate_like: $year, startDate_lesser: $yearLesser, startDate_greater: $yearGreater, episodes_lesser: $episodeLesser, episodes_greater: $episodeGreater, duration_lesser: $durationLesser, duration_greater: $durationGreater, chapters_lesser: $chapterLesser, chapters_greater: $chapterGreater, volumes_lesser: $volumeLesser, volumes_greater: $volumeGreater, licensedBy_in: $licensedBy, isLicensed: $isLicensed, genre_in: $genres, genre_not_in: $excludedGenres, tag_in: $tags, tag_not_in: $excludedTags, minimumTagRank: $minimumTagRank, sort: $sort, isAdult: $isAdult) { ${RESULT_FIELDS} popularity episodes ${NEXT_AIRING} countryOfOrigin } } }`;
22
+ export const ADVANCED_SEARCH_QUERY = `query ($page: Int, $id: Int, $type: MediaType, $isAdult: Boolean = false, $search: String, $format: [MediaFormat], $status: MediaStatus, $size: Int, $countryOfOrigin: CountryCode, $source: MediaSource, $season: MediaSeason, $seasonYear: Int, $year: String, $onList: Boolean, $yearLesser: FuzzyDateInt, $yearGreater: FuzzyDateInt, $episodeLesser: Int, $episodeGreater: Int, $durationLesser: Int, $durationGreater: Int, $chapterLesser: Int, $chapterGreater: Int, $volumeLesser: Int, $volumeGreater: Int, $licensedBy: [String], $isLicensed: Boolean, $genres: [String], $excludedGenres: [String], $tags: [String], $excludedTags: [String], $minimumTagRank: Int, $sort: [MediaSort] = [POPULARITY_DESC, SCORE_DESC]) { Page(page: $page, perPage: $size) { ${PAGE_INFO} media(id: $id, type: $type, season: $season, format_in: $format, status: $status, countryOfOrigin: $countryOfOrigin, source: $source, search: $search, onList: $onList, seasonYear: $seasonYear, startDate_like: $year, startDate_lesser: $yearLesser, startDate_greater: $yearGreater, episodes_lesser: $episodeLesser, episodes_greater: $episodeGreater, duration_lesser: $durationLesser, duration_greater: $durationGreater, chapters_lesser: $chapterLesser, chapters_greater: $chapterGreater, volumes_lesser: $volumeLesser, volumes_greater: $volumeGreater, licensedBy_in: $licensedBy, isLicensed: $isLicensed, genre_in: $genres, genre_not_in: $excludedGenres, tag_in: $tags, tag_not_in: $excludedTags, minimumTagRank: $minimumTagRank, sort: $sort, isAdult: $isAdult) { ${RESULT_FIELDS} popularity episodes countryOfOrigin } } }`;
23
23
 
24
24
  /** Variables: `search`, `page`, `perPage`, `type` (`ANIME` or `MANGA`). */
25
- export const SEARCH_QUERY = `query ($page: Int = 1, $perPage: Int = 15, $type: MediaType = ANIME, $search: String, $isAdult: Boolean = false) { Page(page: $page, perPage: $perPage) { ${PAGE_INFO} media(type: $type, search: $search, isAdult: $isAdult) { ${RESULT_FIELDS} popularity episodes chapters volumes ${NEXT_AIRING} } } }`;
25
+ export const SEARCH_QUERY = `query ($page: Int = 1, $perPage: Int = 15, $type: MediaType = ANIME, $search: String, $isAdult: Boolean = false) { Page(page: $page, perPage: $perPage) { ${PAGE_INFO} media(type: $type, search: $search, isAdult: $isAdult) { ${RESULT_FIELDS} popularity episodes } } }`;
26
26
 
27
27
  /** One page of anime with `filter` applied; the arguments it declares beyond paging are its variables. */
28
28
  const browseQuery = (variables: string, filter: string) =>
@@ -93,7 +93,16 @@ export const episodeCounts = (media: any): { totalEpisodes?: number; currentEpis
93
93
  return { totalEpisodes: media.episodes ?? aired, currentEpisode: aired ?? media.episodes ?? undefined };
94
94
  };
95
95
 
96
- /** The fields every list result (search, trending, the airing schedule…) shares. */
96
+ /** AniList's `nextAiringEpisode`, with `airingAt` as `airingTime`; undefined when nothing is scheduled. */
97
+ const mapNextAiring = (next: any): IAnimeResult['nextAiringEpisode'] =>
98
+ next?.airingAt
99
+ ? { airingTime: next.airingAt, timeUntilAiring: next.timeUntilAiring, episode: next.episode }
100
+ : undefined;
101
+
102
+ /**
103
+ * The fields every list result (search, trending, the airing schedule…) shares, anime or manga:
104
+ * `totalChapters` and `volumes` are a manga's, `duration` (minutes) and `nextAiringEpisode` an anime's.
105
+ */
97
106
  export const mapMediaResult = (media: any) => ({
98
107
  id: String(media.id),
99
108
  malId: media.idMal,
@@ -107,6 +116,11 @@ export const mapMediaResult = (media: any) => ({
107
116
  rating: media.averageScore,
108
117
  type: media.format,
109
118
  releaseDate: media.seasonYear,
119
+ season: media.season ?? undefined,
120
+ duration: media.duration ?? undefined,
121
+ nextAiringEpisode: mapNextAiring(media.nextAiringEpisode),
122
+ totalChapters: media.chapters ?? undefined,
123
+ volumes: media.volumes ?? undefined,
110
124
  });
111
125
 
112
126
  /** A trending, popular or by-genre result. */
@@ -114,7 +128,6 @@ export const mapBrowseResult = (media: any): IAnimeResult => ({
114
128
  ...mapMediaResult(media),
115
129
  trailer: { id: media.trailer?.id, site: media.trailer?.site, thumbnail: media.trailer?.thumbnail },
116
130
  totalEpisodes: episodeCounts(media).totalEpisodes,
117
- duration: media.duration,
118
131
  });
119
132
 
120
133
  /**
@@ -194,15 +207,7 @@ export const mapMediaDetail = (media: any) => ({
194
207
  /** mapMediaDetail plus the airing and episode fields of an anime. */
195
208
  export const mapAnimeDetail = (media: any) => ({
196
209
  ...mapMediaDetail(media),
197
- ...(media.nextAiringEpisode?.airingAt
198
- ? {
199
- nextAiringEpisode: {
200
- airingTime: media.nextAiringEpisode.airingAt,
201
- timeUntilAiring: media.nextAiringEpisode.timeUntilAiring,
202
- episode: media.nextAiringEpisode.episode,
203
- },
204
- }
205
- : {}),
210
+ ...(media.nextAiringEpisode?.airingAt ? { nextAiringEpisode: mapNextAiring(media.nextAiringEpisode) } : {}),
206
211
  ...episodeCounts(media),
207
212
  duration: media.duration,
208
213
  });