react-native-consumet 0.6.1 → 0.7.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 (114) hide show
  1. package/android/build.gradle +6 -4
  2. package/android/generated/java/com/consumet/NativeConsumetSpec.java +6 -1
  3. package/android/generated/jni/RNConsumetSpec-generated.cpp +8 -2
  4. package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI-generated.cpp +11 -2
  5. package/android/generated/jni/react/renderer/components/RNConsumetSpec/RNConsumetSpecJSI.h +14 -5
  6. package/android/src/main/assets/crypto-js.js +1 -0
  7. package/android/src/main/assets/megacloud.decodedpng.js +606 -0
  8. package/android/src/main/assets/megacloud.getsrcs.js +832 -0
  9. package/android/src/main/java/com/consumet/ConsumetModule.kt +42 -68
  10. package/android/src/main/java/com/consumet/DdosGuardModule.kt +176 -33
  11. package/ios/generated/RNConsumetSpec/RNConsumetSpec-generated.mm +9 -2
  12. package/ios/generated/RNConsumetSpec/RNConsumetSpec.h +6 -1
  13. package/ios/generated/RNConsumetSpecJSI-generated.cpp +11 -2
  14. package/ios/generated/RNConsumetSpecJSI.h +14 -5
  15. package/lib/commonjs/NativeConsumet.ts +18 -2
  16. package/lib/commonjs/extractors/megacloud/index.js +2 -3
  17. package/lib/commonjs/extractors/megacloud/index.js.map +1 -1
  18. package/lib/commonjs/extractors/megaup.js +56 -63
  19. package/lib/commonjs/extractors/megaup.js.map +1 -1
  20. package/lib/commonjs/extractors/vidcloud.js +2 -3
  21. package/lib/commonjs/extractors/vidcloud.js.map +1 -1
  22. package/lib/commonjs/index.js +0 -11
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/models/types.js +1 -0
  25. package/lib/commonjs/models/types.js.map +1 -1
  26. package/lib/commonjs/providers/anime/animekai.js +3 -2
  27. package/lib/commonjs/providers/anime/animekai.js.map +1 -1
  28. package/lib/commonjs/providers/anime/animepahe.js +3 -4
  29. package/lib/commonjs/providers/anime/animepahe.js.map +1 -1
  30. package/lib/commonjs/providers/meta/anilist.js +26 -16
  31. package/lib/commonjs/providers/meta/anilist.js.map +1 -1
  32. package/lib/commonjs/providers/movies/himovies.js +404 -0
  33. package/lib/commonjs/providers/movies/himovies.js.map +1 -0
  34. package/lib/commonjs/providers/movies/index.js +5 -1
  35. package/lib/commonjs/providers/movies/index.js.map +1 -1
  36. package/lib/commonjs/providers/movies/netflixmirror.js +243 -0
  37. package/lib/commonjs/providers/movies/netflixmirror.js.map +1 -0
  38. package/lib/commonjs/utils/providers-list.js +1 -1
  39. package/lib/commonjs/utils/providers-list.js.map +1 -1
  40. package/lib/module/NativeConsumet.ts +18 -2
  41. package/lib/module/extractors/megacloud/index.js +2 -2
  42. package/lib/module/extractors/megacloud/index.js.map +1 -1
  43. package/lib/module/extractors/megaup.js +56 -63
  44. package/lib/module/extractors/megaup.js.map +1 -1
  45. package/lib/module/extractors/vidcloud.js +2 -2
  46. package/lib/module/extractors/vidcloud.js.map +1 -1
  47. package/lib/module/index.js +0 -6
  48. package/lib/module/index.js.map +1 -1
  49. package/lib/module/models/types.js +1 -0
  50. package/lib/module/models/types.js.map +1 -1
  51. package/lib/module/providers/anime/animekai.js +3 -2
  52. package/lib/module/providers/anime/animekai.js.map +1 -1
  53. package/lib/module/providers/anime/animepahe.js +1 -2
  54. package/lib/module/providers/anime/animepahe.js.map +1 -1
  55. package/lib/module/providers/meta/anilist.js +26 -16
  56. package/lib/module/providers/meta/anilist.js.map +1 -1
  57. package/lib/module/providers/movies/himovies.js +401 -0
  58. package/lib/module/providers/movies/himovies.js.map +1 -0
  59. package/lib/module/providers/movies/index.js +5 -1
  60. package/lib/module/providers/movies/index.js.map +1 -1
  61. package/lib/module/providers/movies/netflixmirror.js +240 -0
  62. package/lib/module/providers/movies/netflixmirror.js.map +1 -0
  63. package/lib/module/utils/providers-list.js +1 -1
  64. package/lib/module/utils/providers-list.js.map +1 -1
  65. package/lib/typescript/commonjs/src/NativeConsumet.d.ts +24 -3
  66. package/lib/typescript/commonjs/src/NativeConsumet.d.ts.map +1 -1
  67. package/lib/typescript/commonjs/src/extractors/megaup.d.ts +7 -5
  68. package/lib/typescript/commonjs/src/extractors/megaup.d.ts.map +1 -1
  69. package/lib/typescript/commonjs/src/index.d.ts +0 -3
  70. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  71. package/lib/typescript/commonjs/src/models/types.d.ts +2 -1
  72. package/lib/typescript/commonjs/src/models/types.d.ts.map +1 -1
  73. package/lib/typescript/commonjs/src/providers/anime/animepahe.d.ts.map +1 -1
  74. package/lib/typescript/commonjs/src/providers/meta/anilist.d.ts.map +1 -1
  75. package/lib/typescript/commonjs/src/providers/movies/himovies.d.ts +41 -0
  76. package/lib/typescript/commonjs/src/providers/movies/himovies.d.ts.map +1 -0
  77. package/lib/typescript/commonjs/src/providers/movies/index.d.ts +4 -0
  78. package/lib/typescript/commonjs/src/providers/movies/index.d.ts.map +1 -1
  79. package/lib/typescript/commonjs/src/providers/movies/netflixmirror.d.ts +38 -0
  80. package/lib/typescript/commonjs/src/providers/movies/netflixmirror.d.ts.map +1 -0
  81. package/lib/typescript/commonjs/src/utils/providers-list.d.ts +1 -1
  82. package/lib/typescript/commonjs/src/utils/providers-list.d.ts.map +1 -1
  83. package/lib/typescript/module/src/NativeConsumet.d.ts +24 -3
  84. package/lib/typescript/module/src/NativeConsumet.d.ts.map +1 -1
  85. package/lib/typescript/module/src/extractors/megaup.d.ts +7 -5
  86. package/lib/typescript/module/src/extractors/megaup.d.ts.map +1 -1
  87. package/lib/typescript/module/src/index.d.ts +0 -3
  88. package/lib/typescript/module/src/index.d.ts.map +1 -1
  89. package/lib/typescript/module/src/models/types.d.ts +2 -1
  90. package/lib/typescript/module/src/models/types.d.ts.map +1 -1
  91. package/lib/typescript/module/src/providers/anime/animepahe.d.ts.map +1 -1
  92. package/lib/typescript/module/src/providers/meta/anilist.d.ts.map +1 -1
  93. package/lib/typescript/module/src/providers/movies/himovies.d.ts +41 -0
  94. package/lib/typescript/module/src/providers/movies/himovies.d.ts.map +1 -0
  95. package/lib/typescript/module/src/providers/movies/index.d.ts +4 -0
  96. package/lib/typescript/module/src/providers/movies/index.d.ts.map +1 -1
  97. package/lib/typescript/module/src/providers/movies/netflixmirror.d.ts +38 -0
  98. package/lib/typescript/module/src/providers/movies/netflixmirror.d.ts.map +1 -0
  99. package/lib/typescript/module/src/utils/providers-list.d.ts +1 -1
  100. package/lib/typescript/module/src/utils/providers-list.d.ts.map +1 -1
  101. package/package.json +1 -1
  102. package/src/NativeConsumet.ts +18 -2
  103. package/src/extractors/megacloud/index.ts +2 -2
  104. package/src/extractors/megaup.ts +60 -83
  105. package/src/extractors/vidcloud.ts +2 -2
  106. package/src/index.tsx +135 -138
  107. package/src/models/types.ts +1 -0
  108. package/src/providers/anime/animekai.ts +2 -2
  109. package/src/providers/anime/animepahe.ts +1 -2
  110. package/src/providers/meta/anilist.ts +28 -18
  111. package/src/providers/movies/himovies.ts +495 -0
  112. package/src/providers/movies/index.ts +4 -0
  113. package/src/providers/movies/netflixmirror.ts +287 -0
  114. package/src/utils/providers-list.ts +2 -0
