[RU]Desu serialization (#2816)

* [RU]Desu serialization

* extVersionCode

* clean excess

* clean excess
This commit is contained in:
Eshlender 2024-05-09 20:08:50 +05:00 committed by Draff
parent edad8aed4b
commit ad275eb542
3 changed files with 95 additions and 80 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'Desu' extName = 'Desu'
extClass = '.Desu' extClass = '.Desu'
extVersionCode = 23 extVersionCode = 24
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -15,8 +15,8 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.contentOrNull import kotlinx.serialization.json.contentOrNull
import kotlinx.serialization.json.float import kotlinx.serialization.json.float
import kotlinx.serialization.json.floatOrNull import kotlinx.serialization.json.floatOrNull
@ -62,33 +62,8 @@ class Desu : ConfigurableSource, HttpSource() {
.rateLimitHost(baseUrl.toHttpUrl(), 3) .rateLimitHost(baseUrl.toHttpUrl(), 3)
.build() .build()
private fun mangaPageFromJSON(jsonStr: String, next: Boolean): MangasPage { private fun MangaDetDto.toSManga(genresStr: String? = ""): SManga {
val mangaList = json.parseToJsonElement(jsonStr).jsonArray val ratingValue = score!!
.map {
SManga.create().apply {
mangaFromJSON(it.jsonObject, false)
}
}
return MangasPage(mangaList, next)
}
private fun SManga.mangaFromJSON(obj: JsonObject, chapter: Boolean) {
val id = obj["id"]!!.jsonPrimitive.int
url = "/$id"
title = if (isEng.equals("rus")) {
obj["russian"]!!.jsonPrimitive.content
.split(" / ")
.first()
} else {
obj["name"]!!.jsonPrimitive.content
.split(" / ")
.first()
}
thumbnail_url = obj["image"]!!.jsonObject["original"]!!.jsonPrimitive.content
val ratingValue = obj["score"]!!.jsonPrimitive.floatOrNull ?: 0F
val ratingStar = when { val ratingStar = when {
ratingValue > 9.5 -> "★★★★★" ratingValue > 9.5 -> "★★★★★"
ratingValue > 8.5 -> "★★★★✬" ratingValue > 8.5 -> "★★★★✬"
@ -103,12 +78,12 @@ class Desu : ConfigurableSource, HttpSource() {
else -> "☆☆☆☆☆" else -> "☆☆☆☆☆"
} }
val rawAgeStop = when (obj["adult"]!!.jsonPrimitive.int) { val rawAgeStop = when (age_limit!!) {
1 -> "18+" "no" -> ""
else -> "" else -> age_limit.replace("_plus", "+")
} }
val category = when (obj["kind"]!!.jsonPrimitive.content) { val category = when (kind!!) {
"manga" -> "Манга" "manga" -> "Манга"
"manhwa" -> "Манхва" "manhwa" -> "Манхва"
"manhua" -> "Маньхуа" "manhua" -> "Маньхуа"
@ -119,45 +94,36 @@ class Desu : ConfigurableSource, HttpSource() {
var altName = "" var altName = ""
if (obj["synonyms"]?.jsonPrimitive?.content.orEmpty().isNotEmpty() && obj["synonyms"]!!.jsonPrimitive.contentOrNull != null) { if (!synonyms.isNullOrEmpty()) {
altName = "Альтернативные названия:\n" + altName = "Альтернативные названия:\n" +
obj["synonyms"]!!.jsonPrimitive.content synonyms.replace("/", " / ") +
.replace("/", " / ") +
"\n\n" "\n\n"
} }
description = if (isEng.equals("rus")) { return SManga.create().apply {
obj["name"]!!.jsonPrimitive.content title = if (isEng.equals("rus")) {
.split(" / ") russian
.first() } else {
} else { name
obj["russian"]!!.jsonPrimitive.content }
.split(" / ") url = "/$id"
.first() thumbnail_url = image.original
} + "\n" + description = if (isEng.equals("rus")) {
ratingStar + " " + ratingValue + name
" (голосов: " + } else {
obj["score_users"]!!.jsonPrimitive.int + russian
")\n" + altName + } + "\n" + ratingStar + " " + ratingValue + " (голосов: " +
obj["description"]!!.jsonPrimitive.content score_users + ")\n" + altName + this@toSManga.description
genre = ("$category, $rawAgeStop, $genresStr").split(", ").filter { it.isNotEmpty() }.joinToString { it.trim() }
genre = if (chapter) { status = when (trans_status) {
"$category, $rawAgeStop, " + "continued" -> SManga.ONGOING
obj["genres"]!!.jsonArray "completed" -> SManga.COMPLETED
.map { it.jsonObject["russian"]!!.jsonPrimitive.content } else -> when (this@toSManga.status) {
.joinToString() "ongoing" -> SManga.ONGOING
} else { "released" -> SManga.COMPLETED
category + ", " + rawAgeStop + ", " + obj["genres"]!!.jsonPrimitive.content // "copyright" -> SManga.LICENSED Hides available chapters!
} else -> SManga.UNKNOWN
}
status = when (obj["trans_status"]!!.jsonPrimitive.content) {
"continued" -> SManga.ONGOING
"completed" -> SManga.COMPLETED
else -> when (obj["status"]!!.jsonPrimitive.content) {
"ongoing" -> SManga.ONGOING
"released" -> SManga.COMPLETED
// "copyright" -> SManga.LICENSED Hides available chapters!
else -> SManga.UNKNOWN
} }
} }
} }
@ -198,14 +164,12 @@ class Desu : ConfigurableSource, HttpSource() {
} }
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
val res = json.parseToJsonElement(response.body.string()).jsonObject val page = json.decodeFromString<PageWrapperDto<MangaDetDto>>(response.body.string())
val obj = res["response"]!!.jsonArray val mangas = page.response.map {
val nav = res["pageNavParams"]!!.jsonObject it.toSManga()
val count = nav["count"]!!.jsonPrimitive.int }
val limit = nav["limit"]!!.jsonPrimitive.int
val page = nav["page"]!!.jsonPrimitive.int
return mangaPageFromJSON(obj.toString(), count > page * limit) return MangasPage(mangas, page.pageNavParams.count > page.pageNavParams.page * page.pageNavParams.limit)
} }
private fun titleDetailsRequest(manga: SManga): Request { private fun titleDetailsRequest(manga: SManga): Request {
@ -225,11 +189,10 @@ class Desu : ConfigurableSource, HttpSource() {
return GET(baseUrl + "/manga" + manga.url, headers) return GET(baseUrl + "/manga" + manga.url, headers)
} }
override fun mangaDetailsParse(response: Response) = SManga.create().apply { override fun mangaDetailsParse(response: Response) = SManga.create().apply {
val obj = json.parseToJsonElement(response.body.string()) val responseString = response.body.string()
.jsonObject["response"]!! val series = json.decodeFromString<SeriesWrapperDto<MangaDetDto>>(responseString)
.jsonObject val genresStr = json.decodeFromString<SeriesWrapperDto<MangaDetGenresDto>>(responseString).response.genres!!.joinToString { it.russian }
return series.response.toSManga(genresStr)
mangaFromJSON(obj, true)
} }
override fun chapterListParse(response: Response): List<SChapter> { override fun chapterListParse(response: Response): List<SChapter> {

View File

@ -0,0 +1,52 @@
package eu.kanade.tachiyomi.extension.ru.desu
import kotlinx.serialization.Serializable
@Serializable
class SeriesWrapperDto<T>(
val response: T,
)
@Serializable
class PageWrapperDto<T>(
val pageNavParams: NavDto,
val response: List<T>,
) {
@Serializable
class NavDto(
val count: Int,
val page: Int,
val limit: Int,
)
}
@Serializable
class MangaDetDto(
val id: Long,
val name: String,
val russian: String,
val kind: String?,
val description: String?,
val score: Float?,
val score_users: Long?,
val age_limit: String?,
val synonyms: String?,
val image: ImgDto,
val trans_status: String?,
val status: String?,
) {
@Serializable
class ImgDto(
val original: String?,
)
}
@Serializable
class MangaDetGenresDto(
val genres: List<TagsDto>?,
) {
@Serializable
class TagsDto(
val russian: String,
)
}