Fix Comick Genres \ Tags (#18789)

* Simplify Manifest data entries

* Map MD and MU tags to genres

* Switch separator for Ignored Groups setting
From comma to newlines for better readability

* Make MU Tags optional via preferences
Because they might contain spoilers.
- Include demographic \ target audience into genres

* Switch from flattening list to a builder

* Remove unneeded Listener

* Switch migration check to preference boolean
Rename muTags parameter to includeMuTags

* Rename a couple variables
More in line with their context
This commit is contained in:
BrutuZ 2023-11-01 16:01:55 -03:00 committed by GitHub
parent fffb9e929a
commit 1f7aedd8af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 75 additions and 14 deletions

View File

@ -13,14 +13,10 @@
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="comick.app"
android:pathPattern="/comic/.*/..*"
android:scheme="https" />
<data
android:host="comick.app"
android:pathPattern="/comic/..*"
android:scheme="https" />
<data android:scheme="https" />
<data android:host="comick.app" />
<data android:pathPattern="/comic/.*/..*" />
<data android:pathPattern="/comic/..*" />
</intent-filter>
</activity>
</application>

View File

@ -6,7 +6,7 @@ ext {
extName = 'Comick'
pkgNameSuffix = 'all.comickfun'
extClass = '.ComickFunFactory'
extVersionCode = 36
extVersionCode = 37
isNsfw = true
}

View File

@ -4,6 +4,7 @@ import android.app.Application
import android.content.SharedPreferences
import androidx.preference.EditTextPreference
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.network.interceptor.rateLimit
@ -59,7 +60,7 @@ abstract class ComickFun(
key = IGNORED_GROUPS_PREF
title = "Ignored Groups"
summary =
"Chapters from these groups won't be shown.\nComma-separated list of group names (case-insensitive)"
"Chapters from these groups won't be shown.\nOne group name per line (case-insensitive)"
setOnPreferenceChangeListener { _, newValue ->
preferences.edit()
@ -67,18 +68,33 @@ abstract class ComickFun(
.commit()
}
}.also(screen::addPreference)
SwitchPreferenceCompat(screen.context).apply {
key = INCLUDE_MU_TAGS_PREF
title = "Include Tags"
summaryOn = "More specific, but might contain spoilers!"
summaryOff = "Only the broader genres"
setDefaultValue(true)
}.also(screen::addPreference)
}
private val SharedPreferences.ignoredGroups
get() = getString(IGNORED_GROUPS_PREF, "")
?.lowercase()
?.split(",")
?.split("\n")
?.map(String::trim)
?.filter(String::isNotEmpty)
?.sorted()
.orEmpty()
.toSet()
private val SharedPreferences.includeMuTags
get() = getBoolean(INCLUDE_MU_TAGS_PREF, true)
init {
preferences.newLineIgnoredGroups()
}
override fun headersBuilder() = Headers.Builder().apply {
add("Referer", "$baseUrl/")
add("User-Agent", "Tachiyomi ${System.getProperty("http.agent")}")
@ -263,7 +279,7 @@ abstract class ComickFun(
override fun mangaDetailsParse(response: Response): SManga {
val mangaData = response.parseAs<Manga>()
return mangaData.toSManga()
return mangaData.toSManga(includeMuTags = preferences.includeMuTags)
}
override fun getMangaUrl(manga: SManga): String {
@ -347,9 +363,28 @@ abstract class ComickFun(
override fun getFilterList() = getFilters()
private fun SharedPreferences.newLineIgnoredGroups() {
if (getBoolean(MIGRATED_IGNORED_GROUPS, false)) return
val ignoredGroups = getString(IGNORED_GROUPS_PREF, "").orEmpty()
edit()
.putString(
IGNORED_GROUPS_PREF,
ignoredGroups
.split(",")
.map(String::trim)
.filter(String::isNotEmpty)
.joinToString("\n"),
)
.putBoolean(MIGRATED_IGNORED_GROUPS, true)
.apply()
}
companion object {
const val SLUG_SEARCH_PREFIX = "id:"
private const val IGNORED_GROUPS_PREF = "IgnoredGroups"
private const val INCLUDE_MU_TAGS_PREF = "IncludeMangaUpdatesTags"
private const val MIGRATED_IGNORED_GROUPS = "MigratedIgnoredGroups"
private const val limit = 20
val dateFormat by lazy {
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH).apply {

View File

@ -27,8 +27,9 @@ data class Manga(
val artists: List<Name> = emptyList(),
val authors: List<Name> = emptyList(),
val genres: List<Name> = emptyList(),
val demographic: String? = null,
) {
fun toSManga() = SManga.create().apply {
fun toSManga(includeMuTags: Boolean = false) = SManga.create().apply {
// appennding # at end as part of migration from slug to hid
url = "/comic/${comic.hid}#"
title = comic.title
@ -48,7 +49,19 @@ data class Manga(
thumbnail_url = parseCover(comic.cover, comic.mdCovers)
artist = artists.joinToString { it.name.trim() }
author = authors.joinToString { it.name.trim() }
genre = (listOfNotNull(comic.origination) + genres)
genre = buildList {
comic.origination?.let(::add)
demographic?.let { add(Name(it)) }
addAll(genres)
addAll(comic.mdGenres.mapNotNull { it.name })
if (includeMuTags) {
comic.muGenres.categories.forEach { category ->
category.category?.title?.let { add(Name(it)) }
}
}
}
.distinctBy { it.name }
.filter { it.name.isNotBlank() }
.joinToString { it.name.trim() }
}
}
@ -64,6 +77,8 @@ data class Comic(
@SerialName("translation_completed") val translationComplete: Boolean? = true,
@SerialName("md_covers") val mdCovers: List<MDcovers> = emptyList(),
@SerialName("cover_url") val cover: String? = null,
@SerialName("md_comic_md_genres") val mdGenres: List<MdGenres>,
@SerialName("mu_comics") val muGenres: MuComicCategories,
) {
val origination = when (country) {
"jp" -> Name("Manga")
@ -73,6 +88,21 @@ data class Comic(
}
}
@Serializable
data class MdGenres(
@SerialName("md_genres") val name: Name? = null,
)
@Serializable
data class MuComicCategories(
@SerialName("mu_comic_categories") val categories: List<MuCategories> = emptyList(),
)
@Serializable
data class MuCategories(
@SerialName("mu_categories") val category: Title? = null,
)
@Serializable
data class MDcovers(
val b2key: String?,