Refactor the HeanCms code a bit (#16112)
Refactor the HeanCms code a bit.
This commit is contained in:
parent
a4c17a3519
commit
b0cc31af11
@ -2,41 +2,19 @@ package eu.kanade.tachiyomi.extension.en.omegascans
|
||||
|
||||
import eu.kanade.tachiyomi.multisrc.heancms.HeanCms
|
||||
import eu.kanade.tachiyomi.network.interceptor.rateLimitHost
|
||||
import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Response
|
||||
|
||||
class OmegaScans : HeanCms("Omega Scans", "https://omegascans.org", "en") {
|
||||
|
||||
override val client: OkHttpClient = super.client.newBuilder()
|
||||
.rateLimitHost(apiUrl.toHttpUrl(), 1)
|
||||
.build()
|
||||
|
||||
// Site changed from Mangathemesia to HeanCms.
|
||||
// Site changed from MangaThemesia to HeanCms.
|
||||
override val versionId = 2
|
||||
|
||||
override val fetchAllTitles = false
|
||||
|
||||
override val coverPath = ""
|
||||
|
||||
override fun popularMangaParse(response: Response): MangasPage {
|
||||
return super.popularMangaParse(response).apply {
|
||||
this.mangas.forEach {
|
||||
it.thumbnail_url = it.thumbnail_url?.substringAfter("$apiUrl/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun searchMangaParse(response: Response): MangasPage {
|
||||
return super.searchMangaParse(response).apply {
|
||||
this.mangas.forEach {
|
||||
it.thumbnail_url = it.thumbnail_url?.substringAfter("$apiUrl/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun mangaDetailsParse(response: Response): SManga {
|
||||
return super.mangaDetailsParse(response).apply {
|
||||
thumbnail_url = thumbnail_url?.substringAfter("$apiUrl/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ import okhttp3.Request
|
||||
import okhttp3.RequestBody.Companion.toRequestBody
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
@ -34,7 +33,15 @@ abstract class HeanCms(
|
||||
|
||||
override val client: OkHttpClient = network.cloudflareClient
|
||||
|
||||
protected val json: Json by injectLazy()
|
||||
/**
|
||||
* Custom Json instance to make usage of `encodeDefaults`,
|
||||
* which is not enabled on the injected instance of the app.
|
||||
*/
|
||||
protected val json: Json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
explicitNulls = false
|
||||
encodeDefaults = true
|
||||
}
|
||||
|
||||
protected val intl by lazy { HeanCmsIntl(lang) }
|
||||
|
||||
@ -57,7 +64,6 @@ abstract class HeanCms(
|
||||
orderBy = "total_views",
|
||||
status = "Ongoing",
|
||||
type = "Comic",
|
||||
tagIds = emptyList(),
|
||||
)
|
||||
|
||||
val payload = json.encodeToString(payloadObj).toRequestBody(JSON_MEDIA_TYPE)
|
||||
@ -97,7 +103,6 @@ abstract class HeanCms(
|
||||
orderBy = "latest",
|
||||
status = "Ongoing",
|
||||
type = "Comic",
|
||||
tagIds = emptyList(),
|
||||
)
|
||||
|
||||
val payload = json.encodeToString(payloadObj).toRequestBody(JSON_MEDIA_TYPE)
|
||||
@ -328,7 +333,6 @@ abstract class HeanCms(
|
||||
order = "desc",
|
||||
orderBy = "total_views",
|
||||
type = "Comic",
|
||||
tagIds = emptyList(),
|
||||
)
|
||||
|
||||
val payload = json.encodeToString(payloadObj).toRequestBody(JSON_MEDIA_TYPE)
|
||||
|
@ -37,13 +37,10 @@ data class HeanCmsSearchDto(
|
||||
slugMap: Map<String, HeanCms.HeanCmsTitle>,
|
||||
): SManga = SManga.create().apply {
|
||||
val slugOnly = slug.replace(HeanCms.TIMESTAMP_REGEX, "")
|
||||
val thumbnailFileName = slugMap[slugOnly]?.thumbnailFileName.orEmpty()
|
||||
val thumbnailFileName = slugMap[slugOnly]?.thumbnailFileName
|
||||
|
||||
title = this@HeanCmsSearchDto.title
|
||||
thumbnail_url = when {
|
||||
thumbnailFileName.isNotEmpty() -> createThumbnailUrl(apiUrl, coverPath, thumbnailFileName)
|
||||
else -> ""
|
||||
}
|
||||
thumbnail_url = thumbnailFileName?.toAbsoluteThumbnailUrl(apiUrl, coverPath)
|
||||
url = "/series/$slugOnly"
|
||||
}
|
||||
}
|
||||
@ -75,16 +72,13 @@ data class HeanCmsSeriesDto(
|
||||
genre = tags.orEmpty()
|
||||
.sortedBy(HeanCmsTagDto::name)
|
||||
.joinToString { it.name }
|
||||
thumbnail_url = createThumbnailUrl(apiUrl, coverPath, thumbnail)
|
||||
thumbnail_url = thumbnail.ifEmpty { null }
|
||||
?.toAbsoluteThumbnailUrl(apiUrl, coverPath)
|
||||
status = this@HeanCmsSeriesDto.status?.toStatus() ?: SManga.UNKNOWN
|
||||
url = "/series/${slug.replace(HeanCms.TIMESTAMP_REGEX, "")}"
|
||||
}
|
||||
}
|
||||
|
||||
private fun createThumbnailUrl(apiUrl: String, coverPath: String, thumbnail: String): String {
|
||||
return if (thumbnail.startsWith("https://")) thumbnail else "$apiUrl/$coverPath$thumbnail"
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class HeanCmsTagDto(val name: String)
|
||||
|
||||
@ -122,12 +116,16 @@ data class HeanCmsQuerySearchPayloadDto(
|
||||
@SerialName("order_by") val orderBy: String,
|
||||
@SerialName("series_status") val status: String? = null,
|
||||
@SerialName("series_type") val type: String,
|
||||
@SerialName("tags_ids") val tagIds: List<Int>?,
|
||||
@SerialName("tags_ids") val tagIds: List<Int> = emptyList(),
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class HeanCmsSearchPayloadDto(val term: String)
|
||||
|
||||
private fun String.toAbsoluteThumbnailUrl(apiUrl: String, coverPath: String): String {
|
||||
return if (startsWith("https://")) this else "$apiUrl/$coverPath$this"
|
||||
}
|
||||
|
||||
fun String.toStatus(): Int = when (this) {
|
||||
"Ongoing" -> SManga.ONGOING
|
||||
"Hiatus" -> SManga.ON_HIATUS
|
||||
|
@ -9,7 +9,7 @@ class HeanCmsGenerator : ThemeSourceGenerator {
|
||||
|
||||
override val themeClass = "HeanCms"
|
||||
|
||||
override val baseVersionCode: Int = 11
|
||||
override val baseVersionCode: Int = 12
|
||||
|
||||
override val sources = listOf(
|
||||
SingleLang("Omega Scans", "https://omegascans.org", "en", isNsfw = true, overrideVersionCode = 16),
|
||||
|
Loading…
x
Reference in New Issue
Block a user