Fix most unknown titles

This commit is contained in:
Jobobby04 2021-11-14 18:09:47 -05:00
parent fb4d15d9ef
commit b227f2a4a5
2 changed files with 6 additions and 6 deletions

View File

@ -57,7 +57,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.asMdMap().let { it[lang] ?: it["en"].orEmpty() }) title = MdUtil.cleanString(MdUtil.getFromLangMap(mangaAttributesDto.title.asMdMap(), lang, mangaAttributesDto.originalLanguage))
altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty() altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty()
val mangaRelationshipsDto = mangaDto.data.relationships val mangaRelationshipsDto = mangaDto.data.relationships
@ -69,7 +69,7 @@ class ApiMangaParser(
cover = MdUtil.cdnCoverUrl(mangaDto.data.id, coverFileName) cover = MdUtil.cdnCoverUrl(mangaDto.data.id, coverFileName)
} }
description = MdUtil.cleanDescription(MdUtil.getTitle(mangaAttributesDto.description.asMdMap(), lang, mangaAttributesDto.originalLanguage)) description = MdUtil.cleanDescription(MdUtil.getFromLangMap(mangaAttributesDto.description.asMdMap(), lang, mangaAttributesDto.originalLanguage))
authors = mangaRelationshipsDto.filter { relationshipDto -> authors = mangaRelationshipsDto.filter { relationshipDto ->
relationshipDto.type.equals(MdConstants.Types.author, true) relationshipDto.type.equals(MdConstants.Types.author, true)

View File

@ -265,7 +265,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(getTitle(json.attributes.title.asMdMap(), lang, json.attributes.originalLanguage)), title = cleanString(getFromLangMap(json.attributes.title.asMdMap(), lang, json.attributes.originalLanguage)),
cover = json.relationships cover = json.relationships
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt } .firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
?.attributes ?.attributes
@ -276,10 +276,10 @@ class MdUtil {
) )
} }
fun getTitle(titleMap: Map<String, String?>, currentLang: String, originalLanguage: String): String { fun getFromLangMap(langMap: Map<String, String?>, currentLang: String, originalLanguage: String): String {
return titleMap[currentLang] ?: titleMap["en"] ?: titleMap[originalLanguage].let { return langMap[currentLang] ?: langMap["en"] ?: langMap[originalLanguage].let {
if (it == null && originalLanguage == "ja") { if (it == null && originalLanguage == "ja") {
titleMap["jp"] langMap["jp"]
} else { } else {
it it
}.orEmpty() }.orEmpty()