MangaDex: Title fetching improvement (#9238)

Some manga somehow has romaji title tagged as "jp" language. So also use
altTitles list and use extension language as the base language when
searching while keeping english as fallback.

This reduces the possibility of this extension returning empty title.
This commit is contained in:
Ivan Iskandar 2021-09-26 19:23:14 +07:00 committed by GitHub
parent a0873ea677
commit f92453cdcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 9 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'MangaDex'
pkgNameSuffix = 'all.mangadex'
extClass = '.MangaDexFactory'
extVersionCode = 138
extVersionCode = 139
containsNsfw = true
}

View File

@ -137,7 +137,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val fileName = mangaDataDto.relationships.firstOrNull { relationshipDto ->
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
helper.createBasicManga(mangaDataDto, fileName, coverSuffix)
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
}
return MangasPage(mangaList, hasMoreResults)
@ -185,7 +185,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
relationshipDto.type.equals(MDConstants.coverArt, true)
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
helper.createBasicManga(mangaDataDto, fileName, coverSuffix)
helper.createBasicManga(mangaDataDto, fileName, coverSuffix, dexLang)
}
return MangasPage(mangaList, hasMoreResults)
@ -316,10 +316,8 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
override fun mangaDetailsParse(response: Response): SManga {
val manga = helper.json.decodeFromString<MangaDto>(response.body!!.string())
val shortLang = lang.substringBefore("-")
val coverSuffix = preferences.getString(MDConstants.getCoverQualityPreferenceKey(dexLang), "")
return helper.createManga(manga.data, fetchSimpleChapterList(manga, shortLang), shortLang, coverSuffix)
return helper.createManga(manga.data, fetchSimpleChapterList(manga, dexLang), dexLang, coverSuffix)
}
/**

View File

@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonArray
import okhttp3.CacheControl
import okhttp3.Headers
import okhttp3.OkHttpClient
@ -166,10 +167,23 @@ class MangaDexHelper() {
/**
* create an SManga from json element only basic elements
*/
fun createBasicManga(mangaDataDto: MangaDataDto, coverFileName: String?, coverSuffix: String?): SManga {
fun createBasicManga(
mangaDataDto: MangaDataDto,
coverFileName: String?,
coverSuffix: String?,
lang: String
): SManga {
return SManga.create().apply {
url = "/manga/${mangaDataDto.id}"
title = cleanString(mangaDataDto.attributes.title.asMdMap()["en"] ?: "")
val titleMap = mangaDataDto.attributes.title.asMdMap()
val dirtyTitle = titleMap[lang]
?: titleMap["en"]
?: mangaDataDto.attributes.altTitles.jsonArray
.find {
val altTitle = it.asMdMap()
altTitle[lang] ?: altTitle["en"] != null
}?.asMdMap()?.values?.singleOrNull()
title = cleanString(dirtyTitle ?: "")
coverFileName?.let {
thumbnail_url = when (coverSuffix != null && coverSuffix != "") {
@ -231,7 +245,7 @@ class MangaDexHelper() {
.filter { it.isNullOrBlank().not() }
val desc = attr.description.asMdMap()
return createBasicManga(mangaDataDto, coverFileName, coverSuffix).apply {
return createBasicManga(mangaDataDto, coverFileName, coverSuffix, lang).apply {
description = cleanString(desc[lang] ?: desc["en"] ?: "")
author = authors.joinToString(", ")
artist = artists.joinToString(", ")

View File

@ -44,6 +44,7 @@ data class MangaDataDto(
@Serializable
data class MangaAttributesDto(
val title: JsonElement,
val altTitles: JsonElement,
val description: JsonElement,
val originalLanguage: String,
val lastVolume: String?,