|
|
|
|
@ -11,34 +11,38 @@ import org.koitharu.kotatsu.parsers.MangaParser
|
|
|
|
|
import org.koitharu.kotatsu.parsers.config.ConfigKey
|
|
|
|
|
import org.koitharu.kotatsu.parsers.config.MangaSourceConfig
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.*
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.search.MangaSearchQuery
|
|
|
|
|
import org.koitharu.kotatsu.parsers.model.search.MangaSearchQueryCapabilities
|
|
|
|
|
import org.koitharu.kotatsu.parsers.network.OkHttpWebClient
|
|
|
|
|
import org.koitharu.kotatsu.parsers.network.WebClient
|
|
|
|
|
import org.koitharu.kotatsu.parsers.util.*
|
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
@Suppress("OVERRIDE_DEPRECATION")
|
|
|
|
|
@InternalParsersApi
|
|
|
|
|
public abstract class LegacyMangaParser @InternalParsersApi constructor(
|
|
|
|
|
@property:InternalParsersApi public val context: MangaLoaderContext,
|
|
|
|
|
public final override val source: MangaParserSource,
|
|
|
|
|
@Deprecated("Too complex. Use AbstractMangaParser instead")
|
|
|
|
|
internal abstract class FlexibleMangaParser @InternalParsersApi constructor(
|
|
|
|
|
@property:InternalParsersApi val context: MangaLoaderContext,
|
|
|
|
|
final override val source: MangaParserSource,
|
|
|
|
|
) : MangaParser {
|
|
|
|
|
|
|
|
|
|
public final override val searchQueryCapabilities: MangaSearchQueryCapabilities
|
|
|
|
|
get() = filterCapabilities.toMangaSearchQueryCapabilities()
|
|
|
|
|
override val config: MangaSourceConfig by lazy { context.getConfig(source) }
|
|
|
|
|
|
|
|
|
|
abstract override val filterCapabilities: MangaListFilterCapabilities
|
|
|
|
|
open val sourceLocale: Locale
|
|
|
|
|
get() = if (source.locale.isEmpty()) Locale.ROOT else Locale(source.locale)
|
|
|
|
|
|
|
|
|
|
public override val config: MangaSourceConfig by lazy { context.getConfig(source) }
|
|
|
|
|
protected open val userAgentKey: ConfigKey.UserAgent = ConfigKey.UserAgent(context.getDefaultUserAgent())
|
|
|
|
|
|
|
|
|
|
public open val sourceLocale: Locale
|
|
|
|
|
get() = if (source.locale.isEmpty()) Locale.ROOT else Locale(source.locale)
|
|
|
|
|
final override val filterCapabilities: MangaListFilterCapabilities
|
|
|
|
|
get() = searchQueryCapabilities.toMangaListFilterCapabilities()
|
|
|
|
|
|
|
|
|
|
protected val isNsfwSource: Boolean = source.contentType == ContentType.HENTAI
|
|
|
|
|
protected val sourceContentRating: ContentRating?
|
|
|
|
|
get() = if (source.contentType == ContentType.HENTAI) {
|
|
|
|
|
ContentRating.ADULT
|
|
|
|
|
} else {
|
|
|
|
|
null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected open val userAgentKey: ConfigKey.UserAgent = ConfigKey.UserAgent(context.getDefaultUserAgent())
|
|
|
|
|
final override val domain: String
|
|
|
|
|
get() = config[configKeyDomain]
|
|
|
|
|
|
|
|
|
|
@Deprecated("Override intercept() instead")
|
|
|
|
|
override fun getRequestHeaders(): Headers = Headers.Builder()
|
|
|
|
|
.add("User-Agent", config[userAgentKey])
|
|
|
|
|
.build()
|
|
|
|
|
@ -46,49 +50,37 @@ public abstract class LegacyMangaParser @InternalParsersApi constructor(
|
|
|
|
|
/**
|
|
|
|
|
* Used as fallback if value of `order` passed to [getList] is null
|
|
|
|
|
*/
|
|
|
|
|
public open val defaultSortOrder: SortOrder
|
|
|
|
|
open val defaultSortOrder: SortOrder
|
|
|
|
|
get() {
|
|
|
|
|
val supported = availableSortOrders
|
|
|
|
|
return SortOrder.entries.first { it in supported }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final override val domain: String
|
|
|
|
|
get() = config[configKeyDomain]
|
|
|
|
|
|
|
|
|
|
@JvmField
|
|
|
|
|
protected val webClient: WebClient = OkHttpWebClient(context.httpClient, source)
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Search list of manga by specified searchQuery
|
|
|
|
|
*
|
|
|
|
|
* @param query searchQuery
|
|
|
|
|
*/
|
|
|
|
|
public final override suspend fun getList(query: MangaSearchQuery): List<Manga> = getList(
|
|
|
|
|
offset = query.offset,
|
|
|
|
|
order = query.order ?: defaultSortOrder,
|
|
|
|
|
filter = convertToMangaListFilter(query),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
abstract override suspend fun getList(offset: Int, order: SortOrder, filter: MangaListFilter): List<Manga>
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Fetch direct link to the page image.
|
|
|
|
|
*/
|
|
|
|
|
public override suspend fun getPageUrl(page: MangaPage): String = page.url.toAbsoluteUrl(domain)
|
|
|
|
|
override suspend fun getPageUrl(page: MangaPage): String = page.url.toAbsoluteUrl(domain)
|
|
|
|
|
|
|
|
|
|
final override suspend fun getList(offset: Int, order: SortOrder, filter: MangaListFilter): List<Manga> {
|
|
|
|
|
return getList(convertToMangaSearchQuery(offset, order, filter))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Parse favicons from the main page of the source`s website
|
|
|
|
|
*/
|
|
|
|
|
public override suspend fun getFavicons(): Favicons {
|
|
|
|
|
override suspend fun getFavicons(): Favicons {
|
|
|
|
|
return FaviconParser(webClient, domain).parseFavicons()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@CallSuper
|
|
|
|
|
public override fun onCreateConfig(keys: MutableCollection<ConfigKey<*>>) {
|
|
|
|
|
override fun onCreateConfig(keys: MutableCollection<ConfigKey<*>>) {
|
|
|
|
|
keys.add(configKeyDomain)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override suspend fun getRelatedManga(seed: Manga): List<Manga> {
|
|
|
|
|
override suspend fun getRelatedManga(seed: Manga): List<Manga> {
|
|
|
|
|
return RelatedMangaFinder(listOf(this)).invoke(seed)
|
|
|
|
|
}
|
|
|
|
|
|