Fix latest and chapter list not loading in MM. (#9555)

This commit is contained in:
Alessandro Jean 2021-10-20 08:17:14 -03:00 committed by GitHub
parent 00f441e4df
commit 686885026e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 4 deletions

View File

@ -2,9 +2,13 @@ package eu.kanade.tachiyomi.extension.pt.meusmangas
import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor
import eu.kanade.tachiyomi.multisrc.mangasar.MangaSar import eu.kanade.tachiyomi.multisrc.mangasar.MangaSar
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.asJsoup import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -28,6 +32,33 @@ class MeusMangas : MangaSar(
setUrlWithoutDomain(element.selectFirst("a").attr("abs:href")) setUrlWithoutDomain(element.selectFirst("a").attr("abs:href"))
} }
override fun latestUpdatesRequest(page: Int): Request {
val newHeaders = headersBuilder()
.add("X-Requested-With", "XMLHttpRequest")
.build()
val pagePath = if (page > 1) "page/$page" else ""
return GET("$baseUrl/$pagePath", newHeaders)
}
override fun latestUpdatesParse(response: Response): MangasPage {
val document = response.asJsoup()
val mangaList = document.select("li.item_news-manga")
.map(::latestMangaFromElement)
val hasNextPage = document.select("div.loadmore.morepage").firstOrNull() != null
return MangasPage(mangaList, hasNextPage)
}
private fun latestMangaFromElement(element: Element): SManga = SManga.create().apply {
title = element.select("h3.entry-title a").text()
thumbnail_url = element.select("img.manga").attr("src")
setUrlWithoutDomain(element.select("a").first().attr("abs:href"))
}
override fun mangaDetailsParse(response: Response): SManga { override fun mangaDetailsParse(response: Response): SManga {
val document = response.asJsoup() val document = response.asJsoup()
val infoElement = document.selectFirst("div.box-single:has(div.mangapage)") val infoElement = document.selectFirst("div.box-single:has(div.mangapage)")
@ -36,12 +67,62 @@ class MeusMangas : MangaSar(
title = infoElement.selectFirst("h1.kw-title").text() title = infoElement.selectFirst("h1.kw-title").text()
author = infoElement.selectFirst("div.mdq.author").text().trim() author = infoElement.selectFirst("div.mdq.author").text().trim()
description = infoElement.selectFirst("div.sinopse-page").text() description = infoElement.selectFirst("div.sinopse-page").text()
genre = infoElement.select("div.touchcarousel a.widget-btn").joinToString { it.text() } genre = infoElement.select("div.generos a.widget-btn").joinToString { it.text() }
status = infoElement.selectFirst("span.mdq").text().toStatus() status = infoElement.selectFirst("span.mdq").text().toStatus()
thumbnail_url = infoElement.selectFirst("div.thumb img").attr("abs:src") thumbnail_url = infoElement.selectFirst("div.thumb img").attr("abs:src")
} }
} }
override fun chapterListPaginatedRequest(mangaUrl: String, page: Int): Request {
val newHeaders = headersBuilder()
.add("X-Requested-With", "XMLHttpRequest")
.build()
return GET("$baseUrl$mangaUrl/page/$page", newHeaders)
}
override fun chapterListParse(response: Response): List<SChapter> {
var document = response.asJsoup()
val chapterList = document.select(chapterListSelector())
.map(::chapterFromElement)
.toMutableList()
val mangaUrl = response.request.url.toString()
.substringAfter(baseUrl)
.substringBefore("/page")
var hasNextPage = document.select(chapterListNextPageSelector())
.firstOrNull()
while (hasNextPage != null && !hasNextPage.attr("href").endsWith("#")) {
val page = hasNextPage.attr("href")
.substringAfter("page/")
.toInt()
val nextRequest = chapterListPaginatedRequest(mangaUrl, page)
val nextResponse = client.newCall(nextRequest).execute()
document = nextResponse.asJsoup()
chapterList += document.select(chapterListSelector())
.map(::chapterFromElement)
hasNextPage = document.select(chapterListNextPageSelector())
.firstOrNull()
}
return chapterList
}
private fun chapterListSelector() = "ul.list-of-chapters li > a"
private fun chapterListNextPageSelector() = "div.loadmore a.loadmore"
private fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
name = element.select("span.cap-text").text()
date_upload = element.select("span.chapter-date").text().toDate()
setUrlWithoutDomain(element.attr("abs:href"))
}
private fun String.toStatus(): Int = when (this) { private fun String.toStatus(): Int = when (this) {
"Em andamento" -> SManga.ONGOING "Em andamento" -> SManga.ONGOING
"Completo" -> SManga.COMPLETED "Completo" -> SManga.COMPLETED

View File

@ -143,7 +143,7 @@ abstract class MangaSar(
override fun chapterListRequest(manga: SManga): Request = chapterListPaginatedRequest(manga.url) override fun chapterListRequest(manga: SManga): Request = chapterListPaginatedRequest(manga.url)
private fun chapterListPaginatedRequest(mangaUrl: String, page: Int = 1): Request { protected open fun chapterListPaginatedRequest(mangaUrl: String, page: Int = 1): Request {
val mangaId = mangaUrl.substringAfterLast("/") val mangaId = mangaUrl.substringAfterLast("/")
val newHeaders = apiHeadersBuilder() val newHeaders = apiHeadersBuilder()
@ -268,7 +268,7 @@ abstract class MangaSar(
return chain.proceed(chain.request()) return chain.proceed(chain.request())
} }
private fun String.toDate(): Long { protected fun String.toDate(): Long {
return try { return try {
DATE_FORMATTER.parse(this)?.time ?: 0L DATE_FORMATTER.parse(this)?.time ?: 0L
} catch (e: ParseException) { } catch (e: ParseException) {

View File

@ -13,7 +13,7 @@ class MangaSarGenerator : ThemeSourceGenerator {
override val sources = listOf( override val sources = listOf(
SingleLang("MangaTube", "https://mangatube.site", "pt-BR"), SingleLang("MangaTube", "https://mangatube.site", "pt-BR"),
SingleLang("Meus Mangás", "https://meusmangas.net", "pt-BR", isNsfw = true, className = "MeusMangas") SingleLang("Meus Mangás", "https://meusmangas.net", "pt-BR", isNsfw = true, className = "MeusMangas", overrideVersionCode = 1)
) )
companion object { companion object {