diff --git a/src/fr/japscan/build.gradle b/src/fr/japscan/build.gradle index 37572d353..ee6b84753 100644 --- a/src/fr/japscan/build.gradle +++ b/src/fr/japscan/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Japscan' pkgNameSuffix = 'fr.japscan' extClass = '.Japscan' - extVersionCode = 25 + extVersionCode = 26 libVersion = '1.2' } diff --git a/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt b/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt index f34cbd7d6..18304d93b 100644 --- a/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt +++ b/src/fr/japscan/src/eu/kanade/tachiyomi/extension/fr/japscan/Japscan.kt @@ -54,6 +54,7 @@ import java.text.ParseException import java.text.SimpleDateFormat import java.util.Locale import java.util.concurrent.CountDownLatch +import java.util.concurrent.CyclicBarrier import kotlin.collections.ArrayList import kotlin.collections.List import kotlin.collections.distinctBy @@ -62,7 +63,6 @@ import kotlin.collections.first import kotlin.collections.forEach import kotlin.collections.forEachIndexed import kotlin.collections.map -import kotlin.collections.mapIndexed import kotlin.collections.mutableListOf import kotlin.collections.toTypedArray @@ -364,53 +364,66 @@ class Japscan : ConfigurableSource, ParsedHttpSource() { } override fun pageListParse(document: Document): List { - return if (document.getElementsByTag("script").filter { it.attr("src").contains("ujs") }.size > 2) { // scrambled images, webview screenshotting - Log.d("japscan", "scrambled, loading in WVSC urls") - document.getElementsByTag("option").mapIndexed { i, it -> Page(i, "", baseUrl + it.attr("value") + "&wvsc") } - } else { - // unscrambled images, check for single page - val zjsurl = document.getElementsByTag("script").first { it.attr("src").contains("zjs", ignoreCase = true) }.attr("src") - Log.d("japscan", "ZJS at $zjsurl") - val zjs = client.newCall(GET(baseUrl + zjsurl, headers)).execute().body()!!.string() - if ((zjs.toLowerCase().split("new image").size - 1) == 1) { // single page, webview request dumping - Log.d("japscan", "webtoon, netdumping initiated") - val pagecount = document.getElementsByTag("option").size - val pages = ArrayList() - val handler = Handler(Looper.getMainLooper()) - val latch = CountDownLatch(1) + // no webview screenshot needed anymore : + // document.getElementsByTag("option").mapIndexed { i, it -> Page(i, "", baseUrl + it.attr("value") + "&wvsc") } - val dummyimage = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) - val dummystream = ByteArrayOutputStream() - dummyimage.compress(Bitmap.CompressFormat.JPEG, 100, dummystream) + val zjsurl = document.getElementsByTag("script").first { it.attr("src").contains("zjs", ignoreCase = true) }.attr("src") + Log.d("japscan", "ZJS at $zjsurl") + val zjs = client.newCall(GET(baseUrl + zjsurl, headers)).execute().body()!!.string() + Log.d("japscan", "webtoon, netdumping initiated") + val pagecount = document.getElementsByTag("option").size + val pages = ArrayList() + val handler = Handler(Looper.getMainLooper()) + val checkNew = ArrayList(pagecount) + var maxIter = document.getElementsByTag("option").size + var isSinglePage = false + if ((zjs.toLowerCase().split("new image").size - 1) == 1) { + isSinglePage = true + maxIter = 1 + } + var webView: WebView? = null + val dummyimage = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888) + val dummystream = ByteArrayOutputStream() + dummyimage.compress(Bitmap.CompressFormat.JPEG, 100, dummystream) + val barrier = CyclicBarrier(2) - handler.post { + for (i in 0 until maxIter) { + handler.post { + if (webView == null) { val webview = WebView(Injekt.get()) + webView = webview webview.settings.javaScriptEnabled = true webview.settings.domStorageEnabled = true + webview.settings.userAgentString = webview.settings.userAgentString.replace("Mobile", "eliboM").replace("Android", "diordnA") webview.webViewClient = object : WebViewClient() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) override fun shouldInterceptRequest( view: WebView, request: WebResourceRequest ): WebResourceResponse? { - if (request.url.toString().startsWith("https://c.")) { + if (request.url.toString().startsWith("https://cdn.statically.io/img/c.japscan.se/") && !checkNew.contains(request.url.toString())) { + checkNew.add(request.url.toString()) pages.add(Page(pages.size, "", request.url.toString())) Log.d("japscan", "intercepted ${request.url}") - if (pages.size == pagecount) { latch.countDown() } + if (pages.size == pagecount || !isSinglePage) { + barrier.await() + } return WebResourceResponse("image/jpeg", "UTF-8", ByteArrayInputStream(dummystream.toByteArray())) } return super.shouldInterceptRequest(view, request) } } - webview.loadUrl(baseUrl + document.getElementsByTag("option").first().attr("value")) } - latch.await() - return pages - } else { // page by page, just do webview screenshotting because it's easier - Log.d("japscan", "unscrambled, loading WVSC urls") - document.getElementsByTag("option").mapIndexed { i, it -> Page(i, "", baseUrl + it.attr("value") + "&wvsc") } + if (isSinglePage) { + webView?.loadUrl(baseUrl + document.select("li[^data-]").first().dataset()["chapter-url"]) + } else { + webView?.loadUrl(baseUrl + document.getElementsByTag("option")[i].attr("value")) + } } + barrier.await() } + handler.post { webView!!.destroy() } + return pages } override fun imageUrlParse(document: Document): String = ""