Tachiyomi-Extensions/multisrc/overrides/madara/doodmanga/src/Doodmanga.kt

55 lines
2.3 KiB
Kotlin
Raw Normal View History

2023-05-06 14:17:48 +00:00
package eu.kanade.tachiyomi.extension.th.doodmanga
import app.cash.quickjs.QuickJs
import eu.kanade.tachiyomi.multisrc.madara.Madara
import eu.kanade.tachiyomi.source.model.Page
import okhttp3.OkHttpClient
import org.jsoup.nodes.Document
import java.text.SimpleDateFormat
import java.util.Locale
class Doodmanga : Madara("Doodmanga", "https://www.doodmanga.com", "th", SimpleDateFormat("dd MMMMM yyyy", Locale("th"))) {
override val filterNonMangaItems = false
Random User-Agent Refactor (#17059) * lib-randomua * NHentai: Random mobile ua * Madara random UA overhaul * MangaThemesia random UA overhaul * MangaHub random UA overhaul * build errors and warnings * remove preference from Constellar * change to singleton object * network.client * fix copy paste and chapter deep link * exit early * use data class and enum options * missing import * suggested changes Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * re-add empty check to filters * convert to interceptor * update comment Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * update error message * initialize client by lazy * dont check on excluded Filters Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * newlines * move preference helper function into lib * move preference helper function into lib x2 * move check to lib too * move defaultRandomUserAgentType to constructor * rename the interceptor * organize the interceptor and preference stuff in different files * hide custom ua setting when random ua is enabled * English Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * catch specific exception Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * setVisible() fresh stuff * setVisible() fresh stuff * change summary * workaround * Update error message Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Update comment Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com>
2023-07-15 22:52:35 +00:00
override val client: OkHttpClient = super.client.newBuilder()
2023-05-06 14:17:48 +00:00
.addInterceptor(ScrambledImageInterceptor)
.build()
override val pageListParseSelector = "div.text-center > p > img, div.text-center > img, div.text-center > script"
override fun pageListParse(document: Document): List<Page> {
super.countViews(document)
return document.select(pageListParseSelector).mapIndexedNotNull { index, element ->
val src = when (element.tagName()) {
"img" -> element.attr("src")
"script" -> {
if (element.data().startsWith("eval(")) {
val quickJs = QuickJs.create()
val result = quickJs.evaluate(element.data().removePrefix("eval")) as String
quickJs.close()
val src = result.substringAfter("<img src='").substringBefore("'/>")
val sovleImage = result.substringAfter("var sovleImage=[[").substringBefore("]]").split("],[").map { values ->
values.replace("[", "").replace("]", "").split(",").map { it.removeSurrounding("\"") }
}
val segmentWidth = result.substringAfter("width:\"+").substringBefore("+\"px")
val segmentHeight = result.substringAfter("height: \"+").substringBefore("+\"px")
"$src?sovleImage=${sovleImage.joinToString("::") { (x, y, px, py) -> "$x,$y,$px,$py" }}&segmentWidth=$segmentWidth&segmentHeight=$segmentHeight"
} else {
null
}
}
else -> null
}
if (src == null) {
null
} else {
Page(index, document.location(), src)
}
}
}
}