From c09e401b67616f73e5e6146873db85d8a63e0db1 Mon Sep 17 00:00:00 2001 From: Mike <51273546+SnakeDoc83@users.noreply.github.com> Date: Tue, 15 Oct 2019 08:47:32 -0400 Subject: [PATCH] ManhuaDB refactor (#1650) ManhuaDB refactor --- src/zh/manhuadb/build.gradle | 2 +- .../extension/zh/manhuadb/ManhuaDB.kt | 117 ++++-------------- 2 files changed, 22 insertions(+), 97 deletions(-) diff --git a/src/zh/manhuadb/build.gradle b/src/zh/manhuadb/build.gradle index 3d1b8b310..3165d445a 100644 --- a/src/zh/manhuadb/build.gradle +++ b/src/zh/manhuadb/build.gradle @@ -5,7 +5,7 @@ ext { appName = 'Tachiyomi: ManhuaDB' pkgNameSuffix = 'zh.manhuadb' extClass = '.ManhuaDB' - extVersionCode = 1 + extVersionCode = 2 libVersion = '1.2' } diff --git a/src/zh/manhuadb/src/eu/kanade/tachiyomi/extension/zh/manhuadb/ManhuaDB.kt b/src/zh/manhuadb/src/eu/kanade/tachiyomi/extension/zh/manhuadb/ManhuaDB.kt index fed2768a9..d7260528f 100644 --- a/src/zh/manhuadb/src/eu/kanade/tachiyomi/extension/zh/manhuadb/ManhuaDB.kt +++ b/src/zh/manhuadb/src/eu/kanade/tachiyomi/extension/zh/manhuadb/ManhuaDB.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.extension.zh.manhuadb import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.source.model.* import eu.kanade.tachiyomi.source.online.ParsedHttpSource -import eu.kanade.tachiyomi.util.asJsoup import okhttp3.Headers import okhttp3.Request import okhttp3.Response @@ -13,14 +12,13 @@ import java.util.regex.Pattern class ManhuaDB: ParsedHttpSource() { - override val baseUrl: String - get() = "https://www.manhuadb.com" - override val lang: String - get() = "zh" - override val name: String - get() = "漫画DB" - override val supportsLatest: Boolean - get() = true + override val baseUrl = "https://www.manhuadb.com" + + override val lang = "zh" + + override val name = "漫画DB" + + override val supportsLatest = true override fun headersBuilder(): Headers.Builder = super.headersBuilder().add("Referer", "https://www.manhuadb.com") @@ -34,52 +32,26 @@ class ManhuaDB: ParsedHttpSource() { * Rewrite the method to ensure consistency with previous format orders */ override fun chapterListParse(response: Response): List { - val document = response.asJsoup() - return document.select(chapterListSelector()).map { chapterFromElement(it) }.reversed() + return super.chapterListParse(response).reversed() } - override fun chapterListSelector(): String = "#comic-book-list > div > ol > li > a" + override fun chapterListSelector() = "#comic-book-list > div > ol > li > a" override fun imageUrlParse(document: Document): String { - val path = document.select("div.text-center > img.img-fluid").attr("src") - return "$baseUrl$path" + return document.select("div.text-center > img.img-fluid").attr("abs:src") } override fun latestUpdatesFromElement(element: Element): SManga = popularMangaFromElement(element) - override fun latestUpdatesNextPageSelector(): String? = popularMangaNextPageSelector() + override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector() override fun latestUpdatesRequest(page: Int): Request = popularMangaRequest(page) - override fun latestUpdatesSelector(): String = popularMangaSelector() - - /** - * Rewrite the method to fit the next page selector - */ - override fun latestUpdatesParse(response: Response): MangasPage { - val document = response.asJsoup() - - val mangas = document.select(latestUpdatesSelector()).map { element -> - latestUpdatesFromElement(element) - } - - val hasNextPageElement = latestUpdatesNextPageSelector()?.let { selector -> - document.select(selector).first() - } - - val hasNextPage = !(hasNextPageElement?.attr("class")?.contains("disabled") ?: false) - - return MangasPage(mangas, hasNextPage) - } + override fun latestUpdatesSelector() = popularMangaSelector() override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply { title = document.select("h1.comic-title").text() - val path = document.select("td.comic-cover > img").attr("src") - thumbnail_url = if (!path.startsWith("http")) { - "$baseUrl$path" - } else { - path - } + thumbnail_url = document.select("td.comic-cover > img").attr("abs:src") author = document.select("a.comic-creator").text() description = document.select("p.comic_story").text() status = when (document.select("td > a.comic-pub-state").text()) { @@ -87,10 +59,7 @@ class ManhuaDB: ParsedHttpSource() { "已完结" -> SManga.COMPLETED else -> SManga.UNKNOWN } - val genres = document.select("ul.tags > li").map { - it.text() - } - genre = genres.joinToString(", ") + genre = document.select("ul.tags > li a").joinToString{ it.text() } } override fun pageListParse(document: Document): List { @@ -113,71 +82,27 @@ class ManhuaDB: ParsedHttpSource() { manga.setUrlWithoutDomain(it.select("a").first().attr("href")) manga.title = it.text() } - element.select("a > img").first().let { - manga.thumbnail_url = it.attr("src") - } + manga.thumbnail_url = element.select("a > img").attr("abs:src") return manga } - override fun popularMangaNextPageSelector(): String? = "div.form-inline > a:contains(下页)" + override fun popularMangaNextPageSelector() = "a:contains(下页):not(.disabled)" override fun popularMangaRequest(page: Int): Request = GET("$baseUrl/manhua/list-page-$page.html") - /** - * Rewrite the method to fit the next page selector - */ - override fun popularMangaParse(response: Response): MangasPage { - val document = response.asJsoup() - - val mangas = document.select(popularMangaSelector()).map { element -> - popularMangaFromElement(element) - } - - val hasNextPageElement = popularMangaNextPageSelector()?.let { selector -> - document.select(selector).first() - } - - val hasNextPage = !(hasNextPageElement?.attr("class")?.contains("disabled") ?: false) - return MangasPage(mangas, hasNextPage) - } - - override fun popularMangaSelector(): String = "div.comic-book-unit" + override fun popularMangaSelector() = "div.comic-book-unit" override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply { title = element.attr("title") setUrlWithoutDomain(element.attr("href")) - val path = element.select("img").attr("src") - thumbnail_url = if (!path.startsWith("http")) { - "$baseUrl$path" - } else { - path - } + thumbnail_url = element.select("img").attr("abs:src") } - override fun searchMangaNextPageSelector(): String? = popularMangaNextPageSelector() - - /** - * Rewrite the method to fit the next page selector - */ - override fun searchMangaParse(response: Response): MangasPage { - val document = response.asJsoup() - - val mangas = document.select(searchMangaSelector()).map { element -> - searchMangaFromElement(element) - } - - val hasNextPageElement = searchMangaNextPageSelector()?.let { selector -> - document.select(selector).first() - } - - val hasNextPage = !(hasNextPageElement?.attr("class")?.contains("disabled") ?: false) - - return MangasPage(mangas, hasNextPage) - } + override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { return GET("$baseUrl/search?q=$query&p=$page", headers) } - override fun searchMangaSelector(): String = "a.d-block" -} \ No newline at end of file + override fun searchMangaSelector() = "a.d-block" +}