Use ContentType instead of Type

Koitharu 2 years ago
parent b566e4e7e4
commit 0f4808f5b5
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -5,7 +5,11 @@ object ErrorMessages {
const val FILTER_MULTIPLE_STATES_NOT_SUPPORTED = "Multiple states are not supported by this source" const val FILTER_MULTIPLE_STATES_NOT_SUPPORTED = "Multiple states are not supported by this source"
const val FILTER_MULTIPLE_GENRES_NOT_SUPPORTED = "Multiple genres are not supported by this source" const val FILTER_MULTIPLE_GENRES_NOT_SUPPORTED = "Multiple genres are not supported by this source"
const val FILTER_MULTIPLE_CONTENT_RATING_NOT_SUPPORTED = const val FILTER_MULTIPLE_CONTENT_RATING_NOT_SUPPORTED =
"Multiple Content Rating are not supported by this source" "Multiple Content ratings are not supported by this source"
const val FILTER_MULTIPLE_CONTENT_TYPES_NOT_SUPPORTED =
"Multiple Content types are not supported by this source"
const val FILTER_MULTIPLE_DEMOGRAPHICS_NOT_SUPPORTED =
"Multiple Demographics are not supported by this source"
const val FILTER_BOTH_LOCALE_GENRES_NOT_SUPPORTED = const val FILTER_BOTH_LOCALE_GENRES_NOT_SUPPORTED =
"Filtering by both genres and locale is not supported by this source" "Filtering by both genres and locale is not supported by this source"
const val FILTER_BOTH_STATES_GENRES_NOT_SUPPORTED = const val FILTER_BOTH_STATES_GENRES_NOT_SUPPORTED =

@ -43,11 +43,11 @@ abstract class MangaParser @InternalParsersApi constructor(
get() = emptySet() get() = emptySet()
/** /**
* Supported [Type] variants for filtering. May be empty. * Supported [ContentType] variants for filtering. May be empty.
* *
* For better performance use [EnumSet] for more than one item. * For better performance use [EnumSet] for more than one item.
*/ */
open val availableTypes: Set<Type> open val availableContentTypes: Set<ContentType>
get() = emptySet() get() = emptySet()
/** /**
@ -184,8 +184,8 @@ abstract class MangaParser @InternalParsersApi constructor(
locale = null, locale = null,
states = emptySet(), states = emptySet(),
contentRating = emptySet(), contentRating = emptySet(),
type = emptySet(), types = emptySet(),
demographic = emptySet(), demographics = emptySet(),
), ),
) )
} }

@ -7,6 +7,10 @@ enum class ContentType {
*/ */
MANGA, MANGA,
MANHWA,
MANHUA,
/** /**
* Use this if the source provides mostly nsfw content. * Use this if the source provides mostly nsfw content.
*/ */
@ -17,6 +21,8 @@ enum class ContentType {
*/ */
COMICS, COMICS,
NOVEL,
/** /**
* Use this type if no other suits your needs. For example, for an indie manga * Use this type if no other suits your needs. For example, for an indie manga
*/ */

@ -14,9 +14,9 @@ sealed interface MangaListFilter {
(tags.size <= 1 || parser.isMultipleTagsSupported) && (tags.size <= 1 || parser.isMultipleTagsSupported) &&
(tagsExclude.isEmpty() || parser.isTagsExclusionSupported) && (tagsExclude.isEmpty() || parser.isTagsExclusionSupported) &&
(contentRating.isEmpty() || parser.availableContentRating.containsAll(contentRating)) && (contentRating.isEmpty() || parser.availableContentRating.containsAll(contentRating)) &&
(states.isEmpty() || parser.availableStates.containsAll(states) && (states.isEmpty() || parser.availableStates.containsAll(states)) &&
(type.isEmpty() || parser.availableType.containsAll(type)) && (types.isEmpty() || parser.availableContentTypes.containsAll(types)) &&
(demographic.isEmpty() || parser.availableDemographic.containsAll(demographic))) (demographics.isEmpty() || parser.availableDemographics.containsAll(demographics))
is Search -> parser.isSearchSupported is Search -> parser.isSearchSupported
} }
@ -37,12 +37,12 @@ sealed interface MangaListFilter {
@JvmField val locale: Locale?, @JvmField val locale: Locale?,
@JvmField val states: Set<MangaState>, @JvmField val states: Set<MangaState>,
@JvmField val contentRating: Set<ContentRating>, @JvmField val contentRating: Set<ContentRating>,
@JvmField val type: Set<Type>, @JvmField val types: Set<ContentType>,
@JvmField val demographic: Set<Demographic>, @JvmField val demographics: Set<Demographic>,
) : MangaListFilter { ) : MangaListFilter {
override fun isEmpty(): Boolean = override fun isEmpty(): Boolean =
tags.isEmpty() && tagsExclude.isEmpty() && locale == null && states.isEmpty() && contentRating.isEmpty() && type.isEmpty() && demographic.isEmpty() tags.isEmpty() && tagsExclude.isEmpty() && locale == null && states.isEmpty() && contentRating.isEmpty() && types.isEmpty() && demographics.isEmpty()
fun newBuilder() = Builder(sortOrder) fun newBuilder() = Builder(sortOrder)
.tags(tags) .tags(tags)
@ -50,8 +50,8 @@ sealed interface MangaListFilter {
.locale(locale) .locale(locale)
.states(states) .states(states)
.contentRatings(contentRating) .contentRatings(contentRating)
.type(type) .type(types)
.demographic(demographic) .demographic(demographics)
class Builder(sortOrder: SortOrder) { class Builder(sortOrder: SortOrder) {
@ -61,7 +61,7 @@ sealed interface MangaListFilter {
private var _locale: Locale? = null private var _locale: Locale? = null
private var _states: Set<MangaState>? = null private var _states: Set<MangaState>? = null
private var _contentRating: Set<ContentRating>? = null private var _contentRating: Set<ContentRating>? = null
private var _type: Set<Type>? = null private var _types: Set<ContentType>? = null
private var _demographic: Set<Demographic>? = null private var _demographic: Set<Demographic>? = null
fun sortOrder(order: SortOrder) = apply { fun sortOrder(order: SortOrder) = apply {
@ -88,8 +88,8 @@ sealed interface MangaListFilter {
_contentRating = rating _contentRating = rating
} }
fun type(type: Set<Type>?) = apply { fun type(type: Set<ContentType>?) = apply {
_type = type _types = type
} }
fun demographic(demographic: Set<Demographic>?) = apply { fun demographic(demographic: Set<Demographic>?) = apply {
@ -103,8 +103,8 @@ sealed interface MangaListFilter {
locale = _locale, locale = _locale,
states = _states.orEmpty(), states = _states.orEmpty(),
contentRating = _contentRating.orEmpty(), contentRating = _contentRating.orEmpty(),
type = _type.orEmpty(), types = _types.orEmpty(),
demographic = _demographic.orEmpty() demographics = _demographic.orEmpty(),
) )
} }
} }

@ -1,10 +0,0 @@
package org.koitharu.kotatsu.parsers.model
enum class Type {
MANGA,
MANHWA,
MANHUA,
COMIC,
NOVEL,
OTHERS,
}

@ -36,14 +36,14 @@ internal class ComickFunParser(context: MangaLoaderContext) :
SortOrder.NEWEST, SortOrder.NEWEST,
) )
override val availableType: Set<Type> = EnumSet.of( override val availableContentTypes: Set<ContentType> = EnumSet.of(
Type.MANGA, ContentType.MANGA,
Type.MANHWA, ContentType.MANHWA,
Type.MANHUA, ContentType.MANHUA,
Type.OTHERS, ContentType.OTHER,
) )
override val availableDemographic: Set<Demographic> = EnumSet.allOf(Demographic::class.java) override val availableDemographics: Set<Demographic> = EnumSet.allOf(Demographic::class.java)
override val availableStates: Set<MangaState> = override val availableStates: Set<MangaState> =
EnumSet.of(MangaState.ONGOING, MangaState.FINISHED, MangaState.PAUSED, MangaState.ABANDONED) EnumSet.of(MangaState.ONGOING, MangaState.FINISHED, MangaState.PAUSED, MangaState.ABANDONED)
@ -99,20 +99,20 @@ internal class ComickFunParser(context: MangaLoaderContext) :
) )
} }
filter.type.forEach { filter.types.forEach {
url.addQueryParameter( url.addQueryParameter(
"country", "country",
when (it) { when (it) {
Type.MANGA -> "jp" ContentType.MANGA -> "jp"
Type.MANHWA -> "kr" ContentType.MANHWA -> "kr"
Type.MANHUA -> "cn" ContentType.MANHUA -> "cn"
Type.OTHERS -> "others" ContentType.OTHER -> "others"
else -> "" else -> ""
}, },
) )
} }
filter.demographic.forEach { filter.demographics.forEach {
url.addQueryParameter( url.addQueryParameter(
"demographic", "demographic",
when (it) { when (it) {

@ -37,7 +37,7 @@ internal class MangaDexParser(context: MangaLoaderContext) : MangaParser(context
override val availableContentRating: Set<ContentRating> = EnumSet.allOf(ContentRating::class.java) override val availableContentRating: Set<ContentRating> = EnumSet.allOf(ContentRating::class.java)
override val availableDemographic: Set<Demographic> = EnumSet.allOf(Demographic::class.java) override val availableDemographics: Set<Demographic> = EnumSet.allOf(Demographic::class.java)
override val availableStates: Set<MangaState> = override val availableStates: Set<MangaState> =
EnumSet.of(MangaState.ONGOING, MangaState.FINISHED, MangaState.PAUSED, MangaState.ABANDONED) EnumSet.of(MangaState.ONGOING, MangaState.FINISHED, MangaState.PAUSED, MangaState.ABANDONED)
@ -110,7 +110,7 @@ internal class MangaDexParser(context: MangaLoaderContext) : MangaParser(context
} }
} }
filter.demographic.forEach { filter.demographics.forEach {
append("&publicationDemographic[]=") append("&publicationDemographic[]=")
append( append(
when (it) { when (it) {

@ -46,8 +46,14 @@ internal abstract class MangaReaderParser(
override val availableStates: Set<MangaState> override val availableStates: Set<MangaState>
get() = EnumSet.of(MangaState.ONGOING, MangaState.FINISHED, MangaState.PAUSED) get() = EnumSet.of(MangaState.ONGOING, MangaState.FINISHED, MangaState.PAUSED)
override val availableType: Set<Type> override val availableContentTypes: Set<ContentType>
get() = EnumSet.of(Type.MANGA, Type.MANHWA, Type.MANHUA, Type.COMIC, Type.NOVEL) get() = EnumSet.of(
ContentType.MANGA,
ContentType.MANHWA,
ContentType.MANHUA,
ContentType.COMICS,
ContentType.NOVEL,
)
override val isTagsExclusionSupported = true override val isTagsExclusionSupported = true
@ -114,15 +120,15 @@ internal abstract class MangaReaderParser(
} }
} }
filter.type.oneOrThrowIfMany()?.let { filter.types.oneOrThrowIfMany()?.let {
append("&type=") append("&type=")
append( append(
when (it) { when (it) {
Type.MANGA -> "manga" ContentType.MANGA -> "manga"
Type.MANHWA -> "manhwa" ContentType.MANHWA -> "manhwa"
Type.MANHUA -> "manhua" ContentType.MANHUA -> "manhua"
Type.COMIC -> "comic" ContentType.COMICS -> "comic"
Type.NOVEL -> "novel" ContentType.NOVEL -> "novel"
else -> "" else -> ""
}, },
) )

@ -51,48 +51,34 @@ fun Element.parseFailed(message: String? = null): Nothing {
} }
@InternalParsersApi @InternalParsersApi
fun Set<MangaTag>?.oneOrThrowIfMany(): MangaTag? { fun Set<MangaTag>?.oneOrThrowIfMany(): MangaTag? = oneOrThrowIfMany(
return when { ErrorMessages.FILTER_MULTIPLE_GENRES_NOT_SUPPORTED,
isNullOrEmpty() -> null )
size == 1 -> first()
else -> throw IllegalArgumentException(ErrorMessages.FILTER_MULTIPLE_GENRES_NOT_SUPPORTED)
}
}
@InternalParsersApi @InternalParsersApi
fun Set<MangaState>?.oneOrThrowIfMany(): MangaState? { fun Set<MangaState>?.oneOrThrowIfMany(): MangaState? = oneOrThrowIfMany(
return when { ErrorMessages.FILTER_MULTIPLE_STATES_NOT_SUPPORTED,
isNullOrEmpty() -> null )
size == 1 -> first()
else -> throw IllegalArgumentException(ErrorMessages.FILTER_MULTIPLE_STATES_NOT_SUPPORTED)
}
}
@InternalParsersApi @InternalParsersApi
fun Set<Type>?.oneOrThrowIfMany(): Type? { fun Set<ContentType>?.oneOrThrowIfMany(): ContentType? = oneOrThrowIfMany(
return when { ErrorMessages.FILTER_MULTIPLE_CONTENT_TYPES_NOT_SUPPORTED,
isNullOrEmpty() -> null )
size == 1 -> first()
else -> throw IllegalArgumentException(ErrorMessages.FILTER_MULTIPLE_STATES_NOT_SUPPORTED)
}
}
@InternalParsersApi @InternalParsersApi
fun Set<Demographic>?.oneOrThrowIfMany(): Demographic? { fun Set<Demographic>?.oneOrThrowIfMany(): Demographic? = oneOrThrowIfMany(
return when { ErrorMessages.FILTER_MULTIPLE_DEMOGRAPHICS_NOT_SUPPORTED,
isNullOrEmpty() -> null )
size == 1 -> first()
else -> throw IllegalArgumentException(ErrorMessages.FILTER_MULTIPLE_STATES_NOT_SUPPORTED)
}
}
@InternalParsersApi @InternalParsersApi
fun Set<ContentRating>?.oneOrThrowIfMany(): ContentRating? { fun Set<ContentRating>?.oneOrThrowIfMany(): ContentRating? = oneOrThrowIfMany(
return when { ErrorMessages.FILTER_MULTIPLE_CONTENT_RATING_NOT_SUPPORTED,
)
private fun <T> Set<T>?.oneOrThrowIfMany(msg: String): T? = when {
isNullOrEmpty() -> null isNullOrEmpty() -> null
size == 1 -> first() size == 1 -> first()
else -> throw IllegalArgumentException(ErrorMessages.FILTER_MULTIPLE_CONTENT_RATING_NOT_SUPPORTED) else -> throw IllegalArgumentException(msg)
}
} }
val MangaParser.domain: String val MangaParser.domain: String

@ -59,8 +59,8 @@ internal class MangaParserTest {
states = emptySet(), states = emptySet(),
tagsExclude = emptySet(), tagsExclude = emptySet(),
contentRating = emptySet(), contentRating = emptySet(),
type = emptySet(), types = emptySet(),
demographic = emptySet(), demographics = emptySet(),
), ),
).minByOrNull { ).minByOrNull {
it.title.length it.title.length
@ -135,8 +135,8 @@ internal class MangaParserTest {
locale = locales.random(), locale = locales.random(),
states = setOf(), states = setOf(),
contentRating = setOf(), contentRating = setOf(),
type = emptySet(), types = emptySet(),
demographic = emptySet(), demographics = emptySet(),
) )
val list = parser.getList(offset = 0, filter) val list = parser.getList(offset = 0, filter)
checkMangaList(list, filter.locale.toString()) checkMangaList(list, filter.locale.toString())

Loading…
Cancel
Save