Webtoons - update search (#3676)

This commit is contained in:
Mike 2020-07-03 01:59:59 -04:00 committed by GitHub
parent cb5865ffb7
commit c1b40095a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 28 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'Webtoons'
pkgNameSuffix = 'all.webtoons'
extClass = '.WebtoonsFactory'
extVersionCode = 16
extVersionCode = 17
libVersion = '1.2'
}

View File

@ -1,7 +1,7 @@
package eu.kanade.tachiyomi.extension.all.webtoons
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.util.asJsoup
@ -26,11 +26,6 @@ class DongmanManhua : WebtoonsDefault("zh", "") {
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/dailySchedule?sortOrder=UPDATE&webtoonCompleteType=ONGOING", headers)
override fun searchMangaParse(response: Response): MangasPage {
val mangas = response.asJsoup().select(searchMangaSelector()).map { searchMangaFromElement(it) }
return MangasPage(mangas, false)
}
override fun parseDetailsThumbnail(document: Document): String? {
return document.select("div.detail_body").attr("style").substringAfter("(").substringBefore(")")
}
@ -65,4 +60,6 @@ class DongmanManhua : WebtoonsDefault("zh", "") {
override fun chapterParseDate(date: String): Long {
return SimpleDateFormat("yyyy-M-d", Locale.ENGLISH).parse(date).time
}
override fun getFilterList(): FilterList = FilterList()
}

View File

@ -1,6 +1,9 @@
package eu.kanade.tachiyomi.extension.all.webtoons
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.Filter.Header
import eu.kanade.tachiyomi.source.model.Filter.Select
import eu.kanade.tachiyomi.source.model.Filter.Separator
import eu.kanade.tachiyomi.source.model.FilterList
import eu.kanade.tachiyomi.source.model.MangasPage
import eu.kanade.tachiyomi.source.model.SManga
@ -11,6 +14,7 @@ import okhttp3.Cookie
import okhttp3.CookieJar
import okhttp3.Headers
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
@ -28,7 +32,7 @@ abstract class Webtoons(
override val supportsLatest = true
override val client = super.client.newBuilder()
override val client: OkHttpClient = super.client.newBuilder()
.cookieJar(object : CookieJar {
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {}
override fun loadForRequest(url: HttpUrl): List<Cookie> {
@ -117,33 +121,20 @@ abstract class Webtoons(
override fun latestUpdatesNextPageSelector(): String? = null
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
val url = HttpUrl.parse("$baseUrl/search?keyword=$query")?.newBuilder()!!
url.addQueryParameter("searchType", "WEBTOON")
val url = HttpUrl.parse("$baseUrl/$langCode/search?keyword=$query")?.newBuilder()!!
val uriPart = (filters.find { it is SearchType } as? SearchType)?.toUriPart() ?: ""
url.addQueryParameter("searchType", uriPart)
if (uriPart != "WEBTOON" && page > 1) url.addQueryParameter("page", page.toString())
return GET(url.toString(), headers)
}
override fun searchMangaParse(response: Response): MangasPage {
val query = response.request().url().queryParameter("keyword")
val toonDocument = response.asJsoup()
val discDocument = client.newCall(GET("$baseUrl/search?keyword=$query&searchType=CHALLENGE", headers)).execute().asJsoup()
val elements = mutableListOf<Element>().apply {
addAll(toonDocument.select(searchMangaSelector()))
addAll(discDocument.select(searchMangaSelector()))
}
val mangas = elements.map { element ->
searchMangaFromElement(element)
}
return MangasPage(mangas, false)
}
override fun searchMangaSelector() = "#content > div.card_wrap.search li a"
override fun searchMangaFromElement(element: Element): SManga = popularMangaFromElement(element)
override fun searchMangaNextPageSelector(): String? = null
override fun searchMangaNextPageSelector() = "div.more_area, div.paginate a[onclick] + a"
open fun parseDetailsThumbnail(document: Document): String? {
val picElement = document.select("#content > div.cont_box > div.detail_body")
@ -172,4 +163,27 @@ abstract class Webtoons(
}
override fun imageUrlParse(document: Document): String = document.select("img").first().attr("src")
// Filters
override fun getFilterList(): FilterList {
return FilterList(
Header("Query can not be blank"),
Separator(),
SearchType(getOfficialList())
)
}
private class SearchType(vals: Array<Pair<String, String>>) : UriPartFilter("Official or Challenge", vals)
private fun getOfficialList() = arrayOf(
Pair("Any", ""),
Pair("Official only", "WEBTOON"),
Pair("Challenge only", "CHALLENGE")
)
open class UriPartFilter(displayName: String, private val vals: Array<Pair<String, String>>) :
Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
fun toUriPart() = vals[state].second
}
}

View File

@ -222,4 +222,6 @@ open class WebtoonsTranslate(override val lang: String, private val translateLan
}
return ret
}
override fun getFilterList(): FilterList = FilterList()
}