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
|
2022-08-16 11:24:35 +00:00
|
|
|
import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia
|
2022-06-05 21:51:18 +00:00
|
|
|
import eu.kanade.tachiyomi.network.interceptor.rateLimit
|
2021-12-27 18:38:18 +00:00
|
|
|
import eu.kanade.tachiyomi.source.model.Page
|
|
|
|
import kotlinx.serialization.json.jsonArray
|
|
|
|
import kotlinx.serialization.json.jsonPrimitive
|
2021-02-16 11:36:04 +00:00
|
|
|
import okhttp3.OkHttpClient
|
2021-12-27 18:38:18 +00:00
|
|
|
import org.jsoup.nodes.Document
|
2022-08-16 11:24:35 +00:00
|
|
|
import java.lang.IllegalArgumentException
|
2021-02-16 11:36:04 +00:00
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
2022-08-16 11:24:35 +00:00
|
|
|
class xCaliBRScans : MangaThemesia("xCaliBR Scans", "https://xcalibrscans.com", "en") {
|
2021-02-16 11:36:04 +00:00
|
|
|
|
|
|
|
override val client: OkHttpClient = network.cloudflareClient.newBuilder()
|
|
|
|
.connectTimeout(10, TimeUnit.SECONDS)
|
|
|
|
.readTimeout(30, TimeUnit.SECONDS)
|
2022-06-05 21:51:18 +00:00
|
|
|
.rateLimit(2)
|
2021-12-27 18:38:18 +00:00
|
|
|
.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"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-16 11:24:35 +00:00
|
|
|
countViews(document)
|
2021-12-27 18:38:18 +00:00
|
|
|
|
2022-08-16 11:24:35 +00:00
|
|
|
// Some sites also loads pages via javascript
|
|
|
|
if (htmlPages.isNotEmpty()) { return htmlPages }
|
2021-12-27 18:38:18 +00:00
|
|
|
|
2022-08-16 11:24:35 +00:00
|
|
|
val docString = document.toString()
|
|
|
|
val imageListJson = JSON_IMAGE_LIST_REGEX.find(docString)?.destructured?.toList()?.get(0).orEmpty()
|
|
|
|
val imageList = try {
|
|
|
|
json.parseToJsonElement(imageListJson).jsonArray
|
|
|
|
} catch (_: IllegalArgumentException) {
|
|
|
|
emptyList()
|
2021-12-27 18:38:18 +00:00
|
|
|
}
|
2022-08-16 11:24:35 +00:00
|
|
|
val scriptPages = imageList.mapIndexed { i, jsonEl ->
|
|
|
|
Page(i, "", jsonEl.jsonPrimitive.content)
|
2021-12-27 18:38:18 +00:00
|
|
|
}
|
|
|
|
|
2022-08-16 11:24:35 +00:00
|
|
|
return scriptPages
|
2021-12-27 18:38:18 +00:00
|
|
|
}
|
2021-02-16 11:36:04 +00:00
|
|
|
}
|