From ec769a8c82c14fa7fb7085bd0fa488a8a47f8a5e Mon Sep 17 00:00:00 2001 From: MoistSac <74876786+MoistSac@users.noreply.github.com> Date: Mon, 23 Nov 2020 14:11:59 -0800 Subject: [PATCH] Update HentaiNexus (#4936) Update HentaiNexus --- src/en/hentainexus/build.gradle | 2 +- .../extension/en/hentainexus/HentaiNexus.kt | 39 +++++++++++++++++-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/en/hentainexus/build.gradle b/src/en/hentainexus/build.gradle index 218e0b46b..b565ecb07 100644 --- a/src/en/hentainexus/build.gradle +++ b/src/en/hentainexus/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'HentaiNexus' pkgNameSuffix = 'en.hentainexus' extClass = '.HentaiNexus' - extVersionCode = 3 + extVersionCode = 4 libVersion = '1.2' containsNsfw = true } diff --git a/src/en/hentainexus/src/eu/kanade/tachiyomi/extension/en/hentainexus/HentaiNexus.kt b/src/en/hentainexus/src/eu/kanade/tachiyomi/extension/en/hentainexus/HentaiNexus.kt index 88fb18a21..607b5f016 100644 --- a/src/en/hentainexus/src/eu/kanade/tachiyomi/extension/en/hentainexus/HentaiNexus.kt +++ b/src/en/hentainexus/src/eu/kanade/tachiyomi/extension/en/hentainexus/HentaiNexus.kt @@ -16,6 +16,12 @@ import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable import java.net.URLEncoder +import android.util.Base64 +import kotlin.experimental.xor +import com.google.gson.Gson +import com.google.gson.JsonElement +import com.google.gson.JsonObject +import com.google.gson.JsonParser @Nsfw class HentaiNexus : ParsedHttpSource() { @@ -194,13 +200,38 @@ class HentaiNexus : ParsedHttpSource() { override fun pageListParse(document: Document): List { return document.select("script:containsData(initreader)").first().data() - .substringAfter("[") - .substringBefore("]") - .replace(Regex("""["\\]"""), "") - .split(",") + .substringAfter("initReader(\"") + .substringBefore("\", 1") + .let(::decodePages) .mapIndexed { i, image -> Page(i, "", image) } } + private fun decodePages(code: String): List { + val hidden: ByteArray = Base64.decode(code, Base64.DEFAULT) + var key: ByteArray = hidden.sliceArray(0..63) + var body: ByteArray = hidden.sliceArray(64..hidden.size-1) + + val buf = StringBuilder() + + for (begin in 0 until body.size step 64) { + var chunk: ByteArray = body.sliceArray(begin..begin+63) + for (x in 0 until 64) { + buf.append((chunk[x] xor key[x]).toChar()) + } + key = chunk + } + + val json = JsonParser().parse(buf.toString()).asJsonObject + + val base = json.get("b").asString + val folder = json.get("r").asString + val id = json.get("i").asString + return json.get("f").asJsonArray.map { it -> + val page = it.asJsonObject + "${base}${folder}${page.get("h").asString}/${id}/${page.get("p").asString}" + } + } + override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") override fun getFilterList() = FilterList(