Comick: Fix permanently cached First Cover URLs and Score on Description (#5686)

* Remove permanent cache of First Cover URL

Because images can be replaced or even removed altogether

* Reuse preference default constants for `.toSManga` parameters

* Score on description was removed at some point?

* Filter covers earlier and try to narrow it down further by language

* Reformat long line

* Don't assume a default cover language

* Only use country code part of language code

* Reformat for Lint complainer
This commit is contained in:
BrutuZ 2024-10-25 03:05:20 -03:00 committed by Draff
parent 5b7cfb5ca8
commit aafa0be66d
No known key found for this signature in database
GPG Key ID: E8A89F3211677653
3 changed files with 26 additions and 22 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Comick' extName = 'Comick'
extClass = '.ComickFactory' extClass = '.ComickFactory'
extVersionCode = 47 extVersionCode = 48
isNsfw = true isNsfw = true
} }

View File

@ -329,7 +329,11 @@ abstract class Comick(
is TagFilter -> { is TagFilter -> {
if (it.state.isNotEmpty()) { if (it.state.isNotEmpty()) {
it.state.split(",").forEach { it.state.split(",").forEach {
addQueryParameter("tags", it.trim().lowercase().replace(SPACE_AND_SLASH_REGEX, "-").replace("'-", "-and-039-").replace("'", "-and-039-")) addQueryParameter(
"tags",
it.trim().lowercase().replace(SPACE_AND_SLASH_REGEX, "-")
.replace("'-", "-and-039-").replace("'", "-and-039-"),
)
} }
} }
} }
@ -372,29 +376,26 @@ abstract class Comick(
private fun mangaDetailsParse(response: Response, manga: SManga): SManga { private fun mangaDetailsParse(response: Response, manga: SManga): SManga {
val mangaData = response.parseAs<Manga>() val mangaData = response.parseAs<Manga>()
if (!preferences.updateCover && manga.thumbnail_url != mangaData.comic.cover) { if (!preferences.updateCover && manga.thumbnail_url != mangaData.comic.cover) {
if (manga.thumbnail_url.toString().endsWith("#1")) {
return mangaData.toSManga(
includeMuTags = preferences.includeMuTags,
scorePosition = preferences.scorePosition,
covers = listOf(
MDcovers(
b2key = manga.thumbnail_url?.substringBeforeLast("#")
?.substringAfterLast("/"),
vol = "1",
),
),
)
}
val coversUrl = val coversUrl =
"$apiUrl/comic/${mangaData.comic.slug ?: mangaData.comic.hid}/covers?tachiyomi=true" "$apiUrl/comic/${mangaData.comic.slug ?: mangaData.comic.hid}/covers?tachiyomi=true"
val covers = client.newCall(GET(coversUrl)).execute() val covers = client.newCall(GET(coversUrl)).execute()
.parseAs<Covers>().mdCovers.reversed() .parseAs<Covers>().mdCovers.reversed().toMutableList()
if (covers.any { it.vol == "1" }) covers.retainAll { it.vol == "1" }
if (
covers.any { it.locale == comickLang.split('-').first() }
) {
covers.retainAll { it.locale == comickLang.split('-').first() }
}
return mangaData.toSManga( return mangaData.toSManga(
includeMuTags = preferences.includeMuTags, includeMuTags = preferences.includeMuTags,
covers = if (covers.any { it.vol == "1" }) covers.filter { it.vol == "1" } else covers, scorePosition = preferences.scorePosition,
covers = covers,
) )
} }
return mangaData.toSManga(includeMuTags = preferences.includeMuTags) return mangaData.toSManga(
includeMuTags = preferences.includeMuTags,
scorePosition = preferences.scorePosition,
)
} }
override fun getMangaUrl(manga: SManga): String { override fun getMangaUrl(manga: SManga): String {
@ -511,12 +512,12 @@ abstract class Comick(
private val SPACE_AND_SLASH_REGEX = Regex("[ /]") private val SPACE_AND_SLASH_REGEX = Regex("[ /]")
private const val IGNORED_GROUPS_PREF = "IgnoredGroups" private const val IGNORED_GROUPS_PREF = "IgnoredGroups"
private const val INCLUDE_MU_TAGS_PREF = "IncludeMangaUpdatesTags" private const val INCLUDE_MU_TAGS_PREF = "IncludeMangaUpdatesTags"
private const val INCLUDE_MU_TAGS_DEFAULT = false const val INCLUDE_MU_TAGS_DEFAULT = false
private const val MIGRATED_IGNORED_GROUPS = "MigratedIgnoredGroups" private const val MIGRATED_IGNORED_GROUPS = "MigratedIgnoredGroups"
private const val FIRST_COVER_PREF = "DefaultCover" private const val FIRST_COVER_PREF = "DefaultCover"
private const val FIRST_COVER_DEFAULT = true private const val FIRST_COVER_DEFAULT = true
private const val SCORE_POSITION_PREF = "ScorePosition" private const val SCORE_POSITION_PREF = "ScorePosition"
private const val SCORE_POSITION_DEFAULT = "top" const val SCORE_POSITION_DEFAULT = "top"
private const val LIMIT = 20 private const val LIMIT = 20
private const val CHAPTERS_LIMIT = 99999 private const val CHAPTERS_LIMIT = 99999
} }

View File

@ -1,5 +1,7 @@
package eu.kanade.tachiyomi.extension.all.comickfun package eu.kanade.tachiyomi.extension.all.comickfun
import eu.kanade.tachiyomi.extension.all.comickfun.Comick.Companion.INCLUDE_MU_TAGS_DEFAULT
import eu.kanade.tachiyomi.extension.all.comickfun.Comick.Companion.SCORE_POSITION_DEFAULT
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import kotlinx.serialization.SerialName import kotlinx.serialization.SerialName
@ -31,8 +33,8 @@ class Manga(
private val demographic: String? = null, private val demographic: String? = null,
) { ) {
fun toSManga( fun toSManga(
includeMuTags: Boolean = false, includeMuTags: Boolean = INCLUDE_MU_TAGS_DEFAULT,
scorePosition: String = "", scorePosition: String = SCORE_POSITION_DEFAULT,
covers: List<MDcovers>? = null, covers: List<MDcovers>? = null,
) = ) =
SManga.create().apply { SManga.create().apply {
@ -148,6 +150,7 @@ class Covers(
class MDcovers( class MDcovers(
val b2key: String?, val b2key: String?,
val vol: String? = null, val vol: String? = null,
val locale: String? = null,
) )
@Serializable @Serializable