Full-proof way of getting a mangadex manga title, update crashlytics
This commit is contained in:
parent
1c69b066f7
commit
5224988265
@ -280,7 +280,7 @@ dependencies {
|
|||||||
|
|
||||||
// Firebase (EH)
|
// Firebase (EH)
|
||||||
implementation("com.google.firebase:firebase-analytics-ktx:20.0.2")
|
implementation("com.google.firebase:firebase-analytics-ktx:20.0.2")
|
||||||
implementation("com.google.firebase:firebase-crashlytics-ktx:18.2.6")
|
implementation("com.google.firebase:firebase-crashlytics-ktx:18.2.7")
|
||||||
|
|
||||||
// Better logging (EH)
|
// Better logging (EH)
|
||||||
implementation("com.elvishew:xlog:1.11.0")
|
implementation("com.elvishew:xlog:1.11.0")
|
||||||
|
@ -69,7 +69,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(MdUtil.getFromLangMap(mangaAttributesDto.title.asMdMap(), lang, mangaAttributesDto.originalLanguage))
|
title = MdUtil.cleanString(MdUtil.getTitleFromManga(mangaAttributesDto, lang,))
|
||||||
altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty()
|
altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty()
|
||||||
|
|
||||||
val mangaRelationshipsDto = mangaDto.data.relationships
|
val mangaRelationshipsDto = mangaDto.data.relationships
|
||||||
@ -81,7 +81,13 @@ class ApiMangaParser(
|
|||||||
cover = MdUtil.cdnCoverUrl(mangaDto.data.id, coverFileName)
|
cover = MdUtil.cdnCoverUrl(mangaDto.data.id, coverFileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
description = MdUtil.cleanDescription(MdUtil.getFromLangMap(mangaAttributesDto.description.asMdMap(), lang, mangaAttributesDto.originalLanguage))
|
description = MdUtil.cleanDescription(
|
||||||
|
MdUtil.getFromLangMap(
|
||||||
|
langMap = mangaAttributesDto.description.asMdMap(),
|
||||||
|
currentLang = lang,
|
||||||
|
originalLanguage = mangaAttributesDto.originalLanguage
|
||||||
|
).orEmpty()
|
||||||
|
)
|
||||||
|
|
||||||
authors = mangaRelationshipsDto.filter { relationshipDto ->
|
authors = mangaRelationshipsDto.filter { relationshipDto ->
|
||||||
relationshipDto.type.equals(MdConstants.Types.author, true)
|
relationshipDto.type.equals(MdConstants.Types.author, true)
|
||||||
|
@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.source.model.SManga
|
|||||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||||
import exh.log.xLogD
|
import exh.log.xLogD
|
||||||
import exh.md.dto.LoginBodyTokenDto
|
import exh.md.dto.LoginBodyTokenDto
|
||||||
|
import exh.md.dto.MangaAttributesDto
|
||||||
import exh.md.dto.MangaDataDto
|
import exh.md.dto.MangaDataDto
|
||||||
import exh.md.network.NoSessionException
|
import exh.md.network.NoSessionException
|
||||||
import exh.source.getMainSource
|
import exh.source.getMainSource
|
||||||
@ -266,7 +267,7 @@ class MdUtil {
|
|||||||
fun createMangaEntry(json: MangaDataDto, lang: String): MangaInfo {
|
fun createMangaEntry(json: MangaDataDto, lang: String): MangaInfo {
|
||||||
return MangaInfo(
|
return MangaInfo(
|
||||||
key = buildMangaUrl(json.id),
|
key = buildMangaUrl(json.id),
|
||||||
title = cleanString(getFromLangMap(json.attributes.title.asMdMap(), lang, json.attributes.originalLanguage)),
|
title = cleanString(getTitleFromManga(json.attributes, lang)),
|
||||||
cover = json.relationships
|
cover = json.relationships
|
||||||
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
||||||
?.attributes
|
?.attributes
|
||||||
@ -277,14 +278,30 @@ class MdUtil {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFromLangMap(langMap: Map<String, String?>, currentLang: String, originalLanguage: String): String {
|
fun getTitleFromManga(json: MangaAttributesDto, lang: String): String {
|
||||||
return langMap[currentLang] ?: langMap["en"] ?: langMap[originalLanguage].let {
|
return getFromLangMap(json.title.asMdMap(), lang, json.originalLanguage)
|
||||||
if (it == null && originalLanguage == "ja") {
|
?: getAltTitle(json.altTitles, lang, json.originalLanguage)
|
||||||
langMap["jp"]
|
?: json.title.asMdMap<String>()[json.originalLanguage]
|
||||||
} else {
|
?: json.altTitles.firstNotNullOfOrNull { it[json.originalLanguage] }
|
||||||
it
|
.orEmpty()
|
||||||
}.orEmpty()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getFromLangMap(langMap: Map<String, String>, currentLang: String, originalLanguage: String): String? {
|
||||||
|
return langMap[currentLang]
|
||||||
|
?: langMap["en"]
|
||||||
|
?: if (originalLanguage == "ja") {
|
||||||
|
langMap["ja-ro"]
|
||||||
|
?: langMap["jp-ro"]
|
||||||
|
} else null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getAltTitle(langMaps: List<Map<String, String>>, currentLang: String, originalLanguage: String): String? {
|
||||||
|
return langMaps.firstNotNullOfOrNull { it[currentLang] }
|
||||||
|
?: langMaps.firstNotNullOfOrNull { it["en"] }
|
||||||
|
?: if (originalLanguage == "ja") {
|
||||||
|
langMaps.firstNotNullOfOrNull { it["ja-ro"] }
|
||||||
|
?: langMaps.firstNotNullOfOrNull { it["jp-ro"] }
|
||||||
|
} else null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun cdnCoverUrl(dexId: String, fileName: String): String {
|
fun cdnCoverUrl(dexId: String, fileName: String): String {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user