Hentai2Rread - add search sorting (#2770)

* Hentai2Rread - add search sorting

* gradle
This commit is contained in:
Mike 2020-04-23 17:37:48 -04:00 committed by GitHub
parent 7a1663b21c
commit 892a8e5a31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 39 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: Hentai2Read'
pkgNameSuffix = 'en.hentai2read'
extClass = '.Hentai2Read'
extVersionCode = 6
extVersionCode = 7
libVersion = '1.2'
}

View File

@ -67,6 +67,9 @@ class Hentai2Read : ParsedHttpSource() {
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
var searchUrl = "$baseUrl/hentai-list/advanced-search"
return if (page == 1) {
val form = FormBody.Builder().apply {
add("cmd_wpm_wgt_mng_sch_sbm", "Search")
add("txt_wpm_wgt_mng_sch_nme", "")
@ -90,29 +93,27 @@ class Hentai2Read : ParsedHttpSource() {
Filter.TriState.STATE_EXCLUDE -> add("chk_wpm_pag_mng_sch_mng_tag_exc[]", tag.id.toString())
}
}
is SortOrder -> searchUrl += filter.toUriPart()
}
}
}
var searchUrl = "$baseUrl/hentai-list/advanced-search"
if (page > 1) { searchUrl += "/${base64String}" }
return POST("${searchUrl}/all/name-az/$page", headers, form.build())
POST(searchUrl, headers, form.build())
} else {
GET("$searchUrl/${base64String}", headers)
}
}
override fun searchMangaParse(response: Response): MangasPage {
val document = response.asJsoup()
var hasNextPage = false
val mangas = document.select(searchMangaSelector()).map { element ->
searchMangaFromElement(element)
}
val nextPage = document.select(searchMangaNextPageSelector())
nextPage.first()?.let {
hasNextPage = true
val hasNextPage = document.select(searchMangaNextPageSelector()).firstOrNull()?.let {
base64String = it.attr("href").substringAfter("/advanced-search/").substringBefore("/")
}
true
} ?: false
return MangasPage(mangas, hasNextPage)
}
@ -182,8 +183,6 @@ class Hentai2Read : ParsedHttpSource() {
return 0L
}
override fun pageListRequest(chapter: SChapter) = POST(baseUrl + chapter.url, headers)
override fun pageListParse(response: Response): List<Page> {
val pages = mutableListOf<Page>()
val m = pagesUrlPattern.matcher(response.body()!!.string())
@ -196,13 +195,9 @@ class Hentai2Read : ParsedHttpSource() {
return pages
}
override fun pageListParse(document: Document): List<Page> {
throw Exception("Not used")
}
override fun pageListParse(document: Document): List<Page> = throw Exception("Not used")
override fun imageUrlRequest(page: Page) = GET(page.url)
override fun imageUrlParse(document: Document) = ""
override fun imageUrlParse(document: Document) = throw Exception("Not used")
private class MangaNameSelect : Filter.Select<String>("Manga Name", arrayOf("Contains", "Starts With", "Ends With"))
private class ArtistName : Filter.Text("Artist")
@ -215,8 +210,14 @@ class Hentai2Read : ParsedHttpSource() {
private class TagSearchMode : Filter.Select<String>("Tag Search Mode", arrayOf("AND", "OR"))
private class Tag(name: String, val id: Int) : Filter.TriState(name)
private class TagList(title: String, tags: List<Tag>) : Filter.Group<Tag>(title, tags)
private class SortOrder(values: Array<Pair<String, String>>) : UriPartFilter("Order", values)
private open class UriPartFilter(displayName: String, val vals: Array<Pair<String, String>>) :
Filter.Select<String>(displayName, vals.map { it.first }.toTypedArray()) {
fun toUriPart() = vals[state].second
}
override fun getFilterList() = FilterList(
SortOrder(getSortOrder()),
MangaNameSelect(),
Filter.Separator(),
ArtistName(),
@ -239,6 +240,11 @@ class Hentai2Read : ParsedHttpSource() {
TagList("Doujins", getDoujinList())
)
private fun getSortOrder() = arrayOf(
Pair("Most Popular", "/any/all/most-popular"),
Pair("Last Updated", "/any/all/last-updated")
)
// Categories : 27
// $("div#tab-category > div:has(a.block)").map((i, el) => `Tag("${$(el).select("a").first().text().trim()}", ${$(el).find("input").first().attr("value")})`).get().sort().join(",\n")
// on https://hentai2read.com/hentai-search/"