Mangadex fixes
This commit is contained in:
parent
7377892942
commit
e6cb339ff5
@ -38,11 +38,11 @@ data class ChapterAttributesDto(
|
||||
|
||||
@Serializable
|
||||
data class GroupListDto(
|
||||
val limit: Int,
|
||||
val offset: Int,
|
||||
val total: Int,
|
||||
val results: List<GroupDto>,
|
||||
)
|
||||
override val limit: Int,
|
||||
override val offset: Int,
|
||||
override val total: Int,
|
||||
override val results: List<GroupDto>,
|
||||
) : ListCallDto<GroupDto>
|
||||
|
||||
@Serializable
|
||||
data class GroupDto(
|
||||
|
@ -1,6 +1,7 @@
|
||||
package exh.md.dto
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
|
||||
@Serializable
|
||||
data class MangaListDto(
|
||||
@ -22,10 +23,10 @@ data class MangaDataDto(val id: String, val type: String, val attributes: MangaA
|
||||
|
||||
@Serializable
|
||||
data class MangaAttributesDto(
|
||||
val title: Map<String, String>,
|
||||
val title: JsonElement,
|
||||
val altTitles: List<Map<String, String>>,
|
||||
val description: Map<String, String>,
|
||||
val links: Map<String, String>?,
|
||||
val description: JsonElement,
|
||||
val links: JsonElement?,
|
||||
val originalLanguage: String,
|
||||
val lastVolume: String?,
|
||||
val lastChapter: String?,
|
||||
|
@ -7,6 +7,7 @@ import exh.md.dto.ChapterDto
|
||||
import exh.md.dto.MangaDto
|
||||
import exh.md.utils.MdConstants
|
||||
import exh.md.utils.MdUtil
|
||||
import exh.md.utils.asMdMap
|
||||
import exh.metadata.metadata.MangaDexSearchMetadata
|
||||
import exh.metadata.metadata.base.RaisedTag
|
||||
import exh.metadata.metadata.base.getFlatMetadataForManga
|
||||
@ -55,7 +56,7 @@ class ApiMangaParser(
|
||||
try {
|
||||
val mangaAttributesDto = mangaDto.data.attributes
|
||||
mdUuid = mangaDto.data.id
|
||||
title = MdUtil.cleanString(mangaAttributesDto.title[lang] ?: mangaAttributesDto.title["en"]!!)
|
||||
title = MdUtil.cleanString(mangaAttributesDto.title.asMdMap().let { it[lang] ?: it["en"]!! })
|
||||
altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty()
|
||||
|
||||
mangaDto.relationships
|
||||
@ -66,7 +67,7 @@ class ApiMangaParser(
|
||||
cover = MdUtil.cdnCoverUrl(mangaDto.data.id, coverFileName)
|
||||
}
|
||||
|
||||
description = MdUtil.cleanDescription(mangaAttributesDto.description[lang] ?: mangaAttributesDto.description["en"]!!)
|
||||
description = MdUtil.cleanDescription(mangaAttributesDto.description.asMdMap().let { it[lang] ?: it["en"].orEmpty() })
|
||||
|
||||
authors = mangaDto.relationships.filter { relationshipDto ->
|
||||
relationshipDto.type.equals(MdConstants.Types.author, true)
|
||||
@ -85,7 +86,7 @@ class ApiMangaParser(
|
||||
manga.users = it.users
|
||||
}*/
|
||||
|
||||
mangaAttributesDto.links?.let { links ->
|
||||
mangaAttributesDto.links?.asMdMap()?.let { links ->
|
||||
links["al"]?.let { anilistId = it }
|
||||
links["kt"]?.let { kitsuId = it }
|
||||
links["mal"]?.let { myAnimeListId = it }
|
||||
|
@ -2,6 +2,10 @@ package exh.md.utils
|
||||
|
||||
import exh.md.dto.ListCallDto
|
||||
import exh.util.under
|
||||
import kotlinx.serialization.json.JsonElement
|
||||
import kotlinx.serialization.json.contentOrNull
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
suspend fun <T> mdListCall(request: suspend (offset: Int) -> ListCallDto<T>): List<T> {
|
||||
val results = mutableListOf<T>()
|
||||
@ -15,3 +19,9 @@ suspend fun <T> mdListCall(request: suspend (offset: Int) -> ListCallDto<T>): Li
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
fun JsonElement.asMdMap(): Map<String, String> {
|
||||
return runCatching {
|
||||
jsonObject.map { it.key to it.value.jsonPrimitive.contentOrNull.orEmpty() }.toMap()
|
||||
}.getOrElse { emptyMap() }
|
||||
}
|
||||
|
@ -265,7 +265,7 @@ class MdUtil {
|
||||
fun createMangaEntry(json: MangaDto, lang: String): MangaInfo {
|
||||
return MangaInfo(
|
||||
key = buildMangaUrl(json.data.id),
|
||||
title = cleanString(json.data.attributes.title[lang] ?: json.data.attributes.title["en"]!!),
|
||||
title = cleanString(json.data.attributes.title.asMdMap().let { it[lang] ?: it["en"]!! }),
|
||||
cover = json.relationships
|
||||
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
||||
?.attributes
|
||||
|
Loading…
x
Reference in New Issue
Block a user