changed originLang filtering to filter at request time and moved relationships (#9036)

This commit is contained in:
loocool2 2021-09-11 10:07:06 -07:00 committed by GitHub
parent e84751d656
commit df42ef37cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 28 deletions

View File

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

View File

@ -134,7 +134,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val coverSuffix = preferences.getString(MDConstants.getCoverQualityPreferenceKey(dexLang), "")
val mangaList = mangaListDto.results.map { mangaDto ->
val fileName = mangaDto.relationships.firstOrNull { relationshipDto ->
val fileName = mangaDto.data.relationships.firstOrNull { relationshipDto ->
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
helper.createBasicManga(mangaDto, fileName, coverSuffix)
@ -148,7 +148,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val chapterListDto = helper.json.decodeFromString<ChapterListDto>(response.body!!.string())
val hasMoreResults = chapterListDto.limit + chapterListDto.offset < chapterListDto.total
val mangaIds = chapterListDto.results.map { it.relationships }.flatten()
val mangaIds = chapterListDto.results.map { it.data.relationships }.flatten()
.filter { it.type == MDConstants.manga }.map { it.id }.distinct()
val mangaUrl = MDConstants.apiMangaUrl.toHttpUrlOrNull()!!.newBuilder().apply {
@ -167,17 +167,6 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
if (preferences.getBoolean(MDConstants.getContentRatingPornographicPrefKey(dexLang), false)) {
addQueryParameter("contentRating[]", "pornographic")
}
if (preferences.getBoolean(MDConstants.getOriginalLanguageJapanesePref(dexLang), false)) {
addQueryParameter("originalLanguage[]", "ja")
}
// dex has zh and zh-hk for chinese manhua
if (preferences.getBoolean(MDConstants.getOriginalLanguageChinesePref(dexLang), false)) {
addQueryParameter("originalLanguage[]", "zh")
addQueryParameter("originalLanguage[]", "zh-hk")
}
if (preferences.getBoolean(MDConstants.getOriginalLanguageKoreanPref(dexLang), false)) {
addQueryParameter("originalLanguage[]", "ko")
}
mangaIds.forEach { id ->
addQueryParameter("ids[]", id)
@ -192,7 +181,8 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val coverSuffix = preferences.getString(MDConstants.getCoverQualityPreferenceKey(dexLang), "")
val mangaList = mangaIds.mapNotNull { mangaDtoMap[it] }.map { mangaDto ->
val fileName = mangaDto.relationships.firstOrNull { relationshipDto ->
val fileName = mangaDto.data.relationships.firstOrNull { relationshipDto ->
relationshipDto.type.equals(MDConstants.coverArt, true)
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
helper.createBasicManga(mangaDto, fileName, coverSuffix)
@ -201,12 +191,23 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
return MangasPage(mangaList, hasMoreResults)
}
override fun latestUpdatesRequest(page: Int): Request {
val url = MDConstants.apiChapterUrl.toHttpUrlOrNull()!!.newBuilder()
.addQueryParameter("offset", helper.getLatestChapterOffset(page))
.addQueryParameter("limit", MDConstants.latestChapterLimit.toString())
.addQueryParameter("translatedLanguage[]", dexLang)
.addQueryParameter("order[publishAt]", "desc")
.build().toString()
val url = MDConstants.apiChapterUrl.toHttpUrlOrNull()!!.newBuilder().apply {
addQueryParameter("offset", helper.getLatestChapterOffset(page))
addQueryParameter("limit", MDConstants.latestChapterLimit.toString())
addQueryParameter("translatedLanguage[]", dexLang)
addQueryParameter("order[publishAt]", "desc")
if (preferences.getBoolean(MDConstants.getOriginalLanguageJapanesePref(dexLang), false)) {
addQueryParameter("originalLanguage[]", "ja")
}
// dex has zh and zh-hk for chinese manhua
if (preferences.getBoolean(MDConstants.getOriginalLanguageChinesePref(dexLang), false)) {
addQueryParameter("originalLanguage[]", "zh")
addQueryParameter("originalLanguage[]", "zh-hk")
}
if (preferences.getBoolean(MDConstants.getOriginalLanguageKoreanPref(dexLang), false)) {
addQueryParameter("originalLanguage[]", "ko")
}
}.build().toString()
return GET(url, headers, CacheControl.FORCE_NETWORK)
}
@ -229,7 +230,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
throw Exception("Unable to process Chapter request. HTTP code: ${response.code}")
}
helper.json.decodeFromString<ChapterDto>(response.body!!.string()).relationships
helper.json.decodeFromString<ChapterDto>(response.body!!.string()).data.relationships
.find {
it.type == MDConstants.manga
}!!.id

View File

@ -204,15 +204,15 @@ class MangaDexHelper() {
Locale(attr.originalLanguage ?: "").displayLanguage
)
val authors = mangaDto.relationships.filter { relationshipDto ->
val authors = mangaDto.data.relationships.filter { relationshipDto ->
relationshipDto.type.equals(MDConstants.author, true)
}.mapNotNull { it.attributes!!.name }.distinct()
val artists = mangaDto.relationships.filter { relationshipDto ->
val artists = mangaDto.data.relationships.filter { relationshipDto ->
relationshipDto.type.equals(MDConstants.artist, true)
}.mapNotNull { it.attributes!!.name }.distinct()
val coverFileName = mangaDto.relationships.firstOrNull { relationshipDto ->
val coverFileName = mangaDto.data.relationships.firstOrNull { relationshipDto ->
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
@ -253,7 +253,7 @@ class MangaDexHelper() {
val data = chapterDto.data
val attr = data.attributes
val groups = chapterDto.relationships.filter { relationshipDto ->
val groups = chapterDto.data.relationships.filter { relationshipDto ->
relationshipDto.type.equals(
MDConstants.scanlator,
true

View File

@ -14,7 +14,6 @@ data class ChapterListDto(
data class ChapterDto(
val result: String,
val data: ChapterDataDto,
val relationships: List<RelationshipDto>,
)
@Serializable
@ -22,6 +21,7 @@ data class ChapterDataDto(
val id: String,
val type: String,
val attributes: ChapterAttributesDto,
val relationships: List<RelationshipDto>,
)
@Serializable

View File

@ -18,7 +18,6 @@ data class MangaListDto(
data class MangaDto(
val result: String,
val data: MangaDataDto,
val relationships: List<RelationshipDto>,
)
@Serializable
@ -39,6 +38,7 @@ data class MangaDataDto(
val id: String,
val type: String,
val attributes: MangaAttributesDto,
val relationships: List<RelationshipDto>,
)
@Serializable