forked from aniyomiorg/aniyomi-extensions
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(tr/HentaiZM): Update Source and update extractor MegaCloudExtract…
…or (#176)
- Loading branch information
Showing
7 changed files
with
1,441 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
606 changes: 606 additions & 0 deletions
606
lib/megacloud-extractor/src/main/assets/megacloud.decodedpng.js
Large diffs are not rendered by default.
Oops, something went wrong.
714 changes: 714 additions & 0 deletions
714
lib/megacloud-extractor/src/main/assets/megacloud.getsrcs.js
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
...oud-extractor/src/main/java/eu/kanade/tachiyomi/lib/megacloudextractor/WebViewResolver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package eu.kanade.tachiyomi.lib.megacloudextractor | ||
|
||
import android.annotation.SuppressLint | ||
import android.app.Application | ||
import android.os.Handler | ||
import android.os.Looper | ||
import android.util.Log | ||
import android.webkit.ConsoleMessage | ||
import android.webkit.JavascriptInterface | ||
import android.webkit.WebChromeClient | ||
import android.webkit.WebView | ||
import android.webkit.WebViewClient | ||
import eu.kanade.tachiyomi.lib.megacloudextractor.MegaCloudExtractor.VideoDto | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.Headers | ||
import uy.kohesive.injekt.injectLazy | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
class WebViewResolver(private val globalHeaders: Headers) { | ||
private val context: Application by injectLazy() | ||
private val handler by lazy { Handler(Looper.getMainLooper()) } | ||
private val json: Json by injectLazy() | ||
private val tag by lazy { javaClass.simpleName } | ||
|
||
class JsInterface(private val latch: CountDownLatch) { | ||
var result: String? = null | ||
|
||
@JavascriptInterface | ||
fun setResponse(response: String) { | ||
Log.d("WebViewResolver", "script result: $response") | ||
result = response | ||
latch.countDown() | ||
} | ||
} | ||
|
||
fun getJsContent(file: String): String { | ||
return javaClass.getResource(file)!!.readText() | ||
} | ||
|
||
@SuppressLint("SetJavaScriptEnabled") | ||
fun getSources(xrax: String): VideoDto? { | ||
val latch = CountDownLatch(1) | ||
var webView: WebView? = null | ||
val jsi = JsInterface(latch) | ||
|
||
handler.post { | ||
val webview = WebView(context) | ||
webView = webview | ||
with(webview.settings) { | ||
javaScriptEnabled = true | ||
domStorageEnabled = true | ||
databaseEnabled = true | ||
useWideViewPort = false | ||
loadWithOverviewMode = false | ||
userAgentString = globalHeaders["User-Agent"] | ||
} | ||
|
||
webview.addJavascriptInterface(jsi, "jsinterface") | ||
|
||
webview.webViewClient = object : WebViewClient() { | ||
override fun onPageFinished(view: WebView?, url: String?) { | ||
Log.d(tag, "onPageFinished $url") | ||
super.onPageFinished(view, url) | ||
|
||
Log.d(tag, "injecting scripts") | ||
view?.evaluateJavascript(getJsContent("/assets/crypto-js.js")) {} | ||
view?.evaluateJavascript(getJsContent("/assets/megacloud.decodedpng.js")) {} | ||
view?.evaluateJavascript(getJsContent("/assets/megacloud.getsrcs.js")) {} | ||
|
||
Log.d(tag, "running script") | ||
view?.evaluateJavascript( | ||
"getSources(\"${xrax}\")" + | ||
".then( s => jsinterface.setResponse( JSON.stringify(s) ) )", | ||
) {} | ||
} | ||
} | ||
|
||
webview.webChromeClient = object : WebChromeClient() { | ||
override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean { | ||
Log.d( | ||
tag, | ||
"Chrome: [${consoleMessage?.messageLevel()}]" + | ||
"${consoleMessage?.message()}" + | ||
" at ${consoleMessage?.lineNumber()}" + | ||
" in ${consoleMessage?.sourceId()}", | ||
) | ||
return super.onConsoleMessage(consoleMessage) | ||
} | ||
} | ||
|
||
val headers = mapOf("X-Requested-With" to "org.lineageos.jelly") | ||
|
||
webView?.loadUrl("https://megacloud.tv/about", headers) | ||
} | ||
|
||
latch.await(TIMEOUT_SEC, TimeUnit.SECONDS) | ||
|
||
handler.post { | ||
webView?.stopLoading() | ||
webView?.destroy() | ||
webView = null | ||
} | ||
|
||
return jsi.result?.let { json.decodeFromString<VideoDto>(it) } | ||
} | ||
|
||
companion object { | ||
const val TIMEOUT_SEC: Long = 30 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
ext { | ||
extName = 'HentaiZM' | ||
extClass = '.HentaiZM' | ||
extVersionCode = 6 | ||
extVersionCode = 7 | ||
isNsfw = true | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters