[RU]Desu serialization (#2816)
* [RU]Desu serialization * extVersionCode * clean excess * clean excess
This commit is contained in:
		
							parent
							
								
									edad8aed4b
								
							
						
					
					
						commit
						ad275eb542
					
				| @ -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" | ||||||
|  | |||||||
| @ -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,41 +94,31 @@ 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 { | ||||||
|             obj["russian"]!!.jsonPrimitive.content |                 name | ||||||
|                 .split(" / ") |  | ||||||
|                 .first() |  | ||||||
|         } + "\n" + |  | ||||||
|             ratingStar + " " + ratingValue + |  | ||||||
|             " (голосов: " + |  | ||||||
|             obj["score_users"]!!.jsonPrimitive.int + |  | ||||||
|             ")\n" + altName + |  | ||||||
|             obj["description"]!!.jsonPrimitive.content |  | ||||||
| 
 |  | ||||||
|         genre = if (chapter) { |  | ||||||
|             "$category, $rawAgeStop, " + |  | ||||||
|                 obj["genres"]!!.jsonArray |  | ||||||
|                     .map { it.jsonObject["russian"]!!.jsonPrimitive.content } |  | ||||||
|                     .joinToString() |  | ||||||
|         } else { |  | ||||||
|             category + ", " + rawAgeStop + ", " + obj["genres"]!!.jsonPrimitive.content |  | ||||||
|             } |             } | ||||||
| 
 |             url = "/$id" | ||||||
|         status = when (obj["trans_status"]!!.jsonPrimitive.content) { |             thumbnail_url = image.original | ||||||
|  |             description = if (isEng.equals("rus")) { | ||||||
|  |                 name | ||||||
|  |             } else { | ||||||
|  |                 russian | ||||||
|  |             } + "\n" + ratingStar + " " + ratingValue + " (голосов: " + | ||||||
|  |                 score_users + ")\n" + altName + this@toSManga.description | ||||||
|  |             genre = ("$category, $rawAgeStop, $genresStr").split(", ").filter { it.isNotEmpty() }.joinToString { it.trim() } | ||||||
|  |             status = when (trans_status) { | ||||||
|                 "continued" -> SManga.ONGOING |                 "continued" -> SManga.ONGOING | ||||||
|                 "completed" -> SManga.COMPLETED |                 "completed" -> SManga.COMPLETED | ||||||
|             else -> when (obj["status"]!!.jsonPrimitive.content) { |                 else -> when (this@toSManga.status) { | ||||||
|                     "ongoing" -> SManga.ONGOING |                     "ongoing" -> SManga.ONGOING | ||||||
|                     "released" -> SManga.COMPLETED |                     "released" -> SManga.COMPLETED | ||||||
|                     //  "copyright" -> SManga.LICENSED  Hides available chapters! |                     //  "copyright" -> SManga.LICENSED  Hides available chapters! | ||||||
| @ -161,6 +126,7 @@ class Desu : ConfigurableSource, HttpSource() { | |||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     override fun popularMangaRequest(page: Int) = |     override fun popularMangaRequest(page: Int) = | ||||||
|         GET("$baseUrl$API_URL/?limit=50&order=popular&page=$page") |         GET("$baseUrl$API_URL/?limit=50&order=popular&page=$page") | ||||||
| @ -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> { | ||||||
|  | |||||||
							
								
								
									
										52
									
								
								src/ru/desu/src/eu/kanade/tachiyomi/extension/ru/desu/Dto.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								src/ru/desu/src/eu/kanade/tachiyomi/extension/ru/desu/Dto.kt
									
									
									
									
									
										Normal 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, | ||||||
|  |     ) | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Eshlender
						Eshlender