From 8e720b801686615067301911abd1f3be7cec1bd7 Mon Sep 17 00:00:00 2001 From: Alessandro Jean Date: Tue, 8 Jun 2021 13:02:45 -0300 Subject: [PATCH] Fix missing covers and filter order at Tsuki. (#7545) --- src/pt/tsukimangas/build.gradle | 2 +- .../extension/pt/tsukimangas/TsukiMangas.kt | 39 ++++++++++++------- .../pt/tsukimangas/TsukiMangasDto.kt | 2 +- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/pt/tsukimangas/build.gradle b/src/pt/tsukimangas/build.gradle index c09fc353c..a1cdd99fd 100644 --- a/src/pt/tsukimangas/build.gradle +++ b/src/pt/tsukimangas/build.gradle @@ -6,7 +6,7 @@ ext { extName = 'Tsuki Mangás' pkgNameSuffix = 'pt.tsukimangas' extClass = '.TsukiMangas' - extVersionCode = 17 + extVersionCode = 18 libVersion = '1.2' containsNsfw = true } 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 caa530957..d141a1c48 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 @@ -68,8 +68,10 @@ class TsukiMangas : HttpSource() { } private fun popularMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply { + val poster = manga.poster?.substringBefore("?") + title = manga.title - thumbnail_url = baseUrl + "/imgs/" + manga.poster.substringBefore("?") + thumbnail_url = baseUrl + (if (poster.isNullOrEmpty()) EMPTY_COVER else "/imgs/$poster") url = "/obra/${manga.id}/${manga.url}" } @@ -88,8 +90,10 @@ class TsukiMangas : HttpSource() { } private fun latestMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply { + val poster = manga.poster?.substringBefore("?") + title = manga.title - thumbnail_url = baseUrl + "/imgs/" + manga.poster.substringBefore("?") + thumbnail_url = baseUrl + (if (poster.isNullOrEmpty()) EMPTY_COVER else "/imgs/$poster") url = "/obra/${manga.id}/${manga.url}" } @@ -101,12 +105,22 @@ class TsukiMangas : HttpSource() { val url = "$baseUrl/api/v2/mangas?page=$page".toHttpUrlOrNull()!!.newBuilder() url.addQueryParameter("title", query) - // Genre filter must be the first. + // Some filters have to follow an order in the URL. 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 { + if (it.state == Filter.TriState.STATE_INCLUDE) { + url.addQueryParameter("adult_content", "1") + } else if (it.state == Filter.TriState.STATE_EXCLUDE) { + url.addQueryParameter("adult_content", "false") + } + + return@let null + } + filters.filterIsInstance().firstOrNull() ?.let { filter -> if (filter.state!!.index == 0) { @@ -135,14 +149,6 @@ class TsukiMangas : HttpSource() { url.addQueryParameter("status", (filter.state - 1).toString()) } } - - is AdultFilter -> { - if (filter.state == Filter.TriState.STATE_INCLUDE) { - url.addQueryParameter("adult_content", "1") - } else if (filter.state == Filter.TriState.STATE_EXCLUDE) { - url.addQueryParameter("adult_content", "false") - } - } } } @@ -160,8 +166,10 @@ class TsukiMangas : HttpSource() { } private fun searchMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply { + val poster = manga.poster?.substringBefore("?") + title = manga.title - thumbnail_url = baseUrl + "/imgs/" + manga.poster.substringBefore("?") + thumbnail_url = baseUrl + (if (poster.isNullOrEmpty()) EMPTY_COVER else "/imgs/$poster") url = "/obra/${manga.id}/${manga.url}" } @@ -194,9 +202,10 @@ class TsukiMangas : HttpSource() { override fun mangaDetailsParse(response: Response): SManga = SManga.create().apply { val mangaDto = json.decodeFromString(response.body!!.string()) + val poster = mangaDto.poster?.substringBefore("?") title = mangaDto.title - thumbnail_url = baseUrl + "/imgs/" + mangaDto.poster.substringBefore("?") + thumbnail_url = baseUrl + (if (poster.isNullOrEmpty()) EMPTY_COVER else "/imgs/$poster") description = mangaDto.synopsis.orEmpty() status = mangaDto.status.orEmpty().toStatus() author = mangaDto.author.orEmpty() @@ -448,6 +457,8 @@ class TsukiMangas : HttpSource() { private const val UA_DISABLED_MESSAGE = "Permissão de acesso da extensão desativada. " + "Aguarde a reativação pelo site para continuar utilizando." + private const val EMPTY_COVER = "/ext/errorcapa.jpg" + private val DATE_FORMATTER by lazy { SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH) } } } diff --git a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangasDto.kt b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangasDto.kt index f0719a62a..7039f3a02 100644 --- a/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangasDto.kt +++ b/src/pt/tsukimangas/src/eu/kanade/tachiyomi/extension/pt/tsukimangas/TsukiMangasDto.kt @@ -18,7 +18,7 @@ data class TsukiMangaDto( val author: String? = "", val genres: List = emptyList(), val id: Int, - val poster: String, + val poster: String? = "", val status: String? = "", val synopsis: String? = "", val title: String,