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