@@ -8,6 +8,7 @@ import android.webkit.*
8
8
  import com.facebook.react.bridge.Promise
9
9
  import com.facebook.react.bridge.ReactApplicationContext
10
10
  import com.facebook.react.bridge.ReactMethod
11
+ import com.facebook.react.bridge.ReadableMap
11
12
  import com.facebook.react.module.annotations.ReactModule
12
13
  import com.facebook.react.turbomodule.core.interfaces.TurboModule
13
14
  import java.util.concurrent.CountDownLatch
@@ -20,10 +21,7 @@ class ConsumetModule(private val reactContext: ReactApplicationContext) :
20
21
  private val tag by lazy { javaClass.simpleName }
21
22
  private val ddosGuardHelper by lazy { DdosGuardHelper(reactContext) }
22
23
 
23
- class JsInterface(
24
- private val latch: CountDownLatch,
25
- private val context: ReactApplicationContext
26
- ) {
24
+ class JsInterface(private val latch: CountDownLatch) {
27
25
  var result: String? = null
28
26
 
29
27
  @JavascriptInterface
@@ -32,28 +30,21 @@ class ConsumetModule(private val reactContext: ReactApplicationContext) :
32
30
  result = response
33
31
  latch.countDown()
34
32
  }
33
+ }
35
34
 
36
- @JavascriptInterface
37
- fun loadLocalAsset(filename: String): String {
38
- return try {
39
- context.assets.open(filename).bufferedReader().use { it.readText() }
40
- } catch (e: Exception) {
41
- Log.e("ConsumetModule", "Failed to load local asset: $filename", e)
42
- "console.error('Failed to load $filename: ${e.message}');"
43
- }
44
- }
35
+ private fun getJsContent(file: String): String {
36
+ return reactApplicationContext.assets.open(file).bufferedReader().use { it.readText() }
45
37
  }
46
38
 
47
39
  @SuppressLint("SetJavaScriptEnabled")
