Fix chapters not loading at SuperHentais. (#3752)
This commit is contained in:
parent
6a44953465
commit
68620cd051
|
@ -5,7 +5,7 @@ ext {
|
|||
extName = 'Super Mangás'
|
||||
pkgNameSuffix = 'pt.supermangas'
|
||||
extClass = '.SuperMangasFactory'
|
||||
extVersionCode = 2
|
||||
extVersionCode = 3
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,8 @@ abstract class SuperMangasGeneric(
|
|||
|
||||
protected open val contentList: List<Content> = listOf()
|
||||
|
||||
protected open val chapterListOrder: String = "desc"
|
||||
|
||||
private fun genericPaginatedRequest(
|
||||
typeUrl: String,
|
||||
filterData: Map<String, String> = defaultFilter,
|
||||
|
@ -235,19 +237,23 @@ abstract class SuperMangasGeneric(
|
|||
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
val document = response.asJsoup()
|
||||
val totalPage = document.select("select.pageSelect option").last()!!.attr("value").toInt()
|
||||
val idCategory = document.select("div#listaDeConteudo").first()!!.attr("data-id-cat").toInt()
|
||||
val lastPage = document.select("select.pageSelect option").last()!!
|
||||
.attr("value").toInt()
|
||||
val idCategory = document.select("div#listaDeConteudo").first()!!
|
||||
.attr("data-id-cat").toInt()
|
||||
val mangaUrl = response.request().url().toString()
|
||||
|
||||
val chapters = mutableListOf<SChapter>()
|
||||
|
||||
for (page in 1..totalPage) {
|
||||
val result = client.newCall(chapterListPaginatedRequest(idCategory, page, totalPage, mangaUrl)).execute()
|
||||
for (page in 1..lastPage) {
|
||||
val chapterListRequest = chapterListPaginatedRequest(idCategory, page, lastPage, mangaUrl)
|
||||
val result = client.newCall(chapterListRequest).execute()
|
||||
val apiResponse = result.asJsonObject()
|
||||
|
||||
if (apiResponse["codigo"].int == 0) break
|
||||
|
||||
chapters += Jsoup.parse(apiResponse["body"].asJsonArray.joinToString("") { it.string })
|
||||
val htmlBody = apiResponse["body"].array.joinToString("") { it.string }
|
||||
chapters += Jsoup.parse(htmlBody)
|
||||
.select(chapterListSelector())
|
||||
.map { chapterFromElement(it) }
|
||||
}
|
||||
|
@ -261,11 +267,11 @@ abstract class SuperMangasGeneric(
|
|||
.add("page", page.toString())
|
||||
.add("limit", "50")
|
||||
.add("total_page", totalPage.toString())
|
||||
.add("order_video", "desc")
|
||||
.add("order_video", chapterListOrder)
|
||||
.add("type", "book")
|
||||
}
|
||||
|
||||
private fun chapterListPaginatedRequest(idCategory: Int, page: Int, totalPage: Int, mangaUrl: String): Request {
|
||||
protected fun chapterListPaginatedRequest(idCategory: Int, page: Int, totalPage: Int, mangaUrl: String): Request {
|
||||
val form = chapterListPaginatedBody(idCategory, page, totalPage).build()
|
||||
|
||||
val newHeaders = headersBuilder()
|
||||
|
@ -338,7 +344,7 @@ abstract class SuperMangasGeneric(
|
|||
else -> SManga.UNKNOWN
|
||||
}
|
||||
|
||||
private fun Response.asJsonObject(): JsonObject = JSON_PARSER.parse(body()!!.string()).obj
|
||||
protected fun Response.asJsonObject(): JsonObject = JSON_PARSER.parse(body()!!.string()).obj
|
||||
|
||||
private fun Map<String, String>.toUrlQueryParams(): String =
|
||||
map { (k, v) -> "$k=$v" }.joinToString("&")
|
||||
|
|
|
@ -1,11 +1,18 @@
|
|||
package eu.kanade.tachiyomi.extension.pt.supermangas.source
|
||||
|
||||
import com.github.salomonbrys.kotson.array
|
||||
import com.github.salomonbrys.kotson.int
|
||||
import com.github.salomonbrys.kotson.string
|
||||
import eu.kanade.tachiyomi.extension.pt.supermangas.SuperMangasGeneric
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.jsoup.Jsoup
|
||||
|
||||
class SuperHentais : SuperMangasGeneric(
|
||||
"Super Hentais",
|
||||
|
@ -27,6 +34,8 @@ class SuperHentais : SuperMangasGeneric(
|
|||
Triple("10", "manhwa-ero", "Manhwa")
|
||||
)
|
||||
|
||||
override val chapterListOrder = "asc"
|
||||
|
||||
override fun searchMangaWithQueryRequest(query: String): Request {
|
||||
val searchUrl = HttpUrl.parse("$baseUrl/busca")!!.newBuilder()
|
||||
.addEncodedQueryParameter("parametro", query)
|
||||
|
@ -38,6 +47,44 @@ class SuperHentais : SuperMangasGeneric(
|
|||
|
||||
override fun searchMangaSelector(): String = "article.box_view.list div.grid_box:contains(Hentai Manga) div.grid_image.grid_image_vertical a"
|
||||
|
||||
override fun chapterListParse(response: Response): List<SChapter> {
|
||||
val document = response.asJsoup()
|
||||
|
||||
// Parse the first chapter list page available at the html.
|
||||
val chapters = document.select(chapterListSelector())
|
||||
.map { chapterFromElement(it) }
|
||||
.toMutableList()
|
||||
|
||||
// Check if there is more pages.
|
||||
val lastPage = document.select("select.pageSelect option").last()!!
|
||||
.attr("value").toInt()
|
||||
|
||||
if (lastPage > 1) {
|
||||
val idCategory = document.select("div#listaDeConteudo").first()!!
|
||||
.attr("data-id-cat").toInt()
|
||||
val mangaUrl = response.request().url().toString()
|
||||
|
||||
for (page in 2..lastPage) {
|
||||
val chapterListRequest = chapterListPaginatedRequest(idCategory, page, lastPage, mangaUrl)
|
||||
val result = client.newCall(chapterListRequest).execute()
|
||||
val apiResponse = result.asJsonObject()
|
||||
|
||||
// Check if for some reason the API returned an error.
|
||||
if (apiResponse["codigo"].int == 0) break
|
||||
|
||||
val htmlBody = apiResponse["body"].array.joinToString("") { it.string }
|
||||
chapters += Jsoup.parse(htmlBody)
|
||||
.select(chapterListSelector())
|
||||
.map { chapterFromElement(it) }
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse the chapters since the pagination is broken and there is no
|
||||
// way to order some parts as desc in the API and unite with the first page
|
||||
// that is ordered as asc.
|
||||
return chapters.reversed()
|
||||
}
|
||||
|
||||
override fun getFilterList() = FilterList(
|
||||
Filter.Header("Filtros abaixo são ignorados na busca!"),
|
||||
ContentFilter(contentList),
|
||||
|
|
Loading…
Reference in New Issue