2021-05-31 23:03:34 +00:00
|
|
|
package eu.kanade.tachiyomi.extension.pt.cerisescans
|
|
|
|
|
2023-01-23 03:39:45 +00:00
|
|
|
import android.util.Base64
|
|
|
|
import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES
|
2021-05-31 23:03:34 +00:00
|
|
|
import eu.kanade.tachiyomi.multisrc.madara.Madara
|
2022-06-05 21:51:18 +00:00
|
|
|
import eu.kanade.tachiyomi.network.interceptor.rateLimit
|
2023-01-23 03:39:45 +00:00
|
|
|
import eu.kanade.tachiyomi.source.model.Page
|
|
|
|
import kotlinx.serialization.json.jsonArray
|
|
|
|
import kotlinx.serialization.json.jsonObject
|
|
|
|
import kotlinx.serialization.json.jsonPrimitive
|
2021-05-31 23:03:34 +00:00
|
|
|
import okhttp3.OkHttpClient
|
2023-01-23 03:39:45 +00:00
|
|
|
import org.jsoup.nodes.Document
|
2021-05-31 23:03:34 +00:00
|
|
|
import java.text.SimpleDateFormat
|
|
|
|
import java.util.Locale
|
|
|
|
import java.util.concurrent.TimeUnit
|
|
|
|
|
|
|
|
class CeriseScans : Madara(
|
|
|
|
"Cerise Scans",
|
2022-10-31 21:43:21 +00:00
|
|
|
"https://cerisescan.com",
|
2021-05-31 23:03:34 +00:00
|
|
|
"pt-BR",
|
2022-10-31 21:43:21 +00:00
|
|
|
SimpleDateFormat("dd/MM/yyyy", Locale("pt", "BR"))
|
2021-05-31 23:03:34 +00:00
|
|
|
) {
|
|
|
|
|
|
|
|
override val client: OkHttpClient = super.client.newBuilder()
|
2022-06-05 21:51:18 +00:00
|
|
|
.rateLimit(1, 2, TimeUnit.SECONDS)
|
2021-05-31 23:03:34 +00:00
|
|
|
.build()
|
2022-10-31 21:43:21 +00:00
|
|
|
|
|
|
|
override val useNewChapterEndpoint = true
|
2023-01-23 03:39:45 +00:00
|
|
|
|
|
|
|
override fun pageListParse(document: Document): List<Page> {
|
|
|
|
val chapterProtector = document.getElementById("chapter-protector-data")?.html()
|
|
|
|
?: return super.pageListParse(document)
|
|
|
|
|
|
|
|
val password = chapterProtector
|
|
|
|
.substringAfter("wpmangaprotectornonce='")
|
|
|
|
.substringBefore("';")
|
|
|
|
val chapterData = json.parseToJsonElement(
|
|
|
|
chapterProtector
|
|
|
|
.substringAfter("chapter_data='")
|
|
|
|
.substringBefore("';")
|
|
|
|
.replace("\\/", "/")
|
|
|
|
).jsonObject
|
|
|
|
|
|
|
|
val unsaltedCiphertext = Base64.decode(chapterData["ct"]!!.jsonPrimitive.content, Base64.DEFAULT)
|
|
|
|
val salt = chapterData["s"]!!.jsonPrimitive.content.decodeHex()
|
|
|
|
val ciphertext = SALTED + salt + unsaltedCiphertext
|
|
|
|
|
|
|
|
val rawImgArray = CryptoAES.decrypt(Base64.encodeToString(ciphertext, Base64.DEFAULT), password)
|
|
|
|
val imgArrayString = json.parseToJsonElement(rawImgArray).jsonPrimitive.content
|
|
|
|
val imgArray = json.parseToJsonElement(imgArrayString).jsonArray
|
|
|
|
|
|
|
|
return imgArray.mapIndexed { idx, it ->
|
|
|
|
Page(idx, document.location(), it.jsonPrimitive.content)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/66614516
|
|
|
|
private fun String.decodeHex(): ByteArray {
|
|
|
|
check(length % 2 == 0) { "Must have an even length" }
|
|
|
|
|
|
|
|
return chunked(2)
|
|
|
|
.map { it.toInt(16).toByte() }
|
|
|
|
.toByteArray()
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
val SALTED = "Salted__".toByteArray(Charsets.UTF_8)
|
|
|
|
}
|
2021-05-31 23:03:34 +00:00
|
|
|
}
|