From 406db5a2f107cabcc4eb3b6a0d9476aee543e2f3 Mon Sep 17 00:00:00 2001 From: CVIUS <84634607+CVIUS@users.noreply.github.com> Date: Tue, 13 Jul 2021 21:19:08 +0800 Subject: [PATCH] mangaowl: add filter (#8087) * Update MangaOwl.kt * Update MangaOwl.kt * Update build.gradle * Update MangaOwl.kt * Update MangaOwl.kt * Update MangaOwl.kt * Update MangaOwl.kt * Update MangaOwl.kt * Update MangaOwl.kt * Update MangaOwl.kt * Update MangaOwl.kt * Update MangaOwl.kt --- src/en/mangaowl/build.gradle | 2 +- .../extension/en/mangaowl/MangaOwl.kt | 178 +++++++++++++++++- 2 files changed, 177 insertions(+), 3 deletions(-) diff --git a/src/en/mangaowl/build.gradle b/src/en/mangaowl/build.gradle index 65782b33c..e0faf4f6a 100644 --- a/src/en/mangaowl/build.gradle +++ b/src/en/mangaowl/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'MangaOwl' pkgNameSuffix = 'en.mangaowl' extClass = '.MangaOwl' - extVersionCode = 13 + extVersionCode = 14 libVersion = '1.2' } diff --git a/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt b/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt index 6bcb21a2d..612fd2be4 100644 --- a/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt +++ b/src/en/mangaowl/src/eu/kanade/tachiyomi/extension/en/mangaowl/MangaOwl.kt @@ -1,11 +1,14 @@ package eu.kanade.tachiyomi.extension.en.mangaowl 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.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okhttp3.Headers import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document @@ -67,7 +70,23 @@ class MangaOwl : ParsedHttpSource() { // Search override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { - return GET("$baseUrl/search/$page?search=$query&search_field=110&sort=4&completed=2", headers) + val url = "$baseUrl/search/$page".toHttpUrlOrNull()?.newBuilder()!! + url.addQueryParameter("search", query) + + filters.forEach { filter -> + when (filter) { + is SearchFilter -> url.addQueryParameter("search_field", filter.toUriPart()) + is SortFilter -> url.addQueryParameter("sort", filter.toUriPart()) + is StatusFilter -> url.addQueryParameter("completed", filter.toUriPart()) + is GenreFilter -> { + val genres = filter.state + .filter { it.state } + .joinToString(".") { it.uriPart } + url.addQueryParameter("genres", genres) + } + } + } + return GET(url.toString(), headers) } override fun searchMangaSelector() = popularMangaSelector() @@ -141,5 +160,160 @@ class MangaOwl : ParsedHttpSource() { override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") - override fun getFilterList() = FilterList() + + // Filters + + override fun getFilterList() = FilterList( + SearchFilter(), + SortFilter(), + StatusFilter(), + GenreFilter(getGenreList()) + ) + + private open class UriPartFilter(displayName: String, val vals: Array>) : + Filter.Select(displayName, vals.map { it.first }.toTypedArray()) { + fun toUriPart() = vals[state].second + } + + private class SearchFilter : UriPartFilter( + "Search in", + arrayOf( + Pair("All", "123"), + Pair("Manga title", "1"), + Pair("Authors", "2"), + Pair("Description", "3") + ) + ) + + private class SortFilter : UriPartFilter( + "Sort by", + arrayOf( + Pair("Matched", "4"), + Pair("Viewed", "0"), + Pair("Popularity", "1"), + Pair("Create Date", "2"), + Pair("Upload Date", "3") + ) + ) + + private class StatusFilter : UriPartFilter( + "Status", + arrayOf( + Pair("Any", "2"), + Pair("Completed", "1"), + Pair("Ongoing", "0") + ) + ) + + private class Genre(name: String, val uriPart: String) : Filter.CheckBox(name) + private class GenreFilter(genres: List) : Filter.Group("Genres", genres) + private fun getGenreList() = listOf( + Genre("4-koma", "89"), + Genre("Action", "1"), + Genre("Adaptation", "72"), + Genre("Adventure", "2"), + Genre("Aliens", "112"), + Genre("All Ages", "122"), + Genre("Animals", "90"), + Genre("Anthology", "101"), + Genre("Award winning", "91"), + Genre("Bara", "116"), + Genre("Cars", "49"), + Genre("Comedy", "15"), + Genre("Comic", "130"), + Genre("Cooking", "63"), + Genre("Crime", "81"), + Genre("Crossdressing", "105"), + Genre("Delinquents", "73"), + Genre("Dementia", "48"), + Genre("Demons", "3"), + Genre("Doujinshi", "55"), + Genre("Drama", "4"), + Genre("Ecchi", "27"), + Genre("Fan colored", "92"), + Genre("Fantasy", "7"), + Genre("Full Color", "82"), + Genre("Game", "33"), + Genre("Gender Bender", "39"), + Genre("Ghosts", "97"), + Genre("Gore", "107"), + Genre("Gossip", "123"), + Genre("Gyaru", "104"), + Genre("Harem", "38"), + Genre("Historical", "12"), + Genre("Horror", "5"), + Genre("Incest", "98"), + Genre("Isekai", "69"), + Genre("Japanese", "129"), + Genre("Josei", "35"), + Genre("Kids", "42"), + Genre("Korean", "128"), + Genre("Long Strip", "76"), + Genre("Mafia", "82"), + Genre("Magic", "34"), + Genre("Magical Girls", "88"), + Genre("Manga", "127"), + Genre("Manhua", "62"), + Genre("Manhwa", "61"), + Genre("Martial Arts", "37"), + Genre("Mature", "60"), + Genre("Mecha", "36"), + Genre("Medical", "66"), + Genre("Military", "8"), + Genre("Monster girls", "95"), + Genre("Monsters", "84"), + Genre("Music", "32"), + Genre("Mystery", "11"), + Genre("Ninja", "93"), + Genre("Novel", "56"), + Genre("NTR", "121"), + Genre("Office", "126"), + Genre("Office Workers", "99"), + Genre("Official colored", "78"), + Genre("One shot", "67"), + Genre("Parody", "30"), + Genre("Philosophical", "100"), + Genre("Police", "46"), + Genre("Post apocalyptic", "94"), + Genre("Psychological", "9"), + Genre("Reincarnation", "74"), + Genre("Reverse harem", "79"), + Genre("Romance", "25"), + Genre("Samurai", "18"), + Genre("School life", "59"), + Genre("Sci-fi", "70"), + Genre("Seinen", "10"), + Genre("Sexual violence", "117"), + Genre("Shoujo", "28"), + Genre("Shoujo Ai", "40"), + Genre("Shounen", "13"), + Genre("Shounen Ai", "44"), + Genre("Slice of Life", "19"), + Genre("Smut", "65"), + Genre("Space", "29"), + Genre("Sports", "22"), + Genre("Super Power", "17"), + Genre("Superhero", "109"), + Genre("Supernatural", "6"), + Genre("Survival", "85"), + Genre("Thriller", "31"), + Genre("Time travel", "80"), + Genre("Toomics", "120"), + Genre("Traditional games", "113"), + Genre("Tragedy", "68"), + Genre("Uncategorized", "50"), + Genre("Uncensored", "124"), + Genre("User created", "102"), + Genre("Vampires", "103"), + Genre("Vanilla", "125"), + Genre("Video games", "75"), + Genre("Villainess", "119"), + Genre("Virtual reality", "110"), + Genre("Web comic", "77"), + Genre("Webtoon", "71"), + Genre("Wuxia", "106"), + Genre("Yaoi", "51"), + Genre("Yuri", "54"), + Genre("Zombies", "108") + ) }