48
- override fun getSources(xrax: String, promise: Promise) {
40
+ override fun getSources(embedUrl: String, site: String, promise: Promise) {
49
41
  val latch = CountDownLatch(1)
50
42
  var webView: WebView? = null
51
- val jsi = JsInterface(latch, reactContext)
43
+ val jsi = JsInterface(latch)
52
44
 
53
45
  handler.post {
54
- val webview = WebView(reactContext)
46
+ val webview = WebView(reactApplicationContext)
55
47
  webView = webview
56
-
57
48
  with(webview.settings) {
58
49
  javaScriptEnabled = true
59
50
  domStorageEnabled = true
@@ -68,55 +59,20 @@ class ConsumetModule(private val reactContext: ReactApplicationContext) :
68
59
  webview.webViewClient =
69
60
  object : WebViewClient() {
70
61
  override fun onPageFinished(view: WebView?, url: String?) {
62
+ Log.d(tag, "onPageFinished $url")
71
63
  super.onPageFinished(view, url)
72
64
 
73
- val cdnScript =
74
- """
75
- (async function() {
76
- async function loadScriptWithFallback(url, localFilename) {
77
- try {
78
- console.log("Loading from CDN: " + url);
79
- await new Promise((resolve, reject) => {
80
- const script = document.createElement('script');
81
- script.src = url;
82
- script.onload = () => resolve();
83
- script.onerror = () => reject(new Error("CDN failed"));
84
- document.head.appendChild(script);
85
- setTimeout(() => reject(new Error("CDN timeout")), 5000);
86
- });
87
- } catch (e) {
88
- console.warn("Falling back to local asset: " + localFilename);
89
- const localScript = window.jsinterface.loadLocalAsset(localFilename);
90
- eval(localScript);
91
- }
92
- }
93
-
94
- try {
95
- await loadScriptWithFallback("https://cdn.jsdelivr.net/gh/Kohi-den/extensions-source@main/lib/megacloud-extractor/src/main/assets/crypto-js.js", "crypto-js.js");
96
- await loadScriptWithFallback("https://cdn.jsdelivr.net/gh/Kohi-den/extensions-source@main/lib/megacloud-extractor/src/main/assets/megacloud.decodedpng.js", "megacloud.decodedpng.js");
97
- await loadScriptWithFallback("https://cdn.jsdelivr.net/gh/Kohi-den/extensions-source@main/lib/megacloud-extractor/src/main/assets/megacloud.getsrcs.js", "megacloud.getsrcs.js");
98
-
99
- console.log("Calling getSources...");
100
- const result = await getSources("${xrax}");
101
- window.jsinterface.setResponse(JSON.stringify(result));
102
- } catch (err) {
103
- console.error("Execution error:", err);
104
- window.jsinterface.setResponse("ERROR: " + err.message);
105
- }
106
- })();
107
- """.trimIndent()
108
-
109
- view?.evaluateJavascript(cdnScript, null)
110
- }
111
-
112
- override fun onReceivedError(
113
- view: WebView?,
114
- errorCode: Int,
115
- description: String?,
116
- failingUrl: String?
117
- ) {
118
- Log.e(tag, "WebView error: $errorCode - $description @ $failingUrl")
119
- super.onReceivedError(view, errorCode, description, failingUrl)
65
+ Log.d(tag, "injecting scripts")
66
+ // Adjust paths to match your assets folder structure
67
+ view?.evaluateJavascript(getJsContent("crypto-js.js")) {}
68
+ view?.evaluateJavascript(getJsContent("megacloud.decodedpng.js")) {}
69
+ view?.evaluateJavascript(getJsContent("megacloud.getsrcs.js")) {}
70
+
71
+ Log.d(tag, "running script")
72
+ view?.evaluateJavascript(
73
+ "getSources(\"${embedUrl}\",\"${site}\")" +
74
+ ".then( s => jsinterface.setResponse( JSON.stringify(s) ) )",
75
+ ) {}
120
76
  }
121
77
  }
122
78
 
@@ -125,17 +81,30 @@ class ConsumetModule(private val reactContext: ReactApplicationContext) :
125
81
  override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
126
82
  Log.d(
127
83
  tag,
128
- "Console: [${consoleMessage?.messageLevel()}] ${consoleMessage?.message()}"
84
+ "Chrome: [${consoleMessage?.messageLevel()}]" +
85
+ "${consoleMessage?.message()}" +
86
+ " at ${consoleMessage?.lineNumber()}" +
87
+ " in ${consoleMessage?.sourceId()}",
129
88
  )
130
89
  return super.onConsoleMessage(consoleMessage)
131
90
  }
132
91
  }
133
92
 
93
+ Log.d(tag, "loading url: $embedUrl")
94
+ val regex = Regex("https://[a-zA-Z0-9.]*")
95
+ val extractedBase = regex.find(embedUrl)?.value ?: embedUrl
96
+ val baseUrl =
97
+ if (extractedBase.contains("mega", ignoreCase = true)) {
98
+ "https://megacloud.tv"
99
+ } else {
100
+ extractedBase
101
+ }
102
+ Log.d(tag, "baseUrl: $baseUrl")
134
103
  val headers = mapOf("X-Requested-With" to "org.lineageos.jelly")
135
- webview.loadUrl("https://megacloud.tv/about", headers)
104
+ webView?.loadUrl(baseUrl, headers)
136
105
  }
137
106
 
138
- // Await result or timeout
107
+ // Run in a separate thread to not block the JS thread
139
108
  Thread {
140
109
  val success = latch.await(TIMEOUT_SEC, TimeUnit.SECONDS)
141
110
 
@@ -147,7 +116,7 @@ class ConsumetModule(private val reactContext: ReactApplicationContext) :
147
116
  if (success && jsi.result != null) {
148
117
  promise.resolve(jsi.result)
149
118
  } else {
150
- promise.reject("ERROR", "Failed to get sources or timeout2")
119
+ promise.reject("ERROR", "Failed to get sources or timeout")
151
120
  }
152
121
  }
153
122
  }
@@ -168,4 +137,9 @@ class ConsumetModule(private val reactContext: ReactApplicationContext) :
168
137
  override fun getDdosGuardCookiesWithWebView(url: String, promise: Promise) {
169
138
  ddosGuardHelper.getDdosGuardCookiesWithWebView(url, promise)
170
139
  }
140
+
141
+ @ReactMethod
142
+ override fun makeGetRequestWithWebView(url: String, headers: ReadableMap, promise: Promise) {
143
+ ddosGuardHelper.makeGetRequestWithWebView(url, headers, promise)
144
+ }
171
145
  }
@@ -1,18 +1,21 @@
1
1
  package com.consumet
2
2
 
3
+ import android.os.Handler
4
+ import android.os.Looper
5
+ import android.webkit.ConsoleMessage
3
6
  import android.webkit.CookieManager
