Fix missing covers and filter order at Tsuki. (#7545)

This commit is contained in:
Alessandro Jean 2021-06-08 13:02:45 -03:00 committed by GitHub
parent ec464155d3
commit 8e720b8016
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 16 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Tsuki Mangás' extName = 'Tsuki Mangás'
pkgNameSuffix = 'pt.tsukimangas' pkgNameSuffix = 'pt.tsukimangas'
extClass = '.TsukiMangas' extClass = '.TsukiMangas'
extVersionCode = 17 extVersionCode = 18
libVersion = '1.2' libVersion = '1.2'
containsNsfw = true containsNsfw = true
} }

View File

@ -68,8 +68,10 @@ class TsukiMangas : HttpSource() {
} }
private fun popularMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply { private fun popularMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply {
val poster = manga.poster?.substringBefore("?")
title = manga.title 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}" url = "/obra/${manga.id}/${manga.url}"
} }
@ -88,8 +90,10 @@ class TsukiMangas : HttpSource() {
} }
private fun latestMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply { private fun latestMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply {
val poster = manga.poster?.substringBefore("?")
title = manga.title 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}" url = "/obra/${manga.id}/${manga.url}"
} }
@ -101,12 +105,22 @@ class TsukiMangas : HttpSource() {
val url = "$baseUrl/api/v2/mangas?page=$page".toHttpUrlOrNull()!!.newBuilder() val url = "$baseUrl/api/v2/mangas?page=$page".toHttpUrlOrNull()!!.newBuilder()
url.addQueryParameter("title", query) url.addQueryParameter("title", query)
// Genre filter must be the first. // Some filters have to follow an order in the URL.
filters.filterIsInstance<GenreFilter>().firstOrNull()?.state filters.filterIsInstance<GenreFilter>().firstOrNull()?.state
?.filter { it.state } ?.filter { it.state }
?.forEach { url.addQueryParameter("genres[]", it.name) } ?.forEach { url.addQueryParameter("genres[]", it.name) }
// Sort by filter must also be the first. filters.filterIsInstance<AdultFilter>().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<SortByFilter>().firstOrNull() filters.filterIsInstance<SortByFilter>().firstOrNull()
?.let { filter -> ?.let { filter ->
if (filter.state!!.index == 0) { if (filter.state!!.index == 0) {
@ -135,14 +149,6 @@ class TsukiMangas : HttpSource() {
url.addQueryParameter("status", (filter.state - 1).toString()) 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 { private fun searchMangaItemParse(manga: TsukiMangaDto) = SManga.create().apply {
val poster = manga.poster?.substringBefore("?")
title = manga.title 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}" url = "/obra/${manga.id}/${manga.url}"
} }
@ -194,9 +202,10 @@ class TsukiMangas : HttpSource() {
override fun mangaDetailsParse(response: Response): SManga = SManga.create().apply { override fun mangaDetailsParse(response: Response): SManga = SManga.create().apply {
val mangaDto = json.decodeFromString<TsukiMangaDto>(response.body!!.string()) val mangaDto = json.decodeFromString<TsukiMangaDto>(response.body!!.string())
val poster = mangaDto.poster?.substringBefore("?")
title = mangaDto.title 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() description = mangaDto.synopsis.orEmpty()
status = mangaDto.status.orEmpty().toStatus() status = mangaDto.status.orEmpty().toStatus()
author = mangaDto.author.orEmpty() 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. " + private const val UA_DISABLED_MESSAGE = "Permissão de acesso da extensão desativada. " +
"Aguarde a reativação pelo site para continuar utilizando." "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) } private val DATE_FORMATTER by lazy { SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH) }
} }
} }

View File

@ -18,7 +18,7 @@ data class TsukiMangaDto(
val author: String? = "", val author: String? = "",
val genres: List<TsukiGenreDto> = emptyList(), val genres: List<TsukiGenreDto> = emptyList(),
val id: Int, val id: Int,
val poster: String, val poster: String? = "",
val status: String? = "", val status: String? = "",
val synopsis: String? = "", val synopsis: String? = "",
val title: String, val title: String,