Fix chapters not loading at SuperHentais. (#3752)

This commit is contained in:
Alessandro Jean 2020-07-10 21:22:12 -03:00 committed by GitHub
parent 6a44953465
commit 68620cd051
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 9 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Super Mangás' extName = 'Super Mangás'
pkgNameSuffix = 'pt.supermangas' pkgNameSuffix = 'pt.supermangas'
extClass = '.SuperMangasFactory' extClass = '.SuperMangasFactory'
extVersionCode = 2 extVersionCode = 3
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -68,6 +68,8 @@ abstract class SuperMangasGeneric(
protected open val contentList: List<Content> = listOf() protected open val contentList: List<Content> = listOf()
protected open val chapterListOrder: String = "desc"
private fun genericPaginatedRequest( private fun genericPaginatedRequest(
typeUrl: String, typeUrl: String,
filterData: Map<String, String> = defaultFilter, filterData: Map<String, String> = defaultFilter,
@ -235,19 +237,23 @@ abstract class SuperMangasGeneric(
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup() val document = response.asJsoup()
val totalPage = document.select("select.pageSelect option").last()!!.attr("value").toInt() val lastPage = document.select("select.pageSelect option").last()!!
val idCategory = document.select("div#listaDeConteudo").first()!!.attr("data-id-cat").toInt() .attr("value").toInt()
val idCategory = document.select("div#listaDeConteudo").first()!!
.attr("data-id-cat").toInt()
val mangaUrl = response.request().url().toString() val mangaUrl = response.request().url().toString()
val chapters = mutableListOf<SChapter>() val chapters = mutableListOf<SChapter>()
for (page in 1..totalPage) { for (page in 1..lastPage) {
val result = client.newCall(chapterListPaginatedRequest(idCategory, page, totalPage, mangaUrl)).execute() val chapterListRequest = chapterListPaginatedRequest(idCategory, page, lastPage, mangaUrl)
val result = client.newCall(chapterListRequest).execute()
val apiResponse = result.asJsonObject() val apiResponse = result.asJsonObject()
if (apiResponse["codigo"].int == 0) break 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()) .select(chapterListSelector())
.map { chapterFromElement(it) } .map { chapterFromElement(it) }
} }
@ -261,11 +267,11 @@ abstract class SuperMangasGeneric(
.add("page", page.toString()) .add("page", page.toString())
.add("limit", "50") .add("limit", "50")
.add("total_page", totalPage.toString()) .add("total_page", totalPage.toString())
.add("order_video", "desc") .add("order_video", chapterListOrder)
.add("type", "book") .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 form = chapterListPaginatedBody(idCategory, page, totalPage).build()
val newHeaders = headersBuilder() val newHeaders = headersBuilder()
@ -338,7 +344,7 @@ abstract class SuperMangasGeneric(
else -> SManga.UNKNOWN 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 = private fun Map<String, String>.toUrlQueryParams(): String =
map { (k, v) -> "$k=$v" }.joinToString("&") map { (k, v) -> "$k=$v" }.joinToString("&")

View File

@ -1,11 +1,18 @@
package eu.kanade.tachiyomi.extension.pt.supermangas.source 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.extension.pt.supermangas.SuperMangasGeneric
import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.Filter
import eu.kanade.tachiyomi.source.model.FilterList 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.HttpUrl
import okhttp3.Request import okhttp3.Request
import okhttp3.Response
import org.jsoup.Jsoup
class SuperHentais : SuperMangasGeneric( class SuperHentais : SuperMangasGeneric(
"Super Hentais", "Super Hentais",
@ -27,6 +34,8 @@ class SuperHentais : SuperMangasGeneric(
Triple("10", "manhwa-ero", "Manhwa") Triple("10", "manhwa-ero", "Manhwa")
) )
override val chapterListOrder = "asc"
override fun searchMangaWithQueryRequest(query: String): Request { override fun searchMangaWithQueryRequest(query: String): Request {
val searchUrl = HttpUrl.parse("$baseUrl/busca")!!.newBuilder() val searchUrl = HttpUrl.parse("$baseUrl/busca")!!.newBuilder()
.addEncodedQueryParameter("parametro", query) .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 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( override fun getFilterList() = FilterList(
Filter.Header("Filtros abaixo são ignorados na busca!"), Filter.Header("Filtros abaixo são ignorados na busca!"),
ContentFilter(contentList), ContentFilter(contentList),