7
+ import android.webkit.WebChromeClient
8
+ import android.webkit.WebView
9
+ import android.webkit.WebViewClient
4
10
  import com.facebook.react.bridge.Promise
5
11
  import com.facebook.react.bridge.ReactApplicationContext
12
+ import com.facebook.react.bridge.ReadableMap
6
13
  import com.facebook.react.bridge.WritableNativeMap
14
+ import java.util.regex.Pattern
7
15
  import okhttp3.Cookie
8
- import okhttp3.HttpUrl.Companion.toHttpUrlOrNull // Updated import
16
+ import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
9
17
  import okhttp3.OkHttpClient
10
18
  import okhttp3.Request
11
- import java.util.regex.Pattern
12
- import android.webkit.WebView
13
- import android.webkit.WebViewClient
14
- import android.os.Handler
15
- import android.os.Looper
16
19
 
17
20
  class DdosGuardHelper(private val reactContext: ReactApplicationContext) {
18
21
  private val client = OkHttpClient.Builder().build()
@@ -20,10 +23,12 @@ class DdosGuardHelper(private val reactContext: ReactApplicationContext) {
20
23
 
21
24
  fun bypassDdosGuard(url: String, promise: Promise) {
22
25
  try {
23
- val httpUrl = url.toHttpUrlOrNull() ?: run {
24
- promise.reject("ERROR", "Invalid URL")
25
- return
26
- }
26
+ val httpUrl =
27
+ url.toHttpUrlOrNull()
28
+ ?: run {
29
+ promise.reject("ERROR", "Invalid URL")
30
+ return
31
+ }
27
32
 
28
33
  val cookies = cookieManager.getCookie(url)
29
34
  val oldCookies = mutableListOf<Cookie>()
@@ -48,10 +53,12 @@ class DdosGuardHelper(private val reactContext: ReactApplicationContext) {
48
53
  }
49
54
 
50
55
  // Get new cookie
51
- val newCookie = getNewCookie(httpUrl) ?: run {
52
- promise.reject("ERROR", "Failed to get DDos-Guard cookie")
53
- return
54
- }
56
+ val newCookie =
57
+ getNewCookie(httpUrl)
58
+ ?: run {
59
+ promise.reject("ERROR", "Failed to get DDos-Guard cookie")
60
+ return
61
+ }
55
62
 
56
63
  oldCookies.add(newCookie)
57
64
  val newCookieHeader = cookiesToHeaderString(oldCookies)
@@ -84,10 +91,8 @@ class DdosGuardHelper(private val reactContext: ReactApplicationContext) {
84
91
  return ddg2Cookie
85
92
  }
86
93
 
87
- val checkJsRequest = Request.Builder()
88
- .url("https://check.ddos-guard.net/check.js")
89
- .get()
90
- .build()
94
+ val checkJsRequest =
95
+ Request.Builder().url("https://check.ddos-guard.net/check.js").get().build()
91
96
 
92
97
  val checkJsResponse = client.newCall(checkJsRequest).execute()
93
98
  val checkJsBody = checkJsResponse.body?.string() ?: ""
@@ -99,13 +104,11 @@ class DdosGuardHelper(private val reactContext: ReactApplicationContext) {
99
104
  if (!matcher.find()) {
100
105
  return null
101
106
  }
102
- val wellKnown = matcher.group(1)
107
+ // Fix: Ensure we're getting a String from the match group
108
+ val wellKnown = matcher.group(1) ?: ""
103
109
 
104
110
  val checkUrl = "${url.scheme}://${url.host}$wellKnown"
105
- val checkRequest = Request.Builder()
106
- .url(checkUrl)
107
- .get()
108
- .build()
111
+ val checkRequest = Request.Builder().url(checkUrl).get().build()
109
112
 
110
113
  val checkResponse = client.newCall(checkRequest).execute()
111
114
  val setCookieHeader = checkResponse.header("set-cookie")
@@ -123,20 +126,160 @@ class DdosGuardHelper(private val reactContext: ReactApplicationContext) {
123
126
  val webView = WebView(reactContext)
124
127
  webView.settings.javaScriptEnabled = true
125
128
  webView.settings.domStorageEnabled = true
126
-
127
- webView.webViewClient = object : WebViewClient() {
128
- override fun onPageFinished(view: WebView, url: String) {
129
- val cookieManager = android.webkit.CookieManager.getInstance()
130
- val cookie = cookieManager.getCookie(url)
131
- if (!cookie.isNullOrEmpty() && cookie.contains("__ddg2")) {
132
- promise.resolve(cookie)
133
- } else {
134
- promise.reject("COOKIE_ERROR", "No __ddg2 cookie received")
129
+
130
+ webView.webViewClient =
131
+ object : WebViewClient() {
132
+ override fun onPageFinished(view: WebView, url: String) {
133
+ val cookieManager = android.webkit.CookieManager.getInstance()
134
+ val cookie = cookieManager.getCookie(url)
135
+ if (!cookie.isNullOrEmpty() && cookie.contains("__ddg2")) {
136
+ promise.resolve(cookie)
137
+ } else {
138
+ promise.reject("COOKIE_ERROR", "No __ddg2 cookie received")
139
+ }
140
+ }
141
+ }
142
+
143
+ webView.loadUrl(url)
144
+ }
145
+ }
146
+
147
+ fun makeGetRequestWithWebView(
148
+ url: String,
149
+ headers: ReadableMap?,
150
+ promise: Promise
151
+ ) {
152
+ Handler(Looper.getMainLooper()).post {
153
+ // Create and configure the WebView
154
+ val webView = WebView(reactContext)
155
+
156
+ // Enable WebView debugging during development
157
+ WebView.setWebContentsDebuggingEnabled(true)
158
+
159
+ // Configure WebView settings to mimic a browser
160
+ webView.settings.apply {
161
+ javaScriptEnabled = true
162
+ domStorageEnabled = true
163
+ databaseEnabled = true
164
+ loadWithOverviewMode = true
165
+ useWideViewPort = true
166
+ userAgentString = headers?.getString("User-Agent") ?:
167
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
168
+ }
169
+
170
+ // Enable cookies
171
+ val cookieManager = CookieManager.getInstance()
172
+ cookieManager.setAcceptCookie(true)
173
+ cookieManager.setAcceptThirdPartyCookies(webView, true)
174
+
175
+ // Set up timeout handler
176
+ val timeoutHandler = Handler(Looper.getMainLooper())
177
+ val timeoutRunnable = Runnable {
178
+ val allCookies = cookieManager.getCookie(url) ?: ""
179
+
180
+ val result = WritableNativeMap()
181
+ result.putString("url", webView.url ?: url)
182
+ result.putString("cookies", allCookies)
183
+ result.putString("status", "timeout")
184
+
185
+ promise.resolve(result)
186
+
187
+ // Clean up
188
+ webView.stopLoading()
189
+ webView.destroy()
190
+ }
191
+
192
+ // Log console messages for debugging
193
+ webView.webChromeClient = object : WebChromeClient() {
194
+ override fun onConsoleMessage(consoleMessage: ConsoleMessage): Boolean {
195
+ println("WebView Console: ${consoleMessage.message()}")
196
+ return true
197
+ }
198
+ }
199
+
200
+ // Handle page loading events
201
+ webView.webViewClient = object : WebViewClient() {
202
+ override fun onPageFinished(view: WebView, loadedUrl: String) {
203
+ // Cancel the timeout since page is loaded
204
+ timeoutHandler.removeCallbacks(timeoutRunnable)
205
+
206
+ // Capture page content after a short delay to ensure JS execution
207
+ timeoutHandler.postDelayed({
208
+ view.evaluateJavascript(
209
+ """
210
+ (function() {
211
+ try {
212
+ var content = document.documentElement.outerHTML;
213
+ var title = document.title;
214
+ return JSON.stringify({
215
+ content: content,
216
+ title: title
217
+ });
218
+ } catch(e) {
219
+ return JSON.stringify({
220
+ error: e.message
221
+ });
222
+ }
223
+ })();
224
+ """.trimIndent()
225
+ ) { responseJson ->
226
+ // Get cookies
227
+ val cookies = cookieManager.getCookie(loadedUrl) ?: ""
228
+
229
+ // Create result object
230
+ val result = WritableNativeMap()
231
+ result.putString("url", loadedUrl)
232
+ result.putString("response", responseJson)
233
+ result.putString("cookies", cookies)
234
+ result.putString("status", "success")
235
+
236
+ promise.resolve(result)
237
+
238
+ // Clean up
239
+ webView.stopLoading()
240
+ webView.destroy()
241
+ }
242
+ }, 1500) // Wait 1.5 seconds for any JavaScript to execute
243
+ }
244
+
245
+ override fun onReceivedError(view: WebView, errorCode: Int, description: String, failingUrl: String) {
246
+ timeoutHandler.removeCallbacks(timeoutRunnable)
247
+
248
+ promise.reject("WEBVIEW_ERROR", "WebView error: $description")
249
+
250
+ // Clean up
251
+ webView.stopLoading()
252
+ webView.destroy()
253
+ }
254
+ }
255
+
256
+ // Set maximum timeout (30 seconds)
257
+ timeoutHandler.postDelayed(timeoutRunnable, 30000)
258
+
259
+ // Make the request with headers
260
+ if (headers != null && headers.hasKey("User-Agent")) {
261
+ val headerMap = mutableMapOf<String, String>()
262
+ val iterator = headers.keySetIterator()
263
+ while (iterator.hasNextKey()) {
264
+ val key = iterator.nextKey()
265
+ val value = headers.getString(key) ?: ""
266
+
267
+ if (key.equals("Cookie", ignoreCase = true)) {
268
+ // 🔥 Manually set cookies in CookieManager
269
+ val cookiePairs = value.split(";")
270
+ for (cookie in cookiePairs) {
271
+ cookieManager.setCookie(url, cookie.trim())
135
272
  }
273
+ } else {
274
+ headerMap[key] = value
136
275
  }
137
276
  }
138
-
277
+
278
+ webView.loadUrl(url, headerMap)
279
+ } else {
139
280
  webView.loadUrl(url)
140
281
  }
282
+
141
283
  }
284
+ }
142
285
  }
@@ -27,7 +27,7 @@
27
27
  namespace facebook::react {
28
28
 
29
29
  static facebook::jsi::Value __hostFunction_NativeConsumetSpecJSI_getSources(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
30
- return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "getSources", @selector(getSources:resolve:reject:), args, count);
30
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "getSources", @selector(getSources:site:resolve:reject:), args, count);
31
31
  }
32
32
 
33
33
  static facebook::jsi::Value __hostFunction_NativeConsumetSpecJSI_bypassDdosGuard(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
@@ -38,10 +38,14 @@ namespace facebook::react {
38
38
  return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "getDdosGuardCookiesWithWebView", @selector(getDdosGuardCookiesWithWebView:resolve:reject:), args, count);
39
39
  }
40
40
 
41
+ static facebook::jsi::Value __hostFunction_NativeConsumetSpecJSI_makeGetRequestWithWebView(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
42
+ return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "makeGetRequestWithWebView", @selector(makeGetRequestWithWebView:headers:resolve:reject:), args, count);
43
+ }
44
+
41
45
  NativeConsumetSpecJSI::NativeConsumetSpecJSI(const ObjCTurboModule::InitParams &params)
42
46
  : ObjCTurboModule(params) {
43
47
 
44
- methodMap_["getSources"] = MethodMetadata {1, __hostFunction_NativeConsumetSpecJSI_getSources};
48
+ methodMap_["getSources"] = MethodMetadata {2, __hostFunction_NativeConsumetSpecJSI_getSources};
45
49
 
46
50
 
47
51
  methodMap_["bypassDdosGuard"] = MethodMetadata {1, __hostFunction_NativeConsumetSpecJSI_bypassDdosGuard};
@@ -49,5 +53,8 @@ namespace facebook::react {
49
53
 
50
54
  methodMap_["getDdosGuardCookiesWithWebView"] = MethodMetadata {1, __hostFunction_NativeConsumetSpecJSI_getDdosGuardCookiesWithWebView};
51
55
 
56
+
57
+ methodMap_["makeGetRequestWithWebView"] = MethodMetadata {2, __hostFunction_NativeConsumetSpecJSI_makeGetRequestWithWebView};
58
+
52
59
  }
53
60
  } // namespace facebook::react
@@ -35,7 +35,8 @@ NS_ASSUME_NONNULL_BEGIN
35
35
 
36
36
  @protocol NativeConsumetSpec <RCTBridgeModule, RCTTurboModule>
37
37
 
38
- - (void)getSources:(NSString *)xrax
38
+ - (void)getSources:(NSString *)embedUrl
39
+ site:(NSString *)site
39
40
  resolve:(RCTPromiseResolveBlock)resolve
40
41
  reject:(RCTPromiseRejectBlock)reject;
41
42
  - (void)bypassDdosGuard:(NSString *)url
@@ -44,6 +45,10 @@ NS_ASSUME_NONNULL_BEGIN
44
45
  - (void)getDdosGuardCookiesWithWebView:(NSString *)url
45
46
  resolve:(RCTPromiseResolveBlock)resolve
46
47
  reject:(RCTPromiseRejectBlock)reject;
48
+ - (void)makeGetRequestWithWebView:(NSString *)url
49
+ headers:(NSDictionary *)headers
50
+ resolve:(RCTPromiseResolveBlock)resolve
51
+ reject:(RCTPromiseRejectBlock)reject;
47
52
 
48
53
  @end
49
54
 
@@ -14,7 +14,8 @@ namespace facebook::react {
14
14
  static jsi::Value __hostFunction_NativeConsumetCxxSpecJSI_getSources(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15
15
  return static_cast<NativeConsumetCxxSpecJSI *>(&turboModule)->getSources(
16
16
  rt,
17
- count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
17
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
18
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asString(rt)
18
19
  );
19
20
  }
20
21
  static jsi::Value __hostFunction_NativeConsumetCxxSpecJSI_bypassDdosGuard(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
@@ -29,12 +30,20 @@ static jsi::Value __hostFunction_NativeConsumetCxxSpecJSI_getDdosGuardCookiesWit
29
30
  count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt)
30
31
  );
31
32
  }
33
+ static jsi::Value __hostFunction_NativeConsumetCxxSpecJSI_makeGetRequestWithWebView(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
34
+ return static_cast<NativeConsumetCxxSpecJSI *>(&turboModule)->makeGetRequestWithWebView(
35
+ rt,
36
+ count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asString(rt),
37
+ count <= 1 ? throw jsi::JSError(rt, "Expected argument in position 1 to be passed") : args[1].asObject(rt)
38
+ );
39
+ }
32
40
 
33
41
  NativeConsumetCxxSpecJSI::NativeConsumetCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
34
42
  : TurboModule("Consumet", jsInvoker) {
35
- methodMap_["getSources"] = MethodMetadata {1, __hostFunction_NativeConsumetCxxSpecJSI_getSources};
43
+ methodMap_["getSources"] = MethodMetadata {2, __hostFunction_NativeConsumetCxxSpecJSI_getSources};
36
44
  methodMap_["bypassDdosGuard"] = MethodMetadata {1, __hostFunction_NativeConsumetCxxSpecJSI_bypassDdosGuard};
37
45
  methodMap_["getDdosGuardCookiesWithWebView"] = MethodMetadata {1, __hostFunction_NativeConsumetCxxSpecJSI_getDdosGuardCookiesWithWebView};
46
+ methodMap_["makeGetRequestWithWebView"] = MethodMetadata {2, __hostFunction_NativeConsumetCxxSpecJSI_makeGetRequestWithWebView};
38
47
  }
39
48
 
40
49
 
@@ -20,9 +20,10 @@ protected:
20
20
  NativeConsumetCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
21
21
 
22
22
  public:
23
- virtual jsi::Value getSources(jsi::Runtime &rt, jsi::String xrax) = 0;
23
+ virtual jsi::Value getSources(jsi::Runtime &rt, jsi::String embedUrl, jsi::String site) = 0;
24
24
  virtual jsi::Value bypassDdosGuard(jsi::Runtime &rt, jsi::String url) = 0;
25
25
  virtual jsi::Value getDdosGuardCookiesWithWebView(jsi::Runtime &rt, jsi::String url) = 0;
26
+ virtual jsi::Value makeGetRequestWithWebView(jsi::Runtime &rt, jsi::String url, jsi::Object headers) = 0;
26
27
 
27
28
  };
28
29
 
@@ -53,13 +54,13 @@ private:
53
54
 
54
55
  }
55
56
 
56
- jsi::Value getSources(jsi::Runtime &rt, jsi::String xrax) override {
57
+ jsi::Value getSources(jsi::Runtime &rt, jsi::String embedUrl, jsi::String site) override {
57
58
  static_assert(
58
- bridging::getParameterCount(&T::getSources) == 2,
59
- "Expected getSources(...) to have 2 parameters");
59
+ bridging::getParameterCount(&T::getSources) == 3,
60
+ "Expected getSources(...) to have 3 parameters");
60
61
 
61
62
  return bridging::callFromJs<jsi::Value>(
62
- rt, &T::getSources, jsInvoker_, instance_, std::move(xrax));
63
+ rt, &T::getSources, jsInvoker_, instance_, std::move(embedUrl), std::move(site));
63
64
  }
