diff --git a/src/en/mangahasu/build.gradle b/src/en/mangahasu/build.gradle index 81da5016a..6795d513e 100644 --- a/src/en/mangahasu/build.gradle +++ b/src/en/mangahasu/build.gradle @@ -5,8 +5,13 @@ ext { appName = 'Tachiyomi: Mangahasu' pkgNameSuffix = 'en.mangahasu' extClass = '.Mangahasu' - extVersionCode = 5 + extVersionCode = 6 libVersion = '1.2' } +dependencies { + compileOnly 'com.google.code.gson:gson:2.8.5' + compileOnly 'com.github.salomonbrys.kotson:kotson:2.5.0' +} + apply from: "$rootDir/common.gradle" diff --git a/src/en/mangahasu/src/eu/kanade/tachiyomi/extension/en/mangahasu/Mangahasu.kt b/src/en/mangahasu/src/eu/kanade/tachiyomi/extension/en/mangahasu/Mangahasu.kt index af2242922..ff72f44dd 100644 --- a/src/en/mangahasu/src/eu/kanade/tachiyomi/extension/en/mangahasu/Mangahasu.kt +++ b/src/en/mangahasu/src/eu/kanade/tachiyomi/extension/en/mangahasu/Mangahasu.kt @@ -1,5 +1,8 @@ package eu.kanade.tachiyomi.extension.en.mangahasu +import android.util.Base64 +import com.github.salomonbrys.kotson.* +import com.google.gson.JsonParser import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.Page @@ -112,12 +115,31 @@ class Mangahasu: ParsedHttpSource() { } override fun pageListParse(document: Document): List { - val pages = mutableListOf() - var i = 0 - document.select("div.img img").forEach { element -> - i++ - pages.add(Page(i, "", element.attr("src"))) + + //Grab All Pages from site + //Some images are place holders on new chapters. + + val pages = mutableListOf().apply { + document.select("div.img img").forEach { + val pageNumber = it.attr("class").substringAfter("page").toInt() + add(Page(pageNumber,"",it.attr("src"))) + } } + + //Some images are not yet loaded onto Mangahasu's image server. + //Decode temporary URLs and replace placeholder images. + + val lstDUrls = document.select("script:containsData(lstDUrls)").html().substringAfter("lstDUrls").substringAfter("\"").substringBefore("\"") + if (lstDUrls != "W10="){ //Base64 = [] or empty file + val decoded = String(Base64.decode(lstDUrls,Base64.DEFAULT)) + val json = JsonParser().parse(decoded).array + json.forEach { + val pageNumber = it["page"].int + pages.removeAll { page -> page.index == pageNumber } + pages.add(Page(pageNumber,"",it["url"].string)) + } + } + pages.sortBy { page -> page.index } return pages }