From b03d930599c4c125ea83fd04abc575b9d62d1e56 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Mon, 17 May 2021 14:52:36 -0300 Subject: [PATCH] Add more filters to Tsuki. (#7061) --- src/pt/tsukimangas/build.gradle | 3 +- .../extension/pt/tsukimangas/TsukiMangas.kt | 209 ++++++++++++------ 2 files changed, 146 insertions(+), 66 deletions(-) diff --git a/src/pt/tsukimangas/build.gradle b/src/pt/tsukimangas/build.gradle index 9aee7dde4..cb5a88509 100644 --- a/src/pt/tsukimangas/build.gradle +++ b/src/pt/tsukimangas/build.gradle @@ -5,8 +5,9 @@ ext { extName = 'Tsuki Mangás' pkgNameSuffix = 'pt.tsukimangas' extClass = '.TsukiMangas' - extVersionCode = 14 + extVersionCode = 15 libVersion = '1.2' + containsNsfw = true } dependencies { diff --git a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt index 54f83e5bb..eb58979d9 100644 --- a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt +++ b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangas.kt @@ -9,6 +9,7 @@ import com.github.salomonbrys.kotson.string import com.google.gson.JsonElement import com.google.gson.JsonObject import com.google.gson.JsonParser +import eu.kanade.tachiyomi.annotations.Nsfw import eu.kanade.tachiyomi.lib.ratelimit.RateLimitInterceptor import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess @@ -30,6 +31,7 @@ import java.text.SimpleDateFormat import java.util.Locale import java.util.concurrent.TimeUnit +@Nsfw class TsukiMangas : HttpSource() { override val name = "Tsuki Mangás" @@ -51,16 +53,17 @@ class TsukiMangas : HttpSource() { .add("Referer", baseUrl) override fun popularMangaRequest(page: Int): Request { - return GET("$baseUrl/api/v2/home", headers) + return GET("$baseUrl/api/v2/mangas?page=$page&title=&filter=0", headers) } override fun popularMangaParse(response: Response): MangasPage { val result = response.asJson().obj - val popularMangas = result["topviewsmonth"].array + val popularMangas = result["data"].array .map { popularMangaItemParse(it.obj) } - return MangasPage(popularMangas, false) + val hasNextPage = result["page"].int < result["lastPage"].int + return MangasPage(popularMangas, hasNextPage) } private fun popularMangaItemParse(obj: JsonObject) = SManga.create().apply { @@ -97,20 +100,41 @@ class TsukiMangas : HttpSource() { val url = "$baseUrl/api/v2/mangas?page=$page".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("title", query) + // Genre filter must be the first. + filters.filterIsInstance().firstOrNull()?.state + ?.filter { it.state } + ?.forEach { url.addQueryParameter("genres[]", it.name) } + + // Sort by filter must also be the first. + filters.filterIsInstance().firstOrNull() + ?.let { filter -> + if (filter.state!!.index == 0) { + url.addQueryParameter("filter", if (filter.state!!.ascending) "1" else "0") + } else { + url.addQueryParameter("filter", if (filter.state!!.ascending) "3" else "2") + } + } + filters.forEach { filter -> when (filter) { - is GenreFilter -> { - filter.state - .filter { it.state } - .forEach { url.addQueryParameter("genres", it.name) } + is DemographyFilter -> { + if (filter.state > 0) { + url.addQueryParameter("demography", filter.state.toString()) + } } - is TypeFilter -> { + is FormatFilter -> { if (filter.state > 0) { url.addQueryParameter("format", filter.state.toString()) } } + is StatusFilter -> { + if (filter.state > 0) { + url.addQueryParameter("status", (filter.state - 1).toString()) + } + } + is AdultFilter -> { if (filter.state == Filter.TriState.STATE_INCLUDE) { url.addQueryParameter("adult_content", "1") @@ -259,73 +283,36 @@ class TsukiMangas : HttpSource() { private class Genre(name: String) : Filter.CheckBox(name) - private class GenreFilter(genres: List) : Filter.Group("Gêneros", genres) + private class DemographyFilter(demographies: List) : Filter.Select("Demografia", demographies.toTypedArray()) - private class TypeFilter(types: List) : Filter.Select("Formato", types.toTypedArray()) + private class FormatFilter(types: List) : Filter.Select("Formato", types.toTypedArray()) + + private class StatusFilter(statusList: List) : Filter.Select("Status", statusList.toTypedArray()) private class AdultFilter : Filter.TriState("Conteúdo adulto") + private class SortByFilter : Filter.Sort("Ordenar por", arrayOf("Visualizações", "Nota"), Selection(0, false)) + + private class GenreFilter(genres: List) : Filter.Group("Gêneros", genres) + override fun getFilterList(): FilterList = FilterList( + DemographyFilter(getDemographiesList()), + FormatFilter(getSerieFormats()), + StatusFilter(getStatusList()), + AdultFilter(), + SortByFilter(), GenreFilter(getGenreList()), - TypeFilter(getSerieTypes()), - AdultFilter() ) - // [...document.querySelectorAll(".multiselect:first-of-type .multiselect__element span span")] - // .map(i => `Genre("${i.innerHTML}")`).join(",\n") - private fun getGenreList(): List = listOf( - Genre("4-koma"), - Genre("Adulto"), - Genre("Artes Marciais"), - Genre("Aventura"), - Genre("Ação"), - Genre("Bender"), - Genre("Comédia"), - Genre("Drama"), - Genre("Ecchi"), - Genre("Esporte"), - Genre("Fantasia"), - Genre("Ficção"), - Genre("Gastronomia"), - Genre("Gender"), - Genre("Guerra"), - Genre("Harém"), - Genre("Histórico"), - Genre("Horror"), - Genre("Isekai"), - Genre("Josei"), - Genre("Magia"), - Genre("Manhua"), - Genre("Manhwa"), - Genre("Mecha"), - Genre("Medicina"), - Genre("Militar"), - Genre("Mistério"), - Genre("Musical"), - Genre("One-Shot"), - Genre("Psicológico"), - Genre("Romance"), - Genre("Sci-fi"), - Genre("Seinen"), - Genre("Shoujo"), - Genre("Shoujo Ai"), - Genre("Shounen"), - Genre("Shounen Ai"), - Genre("Slice of Life"), - Genre("Sobrenatural"), - Genre("Super Poderes"), - Genre("Suspense"), - Genre("Terror"), - Genre("Thriller"), - Genre("Tragédia"), - Genre("Vida Escolar"), - Genre("Webtoon"), - Genre("Yaoi"), - Genre("Yuri"), - Genre("Zumbi") + private fun getDemographiesList(): List = listOf( + "Todas", + "Shounen", + "Shoujo", + "Seinen", + "Josei" ) - private fun getSerieTypes(): List = listOf( + private fun getSerieFormats(): List = listOf( "Todos", "Mangá", "Manhwa", @@ -333,6 +320,98 @@ class TsukiMangas : HttpSource() { "Novel" ) + private fun getStatusList(): List = listOf( + "Todos", + "Ativo", + "Completo", + "Cancelado", + "Hiato" + ) + + // [...document.querySelectorAll(".multiselect:first-of-type .multiselect__element span span")] + // .map(i => `Genre("${i.innerHTML}")`).join(",\n") + private fun getGenreList(): List = listOf( + Genre("4-Koma"), + Genre("Adaptação"), + Genre("Aliens"), + Genre("Animais"), + Genre("Antologia"), + Genre("Artes Marciais"), + Genre("Aventura"), + Genre("Ação"), + Genre("Colorido por fã"), + Genre("Comédia"), + Genre("Crime"), + Genre("Cross-dressing"), + Genre("Deliquentes"), + Genre("Demônios"), + Genre("Doujinshi"), + Genre("Drama"), + Genre("Ecchi"), + Genre("Esportes"), + Genre("Fantasia"), + Genre("Fantasmas"), + Genre("Filosófico"), + Genre("Gals"), + Genre("Ganhador de Prêmio"), + Genre("Garotas Monstro"), + Genre("Garotas Mágicas"), + Genre("Gastronomia"), + Genre("Gore"), + Genre("Harém"), + Genre("Harém Reverso"), + Genre("Hentai"), + Genre("Histórico"), + Genre("Horror"), + Genre("Incesto"), + Genre("Isekai"), + Genre("Jogos Tradicionais"), + Genre("Lolis"), + Genre("Long Strip"), + Genre("Mafia"), + Genre("Magia"), + Genre("Mecha"), + Genre("Medicina"), + Genre("Militar"), + Genre("Mistério"), + Genre("Monstros"), + Genre("Música"), + Genre("Ninjas"), + Genre("Obscenidade"), + Genre("Oficialmente Colorido"), + Genre("One-shot"), + Genre("Policial"), + Genre("Psicológico"), + Genre("Pós-apocalíptico"), + Genre("Realidade Virtual"), + Genre("Reencarnação"), + Genre("Romance"), + Genre("Samurais"), + Genre("Sci-Fi"), + Genre("Shotas"), + Genre("Shoujo Ai"), + Genre("Shounen Ai"), + Genre("Slice of Life"), + Genre("Sobrenatural"), + Genre("Sobrevivência"), + Genre("Super Herói"), + Genre("Thriller"), + Genre("Todo Colorido"), + Genre("Trabalho de Escritório"), + Genre("Tragédia"), + Genre("Troca de Gênero"), + Genre("Vampiros"), + Genre("Viagem no Tempo"), + Genre("Vida Escolar"), + Genre("Violência Sexual"), + Genre("Vídeo Games"), + Genre("Webcomic"), + Genre("Wuxia"), + Genre("Yaoi"), + Genre("Yuri"), + Genre("Zumbis") + ) + private fun String.toDate(): Long { return try { DATE_FORMATTER.parse(this)?.time ?: 0L