From 98f69886ee478063431c707bc97026245ddf4b73 Mon Sep 17 00:00:00 2001 From: Vetle Ledaal Date: Sun, 2 Jan 2022 23:48:16 +0000 Subject: [PATCH] DigitalTeam: fix external images (#10310) --- src/it/digitalteam/build.gradle | 2 +- .../extension/it/digitalteam/DigitalTeam.kt | 41 ++++++++++++++----- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/it/digitalteam/build.gradle b/src/it/digitalteam/build.gradle index 2fbaa749c..6ec44efff 100644 --- a/src/it/digitalteam/build.gradle +++ b/src/it/digitalteam/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'DigitalTeam' pkgNameSuffix = 'it.digitalteam' extClass = '.DigitalTeam' - extVersionCode = 2 + extVersionCode = 3 } apply from: "$rootDir/common.gradle" diff --git a/src/it/digitalteam/src/eu/kanade/tachiyomi/extension/it/digitalteam/DigitalTeam.kt b/src/it/digitalteam/src/eu/kanade/tachiyomi/extension/it/digitalteam/DigitalTeam.kt index 8e937c8fa..f029dbcf7 100644 --- a/src/it/digitalteam/src/eu/kanade/tachiyomi/extension/it/digitalteam/DigitalTeam.kt +++ b/src/it/digitalteam/src/eu/kanade/tachiyomi/extension/it/digitalteam/DigitalTeam.kt @@ -107,17 +107,22 @@ class DigitalTeam : ParsedHttpSource() { } ?: 0 } - private fun getXhrPages(script_content: String, title: String): String { + private fun getXhrPages(script_content: String, title: String, external: Boolean): String { val infoManga = script_content.substringAfter("m='").substringBefore("'") val infoChapter = script_content.substringAfter("ch='").substringBefore("'") val infoChSub = script_content.substringAfter("chs='").substringBefore("'") - val formBody = FormBody.Builder() + val formBodyBuilder = FormBody.Builder() .add("info[manga]", infoManga) .add("info[chapter]", infoChapter) .add("info[ch_sub]", infoChSub) .add("info[title]", title) - .build() + + if (external) { + formBodyBuilder.add("info[external]", "1") + } + + val formBody = formBodyBuilder.build() val xhrHeaders = headersBuilder() .add("Content-Length", formBody.contentLength().toString()) @@ -139,18 +144,32 @@ class DigitalTeam : ParsedHttpSource() { .substringAfter("current_page=") .substringBefore(";") val title = document.select("title").first().text() + val external = document.select("script[src*='jq_rext.js']").isNotEmpty() - val xhrPages = getXhrPages(scriptContent, title) + val xhrPages = getXhrPages(scriptContent, title, external) val jsonResult = json.parseToJsonElement(xhrPages).jsonArray - val imageData = jsonResult[0].jsonArray - val imagePath = jsonResult[2].jsonPrimitive.content + val imageDatas = jsonResult[0].jsonArray + if (external) { + val imageBases = jsonResult[1].jsonArray - return jsonResult[1].jsonArray.mapIndexed { i, jsonEl -> - val imageUrl = "$baseUrl/reader$imagePath" + - imageData[i].jsonObject["name"]!!.jsonPrimitive.content + - jsonEl.jsonPrimitive.content + - imageData[i].jsonObject["ex"]!!.jsonPrimitive.content + return imageDatas.zip(imageBases).mapIndexed { i, (imageData, imageBase) -> + val imageUrl = imageBase.jsonPrimitive.content + + imageData.jsonObject["name"]!!.jsonPrimitive.content + + imageData.jsonObject["ex"]!!.jsonPrimitive.content + + Page(i, "", imageUrl) + } + } + + val imageSuffixes = jsonResult[1].jsonArray + val imageBase = jsonResult[2].jsonPrimitive.content + + return imageDatas.zip(imageSuffixes).mapIndexed { i, (imageData, imageSuffix) -> + val imageUrl = "$baseUrl/reader$imageBase" + + imageData.jsonObject["name"]!!.jsonPrimitive.content + + imageSuffix.jsonPrimitive.content + + imageData.jsonObject["ex"]!!.jsonPrimitive.content Page(i, "", imageUrl) }