Fix manga details parsing and refactor the code. (#1647)
Fix manga details parsing in SaikaiScan and refactor the code
This commit is contained in:
parent
c87be4188f
commit
ea718e0290
|
@ -5,7 +5,7 @@ ext {
|
|||
appName = 'Tachiyomi: Saikai Scan'
|
||||
pkgNameSuffix = 'pt.saikaiscan'
|
||||
extClass = '.SaikaiScan'
|
||||
extVersionCode = 1
|
||||
extVersionCode = 2
|
||||
libVersion = '1.2'
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.network.GET
|
|||
import eu.kanade.tachiyomi.source.model.*
|
||||
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.jsoup.nodes.Document
|
||||
|
@ -19,13 +20,12 @@ class SaikaiScan : ParsedHttpSource() {
|
|||
|
||||
override val supportsLatest = true
|
||||
|
||||
private val catalogHeaders = Headers.Builder().apply {
|
||||
add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)")
|
||||
add("Host", "saikaiscan.com.br")
|
||||
add("Referer", baseUrl)
|
||||
}.build()
|
||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||
.add("User-Agent", USER_AGENT)
|
||||
.add("Origin", baseUrl)
|
||||
.add("Referer", baseUrl)
|
||||
|
||||
override fun popularMangaRequest(page: Int): Request = GET(baseUrl, catalogHeaders)
|
||||
override fun popularMangaRequest(page: Int): Request = GET(baseUrl, headers)
|
||||
|
||||
override fun popularMangaSelector(): String = "div#menu ul li.has_submenu:eq(3) li a"
|
||||
|
||||
|
@ -36,57 +36,56 @@ class SaikaiScan : ParsedHttpSource() {
|
|||
|
||||
override fun popularMangaNextPageSelector(): String? = null
|
||||
|
||||
override fun latestUpdatesRequest(page: Int): Request = GET(baseUrl, catalogHeaders)
|
||||
override fun latestUpdatesRequest(page: Int): Request = GET(baseUrl, headers)
|
||||
|
||||
override fun latestUpdatesSelector(): String = "ul.manhuas li.manhua-item"
|
||||
|
||||
override fun latestUpdatesFromElement(element: Element): SManga {
|
||||
var image = element.select("div.image.lazyload")
|
||||
var name = element.select("h3")
|
||||
override fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply {
|
||||
val image = element.select("div.image.lazyload")
|
||||
val name = element.select("h3")
|
||||
|
||||
return SManga.create().apply {
|
||||
title = name.text().substringBeforeLast("(")
|
||||
thumbnail_url = baseUrl + image.attr("data-src")
|
||||
url = image.select("a").attr("href")
|
||||
}
|
||||
title = name.text().substringBeforeLast("(")
|
||||
thumbnail_url = baseUrl + image.attr("data-src")
|
||||
url = image.select("a").attr("href")
|
||||
}
|
||||
|
||||
override fun latestUpdatesNextPageSelector(): String? = null
|
||||
|
||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||
return GET("$baseUrl/busca?q=$query", catalogHeaders)
|
||||
val url = HttpUrl.parse("$baseUrl/busca")!!.newBuilder()
|
||||
.addQueryParameter("q", query)
|
||||
|
||||
return GET(url.toString(), headers)
|
||||
}
|
||||
|
||||
override fun searchMangaParse(response: Response): MangasPage {
|
||||
var results = super.searchMangaParse(response)
|
||||
var manhuas = results.mangas.filter { it.url.contains("/manhuas/") }
|
||||
val results = super.searchMangaParse(response)
|
||||
val manhuas = results.mangas.filter { it.url.contains("/manhuas/") }
|
||||
|
||||
return MangasPage(manhuas, results.hasNextPage)
|
||||
}
|
||||
|
||||
override fun searchMangaSelector(): String = "div#news-content ul li"
|
||||
|
||||
override fun searchMangaFromElement(element: Element): SManga {
|
||||
var image = element.select("div.image.lazyload")
|
||||
var name = element.select("h3")
|
||||
override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply {
|
||||
val image = element.select("div.image.lazyload")
|
||||
val name = element.select("h3")
|
||||
|
||||
return SManga.create().apply {
|
||||
title = name.text().substringBeforeLast("(")
|
||||
thumbnail_url = baseUrl + image.attr("data-src")
|
||||
url = image.select("a").attr("href")
|
||||
}
|
||||
title = name.text().substringBeforeLast("(")
|
||||
thumbnail_url = baseUrl + image.attr("data-src")
|
||||
url = image.select("a").attr("href")
|
||||
}
|
||||
|
||||
override fun searchMangaNextPageSelector(): String? = null
|
||||
|
||||
override fun mangaDetailsParse(document: Document): SManga {
|
||||
var projectContent = document.select("div#project-content")
|
||||
var name = projectContent.select("h2").first()
|
||||
var cover = projectContent.select("div.cover img.lazyload")
|
||||
var genres = projectContent.select("div.info:contains(Gênero)")
|
||||
var author = projectContent.select("div.info:contains(Autor)")
|
||||
var status = projectContent.select("div.info:contains(Status)")
|
||||
var summary = projectContent.select("div.summary-text")
|
||||
val projectContent = document.select("div#project-content")
|
||||
val name = projectContent.select("h2").first()
|
||||
val cover = projectContent.select("div.cover img.lazyload")
|
||||
val genres = projectContent.select("div.info:contains(Gênero:)")
|
||||
val author = projectContent.select("div.info:contains(Autor:)")
|
||||
val status = projectContent.select("div.info:contains(Status:)")
|
||||
val summary = projectContent.select("div.summary-text")
|
||||
|
||||
return SManga.create().apply {
|
||||
title = name.text()
|
||||
|
@ -99,8 +98,6 @@ class SaikaiScan : ParsedHttpSource() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun removeLabel(info: String) = info.substringAfter(":")
|
||||
|
||||
private fun parseStatus(status: String) = when {
|
||||
status.contains("Completo") -> SManga.COMPLETED
|
||||
status.contains("Em Tradução", true) -> SManga.ONGOING
|
||||
|
@ -115,22 +112,25 @@ class SaikaiScan : ParsedHttpSource() {
|
|||
|
||||
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
|
||||
scanlator = "Saikai Scan"
|
||||
chapter_number = CHAPTER_REGEX.toRegex().find(element.text())?.groupValues?.get(1)?.toFloatOrNull() ?: 1f
|
||||
chapter_number = CHAPTER_REGEX.find(element.text())?.groupValues?.get(1)?.toFloatOrNull() ?: 1f
|
||||
name = element.text()
|
||||
url = element.attr("href")
|
||||
}
|
||||
|
||||
override fun pageListParse(document: Document): List<Page> {
|
||||
var imagesBlock = document.select("div.manhua-slide div.images-block img.lazyload")
|
||||
val imagesBlock = document.select("div.manhua-slide div.images-block img.lazyload")
|
||||
|
||||
return imagesBlock
|
||||
.mapIndexed { i, el -> Page(i, "", el.absUrl("src")) }
|
||||
.mapIndexed { i, el -> Page(i, "", el.absUrl("src")) }
|
||||
}
|
||||
|
||||
override fun imageUrlParse(document: Document): String = ""
|
||||
|
||||
private fun removeLabel(info: String) = info.substringAfter(":")
|
||||
|
||||
companion object {
|
||||
private const val CHAPTER_REGEX = "Capítulo (\\d+)"
|
||||
private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36"
|
||||
private val CHAPTER_REGEX = "Capítulo (\\d+)".toRegex()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue