Fix manga details parsing and refactor the code. (#1647)

Fix manga details parsing in SaikaiScan and refactor the code
This commit is contained in:
Alessandro Jean 2019-10-14 02:01:01 -03:00 committed by arkon
parent c87be4188f
commit ea718e0290
2 changed files with 40 additions and 40 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Saikai Scan' appName = 'Tachiyomi: Saikai Scan'
pkgNameSuffix = 'pt.saikaiscan' pkgNameSuffix = 'pt.saikaiscan'
extClass = '.SaikaiScan' extClass = '.SaikaiScan'
extVersionCode = 1 extVersionCode = 2
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import okhttp3.Headers import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
@ -19,13 +20,12 @@ class SaikaiScan : ParsedHttpSource() {
override val supportsLatest = true override val supportsLatest = true
private val catalogHeaders = Headers.Builder().apply { override fun headersBuilder(): Headers.Builder = Headers.Builder()
add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64)") .add("User-Agent", USER_AGENT)
add("Host", "saikaiscan.com.br") .add("Origin", baseUrl)
add("Referer", baseUrl) .add("Referer", baseUrl)
}.build()
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" 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 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 latestUpdatesSelector(): String = "ul.manhuas li.manhua-item"
override fun latestUpdatesFromElement(element: Element): SManga { override fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply {
var image = element.select("div.image.lazyload") val image = element.select("div.image.lazyload")
var name = element.select("h3") val name = element.select("h3")
return SManga.create().apply { title = name.text().substringBeforeLast("(")
title = name.text().substringBeforeLast("(") thumbnail_url = baseUrl + image.attr("data-src")
thumbnail_url = baseUrl + image.attr("data-src") url = image.select("a").attr("href")
url = image.select("a").attr("href")
}
} }
override fun latestUpdatesNextPageSelector(): String? = null override fun latestUpdatesNextPageSelector(): String? = null
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { 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 { override fun searchMangaParse(response: Response): MangasPage {
var results = super.searchMangaParse(response) val results = super.searchMangaParse(response)
var manhuas = results.mangas.filter { it.url.contains("/manhuas/") } val manhuas = results.mangas.filter { it.url.contains("/manhuas/") }
return MangasPage(manhuas, results.hasNextPage) return MangasPage(manhuas, results.hasNextPage)
} }
override fun searchMangaSelector(): String = "div#news-content ul li" override fun searchMangaSelector(): String = "div#news-content ul li"
override fun searchMangaFromElement(element: Element): SManga { override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply {
var image = element.select("div.image.lazyload") val image = element.select("div.image.lazyload")
var name = element.select("h3") val name = element.select("h3")
return SManga.create().apply { title = name.text().substringBeforeLast("(")
title = name.text().substringBeforeLast("(") thumbnail_url = baseUrl + image.attr("data-src")
thumbnail_url = baseUrl + image.attr("data-src") url = image.select("a").attr("href")
url = image.select("a").attr("href")
}
} }
override fun searchMangaNextPageSelector(): String? = null override fun searchMangaNextPageSelector(): String? = null
override fun mangaDetailsParse(document: Document): SManga { override fun mangaDetailsParse(document: Document): SManga {
var projectContent = document.select("div#project-content") val projectContent = document.select("div#project-content")
var name = projectContent.select("h2").first() val name = projectContent.select("h2").first()
var cover = projectContent.select("div.cover img.lazyload") val cover = projectContent.select("div.cover img.lazyload")
var genres = projectContent.select("div.info:contains(Gênero)") val genres = projectContent.select("div.info:contains(Gênero:)")
var author = projectContent.select("div.info:contains(Autor)") val author = projectContent.select("div.info:contains(Autor:)")
var status = projectContent.select("div.info:contains(Status)") val status = projectContent.select("div.info:contains(Status:)")
var summary = projectContent.select("div.summary-text") val summary = projectContent.select("div.summary-text")
return SManga.create().apply { return SManga.create().apply {
title = name.text() title = name.text()
@ -99,8 +98,6 @@ class SaikaiScan : ParsedHttpSource() {
} }
} }
private fun removeLabel(info: String) = info.substringAfter(":")
private fun parseStatus(status: String) = when { private fun parseStatus(status: String) = when {
status.contains("Completo") -> SManga.COMPLETED status.contains("Completo") -> SManga.COMPLETED
status.contains("Em Tradução", true) -> SManga.ONGOING status.contains("Em Tradução", true) -> SManga.ONGOING
@ -115,22 +112,25 @@ class SaikaiScan : ParsedHttpSource() {
override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply { override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply {
scanlator = "Saikai Scan" 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() name = element.text()
url = element.attr("href") url = element.attr("href")
} }
override fun pageListParse(document: Document): List<Page> { 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 return imagesBlock
.mapIndexed { i, el -> Page(i, "", el.absUrl("src")) } .mapIndexed { i, el -> Page(i, "", el.absUrl("src")) }
} }
override fun imageUrlParse(document: Document): String = "" override fun imageUrlParse(document: Document): String = ""
private fun removeLabel(info: String) = info.substringAfter(":")
companion object { 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()
} }
} }