Attempt to fix japscan extension (#6566)
This commit is contained in:
parent
73efe1501f
commit
59ef23a023
|
@ -5,7 +5,7 @@ ext {
|
|||
extName = 'Japscan'
|
||||
pkgNameSuffix = 'fr.japscan'
|
||||
extClass = '.Japscan'
|
||||
extVersionCode = 25
|
||||
extVersionCode = 26
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Page> {
|
||||
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
|
||||
// no webview screenshot needed anymore :
|
||||
// document.getElementsByTag("option").mapIndexed { i, it -> Page(i, "", baseUrl + it.attr("value") + "&wvsc") }
|
||||
|
||||
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<Page>()
|
||||
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 dummystream = ByteArrayOutputStream()
|
||||
dummyimage.compress(Bitmap.CompressFormat.JPEG, 100, dummystream)
|
||||
val barrier = CyclicBarrier(2)
|
||||
|
||||
for (i in 0 until maxIter) {
|
||||
handler.post {
|
||||
if (webView == null) {
|
||||
val webview = WebView(Injekt.get<Application>())
|
||||
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()
|
||||
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
|
||||
} 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 = ""
|
||||
|
|
Loading…
Reference in New Issue