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' appName = 'Tachiyomi: Hentai2Read'
pkgNameSuffix = 'en.hentai2read' pkgNameSuffix = 'en.hentai2read'
extClass = '.Hentai2Read' extClass = '.Hentai2Read'
extVersionCode = 6 extVersionCode = 7
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -67,6 +67,9 @@ class Hentai2Read : ParsedHttpSource() {
override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector() override fun latestUpdatesNextPageSelector() = popularMangaNextPageSelector()
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { 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 { val form = FormBody.Builder().apply {
add("cmd_wpm_wgt_mng_sch_sbm", "Search") add("cmd_wpm_wgt_mng_sch_sbm", "Search")
add("txt_wpm_wgt_mng_sch_nme", "") 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()) Filter.TriState.STATE_EXCLUDE -> add("chk_wpm_pag_mng_sch_mng_tag_exc[]", tag.id.toString())
} }
} }
is SortOrder -> searchUrl += filter.toUriPart()
} }
} }
} }
POST(searchUrl, headers, form.build())
var searchUrl = "$baseUrl/hentai-list/advanced-search" } else {
if (page > 1) { searchUrl += "/${base64String}" } GET("$searchUrl/${base64String}", headers)
}
return POST("${searchUrl}/all/name-az/$page", headers, form.build())
} }
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
val document = response.asJsoup() val document = response.asJsoup()
var hasNextPage = false
val mangas = document.select(searchMangaSelector()).map { element -> val mangas = document.select(searchMangaSelector()).map { element ->
searchMangaFromElement(element) searchMangaFromElement(element)
} }
val nextPage = document.select(searchMangaNextPageSelector()) val hasNextPage = document.select(searchMangaNextPageSelector()).firstOrNull()?.let {
nextPage.first()?.let {
hasNextPage = true
base64String = it.attr("href").substringAfter("/advanced-search/").substringBefore("/") base64String = it.attr("href").substringAfter("/advanced-search/").substringBefore("/")
} true
} ?: false
return MangasPage(mangas, hasNextPage) return MangasPage(mangas, hasNextPage)
} }
@ -182,8 +183,6 @@ class Hentai2Read : ParsedHttpSource() {
return 0L return 0L
} }
override fun pageListRequest(chapter: SChapter) = POST(baseUrl + chapter.url, headers)
override fun pageListParse(response: Response): List<Page> { override fun pageListParse(response: Response): List<Page> {
val pages = mutableListOf<Page>() val pages = mutableListOf<Page>()
val m = pagesUrlPattern.matcher(response.body()!!.string()) val m = pagesUrlPattern.matcher(response.body()!!.string())
@ -196,13 +195,9 @@ class Hentai2Read : ParsedHttpSource() {
return pages return pages
} }
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> = throw Exception("Not used")
throw Exception("Not used")
}
override fun imageUrlRequest(page: Page) = GET(page.url) override fun imageUrlParse(document: Document) = throw Exception("Not used")
override fun imageUrlParse(document: Document) = ""
private class MangaNameSelect : Filter.Select<String>("Manga Name", arrayOf("Contains", "Starts With", "Ends With")) private class MangaNameSelect : Filter.Select<String>("Manga Name", arrayOf("Contains", "Starts With", "Ends With"))
private class ArtistName : Filter.Text("Artist") 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 TagSearchMode : Filter.Select<String>("Tag Search Mode", arrayOf("AND", "OR"))
private class Tag(name: String, val id: Int) : Filter.TriState(name) 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 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( override fun getFilterList() = FilterList(
SortOrder(getSortOrder()),
MangaNameSelect(), MangaNameSelect(),
Filter.Separator(), Filter.Separator(),
ArtistName(), ArtistName(),
@ -239,6 +240,11 @@ class Hentai2Read : ParsedHttpSource() {
TagList("Doujins", getDoujinList()) TagList("Doujins", getDoujinList())
) )
private fun getSortOrder() = arrayOf(
Pair("Most Popular", "/any/all/most-popular"),
Pair("Last Updated", "/any/all/last-updated")
)
// Categories : 27 // 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") // $("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/" // on https://hentai2read.com/hentai-search/"