From 1213241bb6ce0cfd0d91b0100a9f56b82a1ee229 Mon Sep 17 00:00:00 2001 From: beerpsi <92439990+beerpiss@users.noreply.github.com> Date: Sun, 29 Jan 2023 11:20:15 +0700 Subject: [PATCH] [constellar] wow another one (#15164) * at some point this gonna surpass asura * unused code * useless assignment --- .../constellarscans/src/ConstellarScans.kt | 67 +++++++++++++------ .../mangathemesia/MangaThemesiaGenerator.kt | 2 +- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt b/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt index 97e64c2d9..e9c4e618e 100644 --- a/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt +++ b/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt @@ -6,7 +6,9 @@ import android.os.Handler import android.os.Looper import android.util.Log import android.view.View +import android.webkit.ConsoleMessage import android.webkit.JavascriptInterface +import android.webkit.WebChromeClient import android.webkit.WebView import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.GET @@ -70,12 +72,11 @@ class ConstellarScans : MangaThemesia("Constellar Scans", "https://constellarsca .cacheControl(CacheControl.FORCE_NETWORK) .build() - internal class JsObject(private val latch: CountDownLatch, var tsData: String = "") { + internal class JsObject(val imageList: MutableList = mutableListOf()) { @JavascriptInterface - fun passData(tsData: String) { - Log.d("constellarscans", "received ts_reader.run data: $tsData") - this.tsData = tsData - latch.countDown() + fun passSingleImage(url: String) { + Log.d("constellarscans", "received image: $url") + imageList.add(url) } } @@ -90,18 +91,26 @@ class ConstellarScans : MangaThemesia("Constellar Scans", "https://constellarsca document.body().prepend( """ - | - """.trimMargin() + + """.trimIndent() ) val handler = Handler(Looper.getMainLooper()) val latch = CountDownLatch(1) - val jsinterface = JsObject(latch) + val jsInterface = JsObject() var webView: WebView? = null handler.post { val webview = WebView(Injekt.get()) @@ -112,17 +121,37 @@ class ConstellarScans : MangaThemesia("Constellar Scans", "https://constellarsca webview.settings.useWideViewPort = false webview.settings.loadWithOverviewMode = false webview.settings.userAgentString = mobileUserAgent - webview.addJavascriptInterface(jsinterface, interfaceName) + webview.addJavascriptInterface(jsInterface, interfaceName) + + webview.webChromeClient = object : WebChromeClient() { + override fun onProgressChanged(view: WebView?, newProgress: Int) { + if (newProgress >= 90) { + latch.countDown() + } + } + + override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean { + if (consoleMessage == null) { return false } + val logContent = "wv: ${consoleMessage.message()} ${consoleMessage.sourceId()}, line ${consoleMessage.lineNumber()}" + when (consoleMessage.messageLevel()) { + ConsoleMessage.MessageLevel.DEBUG -> Log.d("constellarscans", logContent) + ConsoleMessage.MessageLevel.ERROR -> Log.e("constellarscans", logContent) + ConsoleMessage.MessageLevel.LOG -> Log.i("constellarscans", logContent) + ConsoleMessage.MessageLevel.TIP -> Log.i("constellarscans", logContent) + ConsoleMessage.MessageLevel.WARNING -> Log.w("constellarscans", logContent) + else -> Log.d("constellarscans", logContent) + } + + return true + } + } Log.d("constellarscans", "starting webview shenanigans") webview.loadDataWithBaseURL(baseUrl, document.toString(), "text/html", "UTF-8", null) } latch.await() handler.post { webView?.destroy() } - val tsData = json.parseToJsonElement(jsinterface.tsData).jsonObject - return tsData["sources"]!!.jsonArray[0].jsonObject["images"]!!.jsonArray.mapIndexed { idx, it -> - Page(idx, imageUrl = it.jsonPrimitive.content) - } + return jsInterface.imageList.mapIndexed { idx, it -> Page(idx, imageUrl = it) } } override fun imageRequest(page: Page): Request = super.imageRequest(page).newBuilder() diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt index b824a82d9..3d4f4206a 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt @@ -25,7 +25,7 @@ class MangaThemesiaGenerator : ThemeSourceGenerator { SingleLang("Azure Scans", "https://azuremanga.com", "en", overrideVersionCode = 1), SingleLang("Boosei", "https://boosei.net", "id", overrideVersionCode = 2), SingleLang("Clayrer", "https://clayrer.net", "es"), - SingleLang("Constellar Scans", "https://constellarscans.com", "en", isNsfw = true, overrideVersionCode = 10), + SingleLang("Constellar Scans", "https://constellarscans.com", "en", isNsfw = true, overrideVersionCode = 11), SingleLang("Cosmic Scans", "https://cosmicscans.com", "en", overrideVersionCode = 1), SingleLang("Diskus Scan", "https://diskusscan.com", "pt-BR", overrideVersionCode = 7), SingleLang("Dojing.net", "https://dojing.net", "id", isNsfw = true, className = "DojingNet"),