2021-02-16 11:36:04 +00:00
|
|
|
package eu.kanade.tachiyomi.extension.en.xcalibrscans
|
|
|
|
|
2021-12-27 18:38:18 +00:00
|
|
|
import eu.kanade.tachiyomi.extension.en.xcalibrscans.interceptor.MirrorImageInterceptor
|
|
|
|
import eu.kanade.tachiyomi.extension.en.xcalibrscans.interceptor.SplittedImageInterceptor
|
|
|
|
import eu.kanade.tachiyomi.extension.en.xcalibrscans.interceptor.prepareMirrorImageForInterceptor
|
|
|
|
import eu.kanade.tachiyomi.extension.en.xcalibrscans.interceptor.prepareSplittedImageForInterceptor
|
2021-02-16 11:36:04 +00:00
|
|
|
import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor
|
|
|
|
import eu.kanade.tachiyomi.multisrc.wpmangastream.WPMangaStream
|
2021-12-27 18:38:18 +00:00
|
|
|
import eu.kanade.tachiyomi.source.model.Page
|
|
|
|
import kotlinx.serialization.json.Json
|
|
|
|
import kotlinx.serialization.json.jsonArray
|
|
|
|
import kotlinx.serialization.json.jsonPrimitive
|
|
|
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
2021-02-16 11:36:04 +00:00
|
|
|
import okhttp3.OkHttpClient
|
2021-12-27 18:38:18 +00:00
|
|
|
import org.jsoup.nodes.Document
|
|
|
|
import uy.kohesive.injekt.injectLazy
|
2021-02-16 11:36:04 +00:00
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
2021-03-28 11:11:51 +00:00
|
|
|
class xCaliBRScans : WPMangaStream("xCaliBR Scans", "https://xcalibrscans.com", "en") {
|
2021-12-27 18:38:18 +00:00
|
|
|
private val json: Json by injectLazy()
|
2021-02-16 11:36:04 +00:00
|
|
|
|
|
|
|
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
|
|
|
.connectTimeout(10, TimeUnit.SECONDS)
|
|
|
|
.readTimeout(30, TimeUnit.SECONDS)
|
2021-12-27 18:38:18 +00:00
|
|
|
.addNetworkInterceptor(RateLimitInterceptor(2))
|
|
|
|
.addNetworkInterceptor(SplittedImageInterceptor())
|
|
|
|
.addNetworkInterceptor(MirrorImageInterceptor())
|
2021-02-16 11:36:04 +00:00
|
|
|
.build()
|
|
|
|
|
2021-06-08 21:51:36 +00:00
|
|
|
override val hasProjectPage = true
|
2021-12-27 18:38:18 +00:00
|
|
|
|
|
|
|
override val pageSelector = "div#readerarea > p, div#readerarea > div"
|
|
|
|
|
|
|
|
override fun pageListParse(document: Document): List<Page> {
|
|
|
|
val htmlPages = mutableListOf<Page>()
|
|
|
|
|
|
|
|
document.select(pageSelector)
|
|
|
|
.filterNot {
|
|
|
|
it.select("img").all { imgEl ->
|
|
|
|
imgEl.attr("abs:src").isNullOrEmpty()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.map { el ->
|
|
|
|
if (el.tagName() == "div") {
|
|
|
|
when {
|
|
|
|
el.hasClass("kage") -> {
|
|
|
|
el.select("img").map { imgEl ->
|
|
|
|
val index = htmlPages.size
|
|
|
|
val imageUrl =
|
|
|
|
imgEl.attr("abs:src").prepareMirrorImageForInterceptor()
|
|
|
|
htmlPages.add(Page(index, "", imageUrl))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
el.hasClass("row") -> {
|
|
|
|
val index = htmlPages.size
|
|
|
|
val imageUrls = el.select("img").map { imgEl ->
|
|
|
|
imgEl.attr("abs:src")
|
|
|
|
}.prepareSplittedImageForInterceptor()
|
|
|
|
htmlPages.add(Page(index, "", imageUrls))
|
|
|
|
}
|
|
|
|
else -> {
|
|
|
|
val index = htmlPages.size
|
|
|
|
Page(index, "", el.select("img").attr("abs:src"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
val index = htmlPages.size
|
|
|
|
Page(index, "", el.select("img").attr("abs:src"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
val docString = document.toString()
|
|
|
|
val imageListRegex = Regex("\\\"images.*?:.*?(\\[.*?\\])")
|
|
|
|
val imageListJson = imageListRegex.find(docString)!!.destructured.toList()[0]
|
|
|
|
|
|
|
|
val imageList = json.parseToJsonElement(imageListJson).jsonArray
|
|
|
|
val baseResolver = baseUrl.toHttpUrl()
|
|
|
|
|
|
|
|
val scriptPages = imageList.mapIndexed { i, jsonEl ->
|
|
|
|
val imageUrl = jsonEl.jsonPrimitive.content
|
|
|
|
Page(i, "", baseResolver.resolve(imageUrl).toString())
|
|
|
|
}
|
|
|
|
|
|
|
|
if (htmlPages.size < scriptPages.size) {
|
|
|
|
htmlPages += scriptPages
|
|
|
|
}
|
|
|
|
|
|
|
|
countViews(document)
|
|
|
|
|
|
|
|
return htmlPages.distinctBy { it.imageUrl }
|
|
|
|
}
|
2021-02-16 11:36:04 +00:00
|
|
|
}
|