64
65
  jsi::Value bypassDdosGuard(jsi::Runtime &rt, jsi::String url) override {
65
66
  static_assert(
@@ -77,6 +78,14 @@ private:
77
78
  return bridging::callFromJs<jsi::Value>(
78
79
  rt, &T::getDdosGuardCookiesWithWebView, jsInvoker_, instance_, std::move(url));
79
80
  }
81
+ jsi::Value makeGetRequestWithWebView(jsi::Runtime &rt, jsi::String url, jsi::Object headers) override {
82
+ static_assert(
83
+ bridging::getParameterCount(&T::makeGetRequestWithWebView) == 3,
84
+ "Expected makeGetRequestWithWebView(...) to have 3 parameters");
85
+
86
+ return bridging::callFromJs<jsi::Value>(
87
+ rt, &T::makeGetRequestWithWebView, jsInvoker_, instance_, std::move(url), std::move(headers));
88
+ }
80
89
 
81
90
  private:
82
91
  friend class NativeConsumetCxxSpec;
@@ -2,9 +2,25 @@ import type { TurboModule } from 'react-native';
2
2
  import { TurboModuleRegistry } from 'react-native';
3
3
 
4
4
  export interface Spec extends TurboModule {
5
- getSources(xrax: string): Promise<string>;
5
+ getSources(embedUrl: string, site: string): Promise<string>;
6
6
  bypassDdosGuard(url: string): Promise<{ cookie: string }>;
7
7
  getDdosGuardCookiesWithWebView(url: string): Promise<string>;
8
+ makeGetRequestWithWebView(
9
+ url: string,
10
+ headers: { [key: string]: string }
11
+ ): Promise<{
12
+ url: string;
13
+ response: string;
14
+ cookies: string;
15
+ status: string;
16
+ }>;
8
17
  }
9
18
 
10
- export default TurboModuleRegistry.getEnforcing<Spec>('Consumet');
19
+ const NativeConsumet = TurboModuleRegistry.getEnforcing<Spec>('Consumet');
20
+
21
+ export const bypassDdosGuard = NativeConsumet.bypassDdosGuard;
22
+ export const getDdosGuardCookiesWithWebView = NativeConsumet.getDdosGuardCookiesWithWebView;
23
+ export const makeGetRequestWithWebView = NativeConsumet.makeGetRequestWithWebView;
24
+ export const getSources = NativeConsumet.getSources;
25
+
26
+ export default NativeConsumet;
@@ -5,8 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _index = require("../../models/index.js");
8
- var _NativeConsumet = _interopRequireDefault(require("../../NativeConsumet"));
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ var _NativeConsumet = require("../../NativeConsumet");
10
9
  class MegaCloud extends _index.VideoExtractor {
11
10
  serverName = 'MegaCloud';
12
11
  sources = [];
@@ -26,7 +25,7 @@ class MegaCloud extends _index.VideoExtractor {
26
25
  };
27
26
  const regex = /\/([^\/?]+)(?=\?)/;
28
27
  const xrax = embedIframeURL.toString().match(regex)?.[1];
29
- const jsonResponse = await _NativeConsumet.default.getSources(xrax);
28
+ const jsonResponse = await (0, _NativeConsumet.getSources)(embedIframeURL.href, referer);
30
29
  const resp = JSON.parse(jsonResponse);
31
30
  if (!resp) return extractedData;
32
31
  if (Array.isArray(resp.sources)) {
@@ -1 +1 @@
1
- {"version":3,"names":["_index","require","_NativeConsumet","_interopRequireDefault","e","__esModule","default","MegaCloud","VideoExtractor","serverName","sources","extract","embedIframeURL","referer","extractedData","subtitles","intro","start","end","outro","regex","xrax","toString","match","jsonResponse","Consumet","getSources","resp","JSON","parse","Array","isArray","map","s","url","file","isM3U8","type","tracks","track","lang","label","kind","err","_default","exports"],"sourceRoot":"..\\..\\..\\..\\src","sources":["extractors/megacloud/index.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AAA4C,SAAAE,uBAAAC,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAE5C,MAAMG,SAAS,SAASC,qBAAc,CAAC;EAClBC,UAAU,GAAG,WAAW;EACxBC,OAAO,GAAa,EAAE;EAEzC,MAAMC,OAAOA,CAACC,cAAmB,EAAEC,OAAe,GAAG,oBAAoB,EAAE;IACzE,IAAI;MACF,MAAMC,aAAsB,GAAG;QAC7BC,SAAS,EAAE,EAAE;QACbC,KAAK,EAAE;UACLC,KAAK,EAAE,CAAC;UACRC,GAAG,EAAE;QACP,CAAC;QACDC,KAAK,EAAE;UACLF,KAAK,EAAE,CAAC;UACRC,GAAG,EAAE;QACP,CAAC;QACDR,OAAO,EAAE;MACX,CAAC;MACD,MAAMU,KAAK,GAAG,mBAAmB;MACjC,MAAMC,IAAI,GAAGT,cAAc,CAACU,QAAQ,CAAC,CAAC,CAACC,KAAK,CAACH,KAAK,CAAC,GAAG,CAAC,CAAC;MACxD,MAAMI,YAAY,GAAG,MAAMC,uBAAQ,CAACC,UAAU,CAACL,IAAK,CAAC;MACrD,MAAMM,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACL,YAAY,CAAC;MAErC,IAAI,CAACG,IAAI,EAAE,OAAOb,aAAa;MAE/B,IAAIgB,KAAK,CAACC,OAAO,CAACJ,IAAI,CAACjB,OAAO,CAAC,EAAE;QAC/BI,aAAa,CAACJ,OAAO,GAAGiB,IAAI,CAACjB,OAAO,CAACsB,GAAG,CAAEC,CAA8B,KAAM;UAC5EC,GAAG,EAAED,CAAC,CAACE,IAAI;UACXC,MAAM,EAAEH,CAAC,CAACI,IAAI,KAAK,KAAK;UACxBA,IAAI,EAAEJ,CAAC,CAACI;QACV,CAAC,CAAC,CAAC;MACL;MAEAvB,aAAa,CAACE,KAAK,GAAGW,IAAI,CAACX,KAAK,GAAGW,IAAI,CAACX,KAAK,GAAGF,aAAa,CAACE,KAAK;MACnEF,aAAa,CAACK,KAAK,GAAGQ,IAAI,CAACR,KAAK,GAAGQ,IAAI,CAACR,KAAK,GAAGL,aAAa,CAACK,KAAK;MAEnEL,aAAa,CAACC,SAAS,GAAGY,IAAI,CAACW,MAAM,CAACN,GAAG,CAAEO,KAA2C,KAAM;QAC1FL,GAAG,EAAEK,KAAK,CAACJ,IAAI;QACfK,IAAI,EAAED,KAAK,CAACE,KAAK,GAAGF,KAAK,CAACE,KAAK,GAAGF,KAAK,CAACG;MAC1C,CAAC,CAAC,CAAC;MAEH,OAAO;QACL1B,KAAK,EAAEF,aAAa,CAACE,KAAK;QAC1BG,KAAK,EAAEL,aAAa,CAACK,KAAK;QAC1BT,OAAO,EAAEI,aAAa,CAACJ,OAAO;QAC9BK,SAAS,EAAED,aAAa,CAACC;MAC3B,CAAC;IACH,CAAC,CAAC,OAAO4B,GAAG,EAAE;MACZ,MAAMA,GAAG;IACX;EACF;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAvC,OAAA,GAEcC,SAAS","ignoreList":[]}
1
+ {"version":3,"names":["_index","require","_NativeConsumet","MegaCloud","VideoExtractor","serverName","sources","extract","embedIframeURL","referer","extractedData","subtitles","intro","start","end","outro","regex","xrax","toString","match","jsonResponse","getSources","href","resp","JSON","parse","Array","isArray","map","s","url","file","isM3U8","type","tracks","track","lang","label","kind","err","_default","exports","default"],"sourceRoot":"..\\..\\..\\..\\src","sources":["extractors/megacloud/index.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,eAAA,GAAAD,OAAA;AAEA,MAAME,SAAS,SAASC,qBAAc,CAAC;EAClBC,UAAU,GAAG,WAAW;EACxBC,OAAO,GAAa,EAAE;EAEzC,MAAMC,OAAOA,CAACC,cAAmB,EAAEC,OAAe,GAAG,oBAAoB,EAAE;IACzE,IAAI;MACF,MAAMC,aAAsB,GAAG;QAC7BC,SAAS,EAAE,EAAE;QACbC,KAAK,EAAE;UACLC,KAAK,EAAE,CAAC;UACRC,GAAG,EAAE;QACP,CAAC;QACDC,KAAK,EAAE;UACLF,KAAK,EAAE,CAAC;UACRC,GAAG,EAAE;QACP,CAAC;QACDR,OAAO,EAAE;MACX,CAAC;MACD,MAAMU,KAAK,GAAG,mBAAmB;MACjC,MAAMC,IAAI,GAAGT,cAAc,CAACU,QAAQ,CAAC,CAAC,CAACC,KAAK,CAACH,KAAK,CAAC,GAAG,CAAC,CAAC;MACxD,MAAMI,YAAY,GAAG,MAAM,IAAAC,0BAAU,EAACb,cAAc,CAACc,IAAI,EAAEb,OAAO,CAAC;MACnE,MAAMc,IAAI,GAAGC,IAAI,CAACC,KAAK,CAACL,YAAY,CAAC;MAErC,IAAI,CAACG,IAAI,EAAE,OAAOb,aAAa;MAE/B,IAAIgB,KAAK,CAACC,OAAO,CAACJ,IAAI,CAACjB,OAAO,CAAC,EAAE;QAC/BI,aAAa,CAACJ,OAAO,GAAGiB,IAAI,CAACjB,OAAO,CAACsB,GAAG,CAAEC,CAA8B,KAAM;UAC5EC,GAAG,EAAED,CAAC,CAACE,IAAI;UACXC,MAAM,EAAEH,CAAC,CAACI,IAAI,KAAK,KAAK;UACxBA,IAAI,EAAEJ,CAAC,CAACI;QACV,CAAC,CAAC,CAAC;MACL;MAEAvB,aAAa,CAACE,KAAK,GAAGW,IAAI,CAACX,KAAK,GAAGW,IAAI,CAACX,KAAK,GAAGF,aAAa,CAACE,KAAK;MACnEF,aAAa,CAACK,KAAK,GAAGQ,IAAI,CAACR,KAAK,GAAGQ,IAAI,CAACR,KAAK,GAAGL,aAAa,CAACK,KAAK;MAEnEL,aAAa,CAACC,SAAS,GAAGY,IAAI,CAACW,MAAM,CAACN,GAAG,CAAEO,KAA2C,KAAM;QAC1FL,GAAG,EAAEK,KAAK,CAACJ,IAAI;QACfK,IAAI,EAAED,KAAK,CAACE,KAAK,GAAGF,KAAK,CAACE,KAAK,GAAGF,KAAK,CAACG;MAC1C,CAAC,CAAC,CAAC;MAEH,OAAO;QACL1B,KAAK,EAAEF,aAAa,CAACE,KAAK;QAC1BG,KAAK,EAAEL,aAAa,CAACK,KAAK;QAC1BT,OAAO,EAAEI,aAAa,CAACJ,OAAO;QAC9BK,SAAS,EAAED,aAAa,CAACC;MAC3B,CAAC;IACH,CAAC,CAAC,OAAO4B,GAAG,EAAE;MACZ,MAAMA,GAAG;IACX;EACF;AACF;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcvC,SAAS","ignoreList":[]}