Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tr/HentaiZM): Update Source and update extractor MegaCloudExtractor #176

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/megacloud-extractor/src/main/assets/crypto-js.js

Large diffs are not rendered by default.

606 changes: 606 additions & 0 deletions lib/megacloud-extractor/src/main/assets/megacloud.decodedpng.js

Large diffs are not rendered by default.

714 changes: 714 additions & 0 deletions lib/megacloud-extractor/src/main/assets/megacloud.getsrcs.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class MegaCloudExtractor(
private val json: Json by injectLazy()

private val playlistUtils by lazy { PlaylistUtils(client, headers) }
private val webViewResolver by lazy { WebViewResolver(headers) }

private val cacheControl = CacheControl.Builder().noStore().build()
private val noCacheClient = client.newBuilder()
Expand Down Expand Up @@ -141,10 +142,16 @@ class MegaCloudExtractor(

private fun getVideoDto(url: String): VideoDto {
val type = if (url.startsWith("https://megacloud.tv")) 0 else 1

val keyType = SOURCES_KEY[type]

val id = url.substringAfter(SOURCES_SPLITTER[type], "")
.substringBefore("?", "").ifEmpty { throw Exception("I HATE THE ANTICHRIST") }

if (type == 0) {
return webViewResolver.getSources(id)!!
}

val srcRes = client.newCall(GET(SERVER_URL[type] + SOURCES_URL[type] + id))
.execute()
.body.string()
Expand Down
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
}
}
2 changes: 1 addition & 1 deletion src/tr/hentaizm/build.gradle
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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class HentaiZM : ParsedAnimeHttpSource(), ConfigurableAnimeSource {

override val name = "HentaiZM"

override val baseUrl = "https://www.hentaizm.fun"
override val baseUrl = "https://www.hentaizm3.online/"

override val lang = "tr"

Expand Down
Loading