From 44ee4ec99cd3c5d038edf9b0b8a925076662632c Mon Sep 17 00:00:00 2001 From: Rama Bondan Prakoso Date: Sun, 26 Jul 2020 07:45:06 +0700 Subject: [PATCH] Ngomik: Update url and add filters (#3887) * Ngomik: Update url and add filters Signed-off-by: Rama Bondan Prakoso * Ngomik: Adjust the code Signed-off-by: Rama Bondan Prakoso --- src/id/ngomik/build.gradle | 2 +- .../tachiyomi/extension/id/ngomik/Ngomik.kt | 125 +++++++++++++++++- 2 files changed, 122 insertions(+), 5 deletions(-) diff --git a/src/id/ngomik/build.gradle b/src/id/ngomik/build.gradle index 5658afb1c..5e8e67675 100644 --- a/src/id/ngomik/build.gradle +++ b/src/id/ngomik/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Ngomik' pkgNameSuffix = 'id.ngomik' extClass = '.Ngomik' - extVersionCode = 1 + extVersionCode = 2 libVersion = '1.2' } diff --git a/src/id/ngomik/src/eu/kanade/tachiyomi/extension/id/ngomik/Ngomik.kt b/src/id/ngomik/src/eu/kanade/tachiyomi/extension/id/ngomik/Ngomik.kt index 5a31b599b..9e1e248a8 100644 --- a/src/id/ngomik/src/eu/kanade/tachiyomi/extension/id/ngomik/Ngomik.kt +++ b/src/id/ngomik/src/eu/kanade/tachiyomi/extension/id/ngomik/Ngomik.kt @@ -1,12 +1,14 @@ package eu.kanade.tachiyomi.extension.id.ngomik 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.OkHttpClient +import okhttp3.Request import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -24,7 +26,7 @@ class Ngomik : ParsedHttpSource() { override fun popularMangaSelector() = "div.imgu > a.series" - override fun popularMangaRequest(page: Int) = GET("$baseUrl/daftar-komik/page/$page/?order=popular", headers) + override fun popularMangaRequest(page: Int) = GET("$baseUrl/all-komik/page/$page/?order=popular", headers) override fun popularMangaFromElement(element: Element) = SManga.create().apply { setUrlWithoutDomain(element.attr("href")) @@ -36,7 +38,7 @@ class Ngomik : ParsedHttpSource() { override fun latestUpdatesSelector() = popularMangaSelector() - override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/daftar-komik/page/$page/?order=update", headers) + override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/all-komik/page/$page/?order=update", headers) override fun latestUpdatesFromElement(element: Element) = popularMangaFromElement(element) @@ -44,7 +46,17 @@ class Ngomik : ParsedHttpSource() { override fun searchMangaSelector() = popularMangaSelector() - override fun searchMangaRequest(page: Int, query: String, filters: FilterList) = GET("$baseUrl/page/$page/?s=$query", headers) + override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { + val filters = if (filters.isEmpty()) getFilterList() else filters + val genre = filters.findInstance()?.toUriPart() + val order = filters.findInstance()?.toUriPart() + + return when { + order!!.isNotEmpty() -> GET("$baseUrl/all-komik/page/$page/?order=$order") + genre!!.isNotEmpty() -> GET("$baseUrl/genres/$genre/page/$page/?s=$query") + else -> GET("$baseUrl/page/$page/?s=$query") + } + } override fun searchMangaFromElement(element: Element) = popularMangaFromElement(element) @@ -80,5 +92,110 @@ class Ngomik : ParsedHttpSource() { override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not Used") - override fun getFilterList() = FilterList() + override fun getFilterList() = FilterList( + Filter.Header("Order by filter cannot be used with others"), + OrderByFilter(), + Filter.Separator(), + GenreList() + ) + + private class OrderByFilter : UriPartFilter("Order By", arrayOf( + Pair("", ""), + Pair("4-koma", "4-Koma"), + Pair("action", "Action"), + Pair("adaptation", "Adaptation"), + Pair("adult", "Adult"), + Pair("adventure", "Adventure"), + Pair("animal", "Animal"), + Pair("animals", "Animals"), + Pair("anthology", "Anthology"), + Pair("apocalypto", "Apocalypto"), + Pair("comedy", "Comedy"), + Pair("comic", "Comic"), + Pair("cooking", "Cooking"), + Pair("crime", "Crime"), + Pair("demons", "Demons"), + Pair("doujinshi", "Doujinshi"), + Pair("drama", "Drama"), + Pair("ecchi", "Ecchi"), + Pair("fantasi", "Fantasi"), + Pair("fantasy", "Fantasy"), + Pair("game", "Game"), + Pair("gender-bender", "Gender Bender"), + Pair("genderswap", "Genderswap"), + Pair("drama", "Drama"), + Pair("gore", "Gore"), + Pair("harem", "Harem"), + Pair("hentai", "Hentai"), + Pair("historical", "Historical"), + Pair("horor", "Horor"), + Pair("horror", "Horror"), + Pair("isekai", "Isekai"), + Pair("josei", "Josei"), + Pair("kingdom", "kingdom"), + Pair("magic", "Magic"), + Pair("manga", "Manga"), + Pair("manhua", "Manhua"), + Pair("manhwa", "Manhwa"), + Pair("martial-art", "Martial Art"), + Pair("martial-arts", "Martial Arts"), + Pair("mature", "Mature"), + Pair("mecha", "Mecha"), + Pair("medical", "Medical"), + Pair("military", "Military"), + Pair("modern", "Modern"), + Pair("monster", "Monster"), + Pair("monster-girls", "Monster Girls"), + Pair("music", "Music"), + Pair("mystery", "Mystery"), + Pair("oneshot", "Oneshot"), + Pair("post-apocalyptic", "Post-Apocalyptic"), + Pair("project", "Project"), + Pair("psychological", "Psychological"), + Pair("reincarnation", "Reincarnation"), + Pair("romance", "Romance"), + Pair("romancem", "Romancem"), + Pair("samurai", "Samurai"), + Pair("school", "School"), + Pair("school-life", "School Life"), + Pair("sci-fi", "Sci-Fi"), + Pair("seinen", "Seinen"), + Pair("shoujo", "Shoujo"), + Pair("shoujo-ai", "Shoujo Ai"), + Pair("shounen", "Shounen"), + Pair("shounen-ai", "Shounen Ai"), + Pair("slice-of-life", "Slice of Life"), + Pair("smut", "Smut"), + Pair("sports", "Sports"), + Pair("style-ancient", "Style ancient"), + Pair("super-power", "Super Power"), + Pair("superhero", "Superhero"), + Pair("supernatural", "Supernatural"), + Pair("survival", "Survival"), + Pair("survive", "Survive"), + Pair("thriller", "Thriller"), + Pair("time-travel", "Time Travel"), + Pair("tragedy", "Tragedy"), + Pair("urban", "Urban"), + Pair("vampire", "Vampire"), + Pair("video-games", "Video Games"), + Pair("virtual-reality", "Virtual Reality"), + Pair("webtoons", "Webtoons"), + Pair("yuri", "Yuri"), + Pair("zombies", "Zombies") + )) + + private open class UriPartFilter(displayName: String, val vals: Array>) : + Filter.Select(displayName, vals.map { it.second }.toTypedArray()) { + fun toUriPart() = vals[state].first + } + + private inline fun Iterable<*>.findInstance() = find { it is T } as? T }