Attempt to fix japscan extension (#6566)

This commit is contained in:
BayLee4 2021-04-15 20:30:28 +02:00 committed by GitHub
parent 73efe1501f
commit 59ef23a023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 28 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Japscan' extName = 'Japscan'
pkgNameSuffix = 'fr.japscan' pkgNameSuffix = 'fr.japscan'
extClass = '.Japscan' extClass = '.Japscan'
extVersionCode = 25 extVersionCode = 26
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -54,6 +54,7 @@ import java.text.ParseException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
import java.util.concurrent.CyclicBarrier
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.collections.List import kotlin.collections.List
import kotlin.collections.distinctBy import kotlin.collections.distinctBy
@ -62,7 +63,6 @@ import kotlin.collections.first
import kotlin.collections.forEach import kotlin.collections.forEach
import kotlin.collections.forEachIndexed import kotlin.collections.forEachIndexed
import kotlin.collections.map import kotlin.collections.map
import kotlin.collections.mapIndexed
import kotlin.collections.mutableListOf import kotlin.collections.mutableListOf
import kotlin.collections.toTypedArray import kotlin.collections.toTypedArray
@ -364,53 +364,66 @@ class Japscan : ConfigurableSource, ParsedHttpSource() {
} }
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
return if (document.getElementsByTag("script").filter { it.attr("src").contains("ujs") }.size > 2) { // scrambled images, webview screenshotting // no webview screenshot needed anymore :
Log.d("japscan", "scrambled, loading in WVSC urls") // document.getElementsByTag("option").mapIndexed { i, it -> Page(i, "", baseUrl + it.attr("value") + "&wvsc") }
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") val zjsurl = document.getElementsByTag("script").first { it.attr("src").contains("zjs", ignoreCase = true) }.attr("src")
Log.d("japscan", "ZJS at $zjsurl") Log.d("japscan", "ZJS at $zjsurl")
val zjs = client.newCall(GET(baseUrl + zjsurl, headers)).execute().body()!!.string() 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") Log.d("japscan", "webtoon, netdumping initiated")
val pagecount = document.getElementsByTag("option").size val pagecount = document.getElementsByTag("option").size
val pages = ArrayList<Page>() val pages = ArrayList<Page>()
val handler = Handler(Looper.getMainLooper()) val handler = Handler(Looper.getMainLooper())
val latch = CountDownLatch(1) val checkNew = ArrayList<String>(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 dummyimage = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
val dummystream = ByteArrayOutputStream() val dummystream = ByteArrayOutputStream()
dummyimage.compress(Bitmap.CompressFormat.JPEG, 100, dummystream) dummyimage.compress(Bitmap.CompressFormat.JPEG, 100, dummystream)
val barrier = CyclicBarrier(2)
for (i in 0 until maxIter) {
handler.post { handler.post {
if (webView == null) {
val webview = WebView(Injekt.get<Application>()) val webview = WebView(Injekt.get<Application>())
webView = webview
webview.settings.javaScriptEnabled = true webview.settings.javaScriptEnabled = true
webview.settings.domStorageEnabled = true webview.settings.domStorageEnabled = true
webview.settings.userAgentString = webview.settings.userAgentString.replace("Mobile", "eliboM").replace("Android", "diordnA")
webview.webViewClient = object : WebViewClient() { webview.webViewClient = object : WebViewClient() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @TargetApi(Build.VERSION_CODES.LOLLIPOP)
override fun shouldInterceptRequest( override fun shouldInterceptRequest(
view: WebView, view: WebView,
request: WebResourceRequest request: WebResourceRequest
): WebResourceResponse? { ): 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())) pages.add(Page(pages.size, "", request.url.toString()))
Log.d("japscan", "intercepted ${request.url}") 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 WebResourceResponse("image/jpeg", "UTF-8", ByteArrayInputStream(dummystream.toByteArray()))
} }
return super.shouldInterceptRequest(view, request) return super.shouldInterceptRequest(view, request)
} }
} }
webview.loadUrl(baseUrl + document.getElementsByTag("option").first().attr("value"))
} }
latch.await() 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 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") }
}
}
} }
override fun imageUrlParse(document: Document): String = "" override fun imageUrlParse(document: Document): String = ""