Recode pageListParse (#2205)

Find and replace placeholder images
This commit is contained in:
happywillow0 2020-02-07 18:43:31 -05:00 committed by GitHub
parent 49228e0114
commit fbcabbc15a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 6 deletions

View File

@ -5,8 +5,13 @@ ext {
appName = 'Tachiyomi: Mangahasu' appName = 'Tachiyomi: Mangahasu'
pkgNameSuffix = 'en.mangahasu' pkgNameSuffix = 'en.mangahasu'
extClass = '.Mangahasu' extClass = '.Mangahasu'
extVersionCode = 5 extVersionCode = 6
libVersion = '1.2' 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" apply from: "$rootDir/common.gradle"

View File

@ -1,5 +1,8 @@
package eu.kanade.tachiyomi.extension.en.mangahasu 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.network.GET
import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
@ -112,12 +115,31 @@ class Mangahasu: ParsedHttpSource() {
} }
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
val pages = mutableListOf<Page>()
var i = 0 //Grab All Pages from site
document.select("div.img img").forEach { element -> //Some images are place holders on new chapters.
i++
pages.add(Page(i, "", element.attr("src"))) val pages = mutableListOf<Page>().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 return pages
} }