From aea608013b773d6db0e1a9e70d99a955429b3781 Mon Sep 17 00:00:00 2001 From: dngonz Date: Wed, 27 Nov 2024 22:05:55 +0100 Subject: [PATCH] HentaiDex: fix global searching (#6312) * fix search * apply reviewed changes --- src/en/hentaidex/build.gradle | 2 +- .../extension/en/hentaidex/HentaiDex.kt | 103 +++++++++++++++++- 2 files changed, 103 insertions(+), 2 deletions(-) diff --git a/src/en/hentaidex/build.gradle b/src/en/hentaidex/build.gradle index 9d1e977f4..c08994b80 100644 --- a/src/en/hentaidex/build.gradle +++ b/src/en/hentaidex/build.gradle @@ -3,7 +3,7 @@ ext { extClass = '.HentaiDex' themePkg = 'mangathemesia' baseUrl = 'https://dexhentai.com' - overrideVersionCode = 0 + overrideVersionCode = 1 isNsfw = true } diff --git a/src/en/hentaidex/src/eu/kanade/tachiyomi/extension/en/hentaidex/HentaiDex.kt b/src/en/hentaidex/src/eu/kanade/tachiyomi/extension/en/hentaidex/HentaiDex.kt index 2f75b39f8..a881c6ea0 100644 --- a/src/en/hentaidex/src/eu/kanade/tachiyomi/extension/en/hentaidex/HentaiDex.kt +++ b/src/en/hentaidex/src/eu/kanade/tachiyomi/extension/en/hentaidex/HentaiDex.kt @@ -1,7 +1,12 @@ package eu.kanade.tachiyomi.extension.en.hentaidex import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.source.model.Filter +import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.SChapter +import okhttp3.HttpUrl.Companion.toHttpUrl +import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Element import java.text.SimpleDateFormat @@ -12,8 +17,10 @@ class HentaiDex : MangaThemesia( "https://dexhentai.com", "en", dateFormat = SimpleDateFormat("MMMM d, yyyy", Locale.US), + mangaUrlDirectory = "/title", ) { - override fun chapterListParse(response: Response): List = super.chapterListParse(response).sortedByDescending { it.chapter_number } + override fun chapterListParse(response: Response): List = + super.chapterListParse(response).sortedByDescending { it.chapter_number } override fun chapterFromElement(element: Element) = SChapter.create().apply { val urlElements = element.select("a") @@ -22,4 +29,98 @@ class HentaiDex : MangaThemesia( chapter_number = element.attr("data-num").toFloat() date_upload = element.selectFirst(".chapterdate")?.text().parseChapterDate() } + + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val url = baseUrl.toHttpUrl().newBuilder() + + // Can't use filter if is a global search + if (query.isNotEmpty()) { + url.addQueryParameter("s", query) + return GET(url.build(), headers) + } + + filters.forEach { filter -> + when (filter) { + is AuthorFilter -> { + url.addQueryParameter("author", filter.state) + } + + is YearFilter -> { + url.addQueryParameter("yearx", filter.state) + } + + is StatusFilter -> { + url.addQueryParameter("status", filter.selectedValue()) + } + + is TypeFilter -> { + url.addQueryParameter("type", filter.selectedValue()) + } + + is OrderByFilter -> { + url.addQueryParameter("order", filter.selectedValue()) + } + + is GenreListFilter -> { + filter.state + .filterNot { it.state == Filter.TriState.STATE_IGNORE } + .forEach { + val genre = when (it.state) { + Filter.TriState.STATE_EXCLUDE -> "-${it.value}" + else -> it.value + } + + url.addQueryParameter("genre[]", genre) + } + } + // if site has project page, default value "hasProjectPage" = false + is ProjectFilter -> { + if (filter.selectedValue() == "project-filter-on") { + url.setPathSegment(0, projectPageString.substring(1)) + } + } + + else -> { /* Do Nothing */ + } + } + } + url.addPathSegment(mangaUrlDirectory.substring(1)) + .addQueryParameter("page", page.toString()) + return GET(url.build(), headers) + } + + override fun getFilterList(): FilterList { + val filters = mutableListOf>( + Filter.Header("Text search ignores filters"), + Filter.Separator(), + AuthorFilter(intl["author_filter_title"]), + YearFilter(intl["year_filter_title"]), + StatusFilter(intl["status_filter_title"], statusOptions), + TypeFilter(intl["type_filter_title"], typeFilterOptions), + OrderByFilter(intl["order_by_filter_title"], orderByFilterOptions), + ) + if (!genrelist.isNullOrEmpty()) { + filters.addAll( + listOf( + Filter.Header(intl["genre_exclusion_warning"]), + GenreListFilter(intl["genre_filter_title"], getGenreList()), + ), + ) + } else { + filters.add( + Filter.Header(intl["genre_missing_warning"]), + ) + } + if (hasProjectPage) { + filters.addAll( + mutableListOf>( + Filter.Separator(), + Filter.Header(intl["project_filter_warning"]), + Filter.Header(intl.format("project_filter_name", name)), + ProjectFilter(intl["project_filter_title"], projectFilterOptions), + ), + ) + } + return FilterList(filters) + } }