Change configuration behavior
parent
3589bee5f9
commit
6ab5743f66
@ -1,6 +0,0 @@
|
||||
package org.koitharu.kotatsu.parsers
|
||||
|
||||
interface MangaSourceConfig {
|
||||
fun getDomain(defaultValue: String): String
|
||||
fun isSslEnabled(defaultValue: Boolean): Boolean
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
package org.koitharu.kotatsu.parsers.config
|
||||
|
||||
sealed class ConfigKey<T>(
|
||||
val key: String,
|
||||
) {
|
||||
|
||||
abstract val defaultValue: T
|
||||
|
||||
class Domain(
|
||||
override val defaultValue: String,
|
||||
val presetValues: Array<String>?,
|
||||
) : ConfigKey<String>("domain")
|
||||
}
|
||||
@ -0,0 +1,6 @@
|
||||
package org.koitharu.kotatsu.parsers.config
|
||||
|
||||
interface MangaSourceConfig {
|
||||
|
||||
operator fun <T> get(key: ConfigKey<T>): T
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
package org.koitharu.kotatsu.parsers.model
|
||||
|
||||
internal const val RATING_UNKNOWN = -1f
|
||||
@ -1,25 +1,98 @@
|
||||
package org.koitharu.kotatsu.parsers.model
|
||||
|
||||
data class Manga(
|
||||
class Manga(
|
||||
val id: Long,
|
||||
val title: String,
|
||||
val altTitle: String? = null,
|
||||
val altTitle: String?,
|
||||
val url: String, // relative url for internal use
|
||||
val publicUrl: String,
|
||||
val rating: Float = NO_RATING, // normalized value [0..1] or -1
|
||||
val isNsfw: Boolean = false,
|
||||
val rating: Float, // normalized value [0..1] or -1
|
||||
val isNsfw: Boolean,
|
||||
val coverUrl: String,
|
||||
val tags: Set<MangaTag>,
|
||||
val state: MangaState?,
|
||||
val author: String?,
|
||||
val largeCoverUrl: String? = null,
|
||||
val description: String? = null, // HTML
|
||||
val tags: Set<MangaTag> = emptySet(),
|
||||
val state: MangaState? = null,
|
||||
val author: String? = null,
|
||||
val chapters: List<MangaChapter>? = null,
|
||||
val source: MangaSource,
|
||||
) {
|
||||
|
||||
companion object {
|
||||
val hasRating: Boolean
|
||||
get() = rating in 0f..1f
|
||||
|
||||
const val NO_RATING = -1f
|
||||
internal fun copy(
|
||||
title: String = this.title,
|
||||
altTitle: String? = this.altTitle,
|
||||
publicUrl: String = this.publicUrl,
|
||||
rating: Float = this.rating,
|
||||
isNsfw: Boolean = this.isNsfw,
|
||||
coverUrl: String = this.coverUrl,
|
||||
tags: Set<MangaTag> = this.tags,
|
||||
state: MangaState? = this.state,
|
||||
author: String? = this.author,
|
||||
largeCoverUrl: String? = this.largeCoverUrl,
|
||||
description: String? = this.description,
|
||||
chapters: List<MangaChapter>? = this.chapters,
|
||||
) = Manga(
|
||||
id = id,
|
||||
title = title,
|
||||
altTitle = altTitle,
|
||||
url = url,
|
||||
publicUrl = publicUrl,
|
||||
rating = rating,
|
||||
isNsfw = isNsfw,
|
||||
coverUrl = coverUrl,
|
||||
tags = tags,
|
||||
state = state,
|
||||
author = author,
|
||||
largeCoverUrl = largeCoverUrl,
|
||||
description = description,
|
||||
chapters = chapters,
|
||||
source = source,
|
||||
)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Manga
|
||||
|
||||
if (id != other.id) return false
|
||||
if (title != other.title) return false
|
||||
if (altTitle != other.altTitle) return false
|
||||
if (url != other.url) return false
|
||||
if (publicUrl != other.publicUrl) return false
|
||||
if (rating != other.rating) return false
|
||||
if (isNsfw != other.isNsfw) return false
|
||||
if (coverUrl != other.coverUrl) return false
|
||||
if (tags != other.tags) return false
|
||||
if (state != other.state) return false
|
||||
if (author != other.author) return false
|
||||
if (largeCoverUrl != other.largeCoverUrl) return false
|
||||
if (description != other.description) return false
|
||||
if (chapters != other.chapters) return false
|
||||
if (source != other.source) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + title.hashCode()
|
||||
result = 31 * result + (altTitle?.hashCode() ?: 0)
|
||||
result = 31 * result + url.hashCode()
|
||||
result = 31 * result + publicUrl.hashCode()
|
||||
result = 31 * result + rating.hashCode()
|
||||
result = 31 * result + isNsfw.hashCode()
|
||||
result = 31 * result + coverUrl.hashCode()
|
||||
result = 31 * result + tags.hashCode()
|
||||
result = 31 * result + (state?.hashCode() ?: 0)
|
||||
result = 31 * result + (author?.hashCode() ?: 0)
|
||||
result = 31 * result + (largeCoverUrl?.hashCode() ?: 0)
|
||||
result = 31 * result + (description?.hashCode() ?: 0)
|
||||
result = 31 * result + (chapters?.hashCode() ?: 0)
|
||||
result = 31 * result + source.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
@ -1,9 +1,34 @@
|
||||
package org.koitharu.kotatsu.parsers.model
|
||||
|
||||
data class MangaPage(
|
||||
class MangaPage(
|
||||
val id: Long,
|
||||
val url: String,
|
||||
val referer: String,
|
||||
val preview: String?,
|
||||
val source: MangaSource,
|
||||
)
|
||||
) {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MangaPage
|
||||
|
||||
if (id != other.id) return false
|
||||
if (url != other.url) return false
|
||||
if (referer != other.referer) return false
|
||||
if (preview != other.preview) return false
|
||||
if (source != other.source) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id.hashCode()
|
||||
result = 31 * result + url.hashCode()
|
||||
result = 31 * result + referer.hashCode()
|
||||
result = 31 * result + (preview?.hashCode() ?: 0)
|
||||
result = 31 * result + source.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,28 @@
|
||||
package org.koitharu.kotatsu.parsers.model
|
||||
|
||||
data class MangaTag(
|
||||
class MangaTag(
|
||||
val title: String,
|
||||
val key: String,
|
||||
val source: MangaSource,
|
||||
)
|
||||
) {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MangaTag
|
||||
|
||||
if (title != other.title) return false
|
||||
if (key != other.key) return false
|
||||
if (source != other.source) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = title.hashCode()
|
||||
result = 31 * result + key.hashCode()
|
||||
result = 31 * result + source.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package org.koitharu.kotatsu.parsers.site
|
||||
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
internal class MangaChanParser(override val context: MangaLoaderContext) : ChanParser() {
|
||||
internal class MangaChanParser(override val context: MangaLoaderContext) : ChanParser(MangaSource.MANGACHAN) {
|
||||
|
||||
override val defaultDomain = "manga-chan.me"
|
||||
override val source = MangaSource.MANGACHAN
|
||||
override val configKeyDomain = ConfigKey.Domain("manga-chan.me", null)
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package org.koitharu.kotatsu.parsers.site
|
||||
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
internal class MintMangaParser(override val context: MangaLoaderContext) : GroupleParser() {
|
||||
internal class MintMangaParser(override val context: MangaLoaderContext) : GroupleParser(MangaSource.MINTMANGA) {
|
||||
|
||||
override val source = MangaSource.MINTMANGA
|
||||
override val defaultDomain: String = "mintmanga.live"
|
||||
override val configKeyDomain = ConfigKey.Domain("mintmanga.live", null)
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package org.koitharu.kotatsu.parsers.site
|
||||
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
internal class ReadmangaParser(override val context: MangaLoaderContext) : GroupleParser() {
|
||||
internal class ReadmangaParser(override val context: MangaLoaderContext) : GroupleParser(MangaSource.READMANGA_RU) {
|
||||
|
||||
override val defaultDomain = "readmanga.io"
|
||||
override val source = MangaSource.READMANGA_RU
|
||||
override val configKeyDomain = ConfigKey.Domain("readmanga.io", null)
|
||||
}
|
||||
@ -1,10 +1,10 @@
|
||||
package org.koitharu.kotatsu.parsers.site
|
||||
|
||||
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
internal class SelfMangaParser(override val context: MangaLoaderContext) : GroupleParser() {
|
||||
internal class SelfMangaParser(override val context: MangaLoaderContext) : GroupleParser(MangaSource.SELFMANGA) {
|
||||
|
||||
override val defaultDomain = "selfmanga.live"
|
||||
override val source = MangaSource.SELFMANGA
|
||||
override val configKeyDomain = ConfigKey.Domain("selfmanga.live", null)
|
||||
}
|
||||
@ -1,8 +1,9 @@
|
||||
package org.koitharu.kotatsu.parsers
|
||||
|
||||
internal class SourceConfigMock : MangaSourceConfig {
|
||||
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
||||
|
||||
override fun getDomain(defaultValue: String): String = defaultValue
|
||||
internal class SourceConfigMock : MangaSourceConfig {
|
||||
|
||||
override fun isSslEnabled(defaultValue: Boolean): Boolean = defaultValue
|
||||
override fun <T> get(key: ConfigKey<T>): T = key.defaultValue
|
||||
}
|
||||
Loading…
Reference in New Issue