Update Mangadex to new `chapterListDto` and `MangaListDto` following deprecation (#9046)

* update chapterListDto

* update MangaListDto

* increment md.extvercode
This commit is contained in:
nicki 2021-09-13 00:49:57 +05:30 committed by GitHub
parent 9901f97b5d
commit fb87b363e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 34 deletions

View File

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

View File

@ -133,11 +133,11 @@ 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.data.relationships.firstOrNull { relationshipDto ->
val mangaList = mangaListDto.data.map { mangaDataDto ->
val fileName = mangaDataDto.relationships.firstOrNull { relationshipDto ->
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
helper.createBasicManga(mangaDto, fileName, coverSuffix)
helper.createBasicManga(mangaDataDto, fileName, coverSuffix)
}
return MangasPage(mangaList, hasMoreResults)
@ -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.data.relationships }.flatten()
val mangaIds = chapterListDto.data.map { it.relationships }.flatten()
.filter { it.type == MDConstants.manga }.map { it.id }.distinct()
val mangaUrl = MDConstants.apiMangaUrl.toHttpUrlOrNull()!!.newBuilder().apply {
@ -176,16 +176,16 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val mangaResponse = client.newCall(GET(mangaUrl, headers, CacheControl.FORCE_NETWORK)).execute()
val mangaListDto = helper.json.decodeFromString<MangaListDto>(mangaResponse.body!!.string())
val mangaDtoMap = mangaListDto.results.associateBy({ it.data.id }, { it })
val mangaDtoMap = mangaListDto.data.associateBy({ it.id }, { it })
val coverSuffix = preferences.getString(MDConstants.getCoverQualityPreferenceKey(dexLang), "")
val mangaList = mangaIds.mapNotNull { mangaDtoMap[it] }.map { mangaDto ->
val fileName = mangaDto.data.relationships.firstOrNull { relationshipDto ->
val mangaList = mangaIds.mapNotNull { mangaDtoMap[it] }.map { mangaDataDto ->
val fileName = mangaDataDto.relationships.firstOrNull { relationshipDto ->
relationshipDto.type.equals(MDConstants.coverArt, true)
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
helper.createBasicManga(mangaDto, fileName, coverSuffix)
helper.createBasicManga(mangaDataDto, fileName, coverSuffix)
}
return MangasPage(mangaList, hasMoreResults)
@ -318,7 +318,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val shortLang = lang.substringBefore("-")
val coverSuffix = preferences.getString(MDConstants.getCoverQualityPreferenceKey(dexLang), "")
return helper.createManga(manga, fetchSimpleChapterList(manga, shortLang), shortLang, coverSuffix)
return helper.createManga(manga.data, fetchSimpleChapterList(manga, shortLang), shortLang, coverSuffix)
}
/**
@ -374,7 +374,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
try {
val chapterListResponse = helper.json.decodeFromString<ChapterListDto>(response.body!!.string())
val chapterListResults = chapterListResponse.results.toMutableList()
val chapterListResults = chapterListResponse.data.toMutableList()
val mangaId =
response.request.url.toString().substringBefore("/feed")
@ -392,7 +392,7 @@ abstract class MangaDex(override val lang: String, val dexLang: String) :
val newResponse =
client.newCall(actualChapterListRequest(mangaId, offset)).execute()
val newChapterList = helper.json.decodeFromString<ChapterListDto>(newResponse.body!!.string())
chapterListResults.addAll(newChapterList.results)
chapterListResults.addAll(newChapterList.data)
hasMoreResults = (limit + offset) < newChapterList.total
}

View File

@ -2,9 +2,9 @@ package eu.kanade.tachiyomi.extension.all.mangadex
import android.util.Log
import eu.kanade.tachiyomi.extension.all.mangadex.dto.AtHomeDto
import eu.kanade.tachiyomi.extension.all.mangadex.dto.ChapterDto
import eu.kanade.tachiyomi.extension.all.mangadex.dto.ChapterDataDto
import eu.kanade.tachiyomi.extension.all.mangadex.dto.MangaAttributesDto
import eu.kanade.tachiyomi.extension.all.mangadex.dto.MangaDto
import eu.kanade.tachiyomi.extension.all.mangadex.dto.MangaDataDto
import eu.kanade.tachiyomi.extension.all.mangadex.dto.asMdMap
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.source.model.Page
@ -166,15 +166,15 @@ class MangaDexHelper() {
/**
* create an SManga from json element only basic elements
*/
fun createBasicManga(mangaDto: MangaDto, coverFileName: String?, coverSuffix: String?): SManga {
fun createBasicManga(mangaDataDto: MangaDataDto, coverFileName: String?, coverSuffix: String?): SManga {
return SManga.create().apply {
url = "/manga/${mangaDto.data.id}"
title = cleanString(mangaDto.data.attributes.title.asMdMap()["en"] ?: "")
url = "/manga/${mangaDataDto.id}"
title = cleanString(mangaDataDto.attributes.title.asMdMap()["en"] ?: "")
coverFileName?.let {
thumbnail_url = when (coverSuffix != null && coverSuffix != "") {
true -> "${MDConstants.cdnUrl}/covers/${mangaDto.data.id}/$coverFileName$coverSuffix"
else -> "${MDConstants.cdnUrl}/covers/${mangaDto.data.id}/$coverFileName"
true -> "${MDConstants.cdnUrl}/covers/${mangaDataDto.id}/$coverFileName$coverSuffix"
else -> "${MDConstants.cdnUrl}/covers/${mangaDataDto.id}/$coverFileName"
}
}
}
@ -183,10 +183,9 @@ class MangaDexHelper() {
/**
* Create an SManga from json element with all details
*/
fun createManga(mangaDto: MangaDto, chapters: List<String>, lang: String, coverSuffix: String?): SManga {
fun createManga(mangaDataDto: MangaDataDto, chapters: List<String>, lang: String, coverSuffix: String?): SManga {
try {
val data = mangaDto.data
val attr = data.attributes
val attr = mangaDataDto.attributes
// things that will go with the genre tags but aren't actually genre
@ -204,15 +203,15 @@ class MangaDexHelper() {
Locale(attr.originalLanguage ?: "").displayLanguage
)
val authors = mangaDto.data.relationships.filter { relationshipDto ->
val authors = mangaDataDto.relationships.filter { relationshipDto ->
relationshipDto.type.equals(MDConstants.author, true)
}.mapNotNull { it.attributes!!.name }.distinct()
val artists = mangaDto.data.relationships.filter { relationshipDto ->
val artists = mangaDataDto.relationships.filter { relationshipDto ->
relationshipDto.type.equals(MDConstants.artist, true)
}.mapNotNull { it.attributes!!.name }.distinct()
val coverFileName = mangaDto.data.relationships.firstOrNull { relationshipDto ->
val coverFileName = mangaDataDto.relationships.firstOrNull { relationshipDto ->
relationshipDto.type.equals(MDConstants.coverArt, true)
}?.attributes?.fileName
@ -222,7 +221,7 @@ class MangaDexHelper() {
// map ids to tag names
val genreList = (
attr.tags
.map { it.id }
.map { mangaDataDto.id }
.map { dexId ->
tags.firstOrNull { it.id == dexId }
}
@ -232,7 +231,7 @@ class MangaDexHelper() {
.filter { it.isNullOrBlank().not() }
val desc = attr.description.asMdMap()
return createBasicManga(mangaDto, coverFileName, coverSuffix).apply {
return createBasicManga(mangaDataDto, coverFileName, coverSuffix).apply {
description = cleanString(desc[lang] ?: desc["en"] ?: "")
author = authors.joinToString(", ")
artist = artists.joinToString(", ")
@ -248,12 +247,11 @@ class MangaDexHelper() {
/**
* create the SChapter from json
*/
fun createChapter(chapterDto: ChapterDto): SChapter? {
fun createChapter(chapterDataDto: ChapterDataDto): SChapter? {
try {
val data = chapterDto.data
val attr = data.attributes
val attr = chapterDataDto.attributes
val groups = chapterDto.data.relationships.filter { relationshipDto ->
val groups = chapterDataDto.relationships.filter { relationshipDto ->
relationshipDto.type.equals(
MDConstants.scanlator,
true
@ -299,7 +297,7 @@ class MangaDexHelper() {
// In future calculate [END] if non mvp api doesnt provide it
return SChapter.create().apply {
url = "/chapter/${data.id}"
url = "/chapter/${chapterDataDto.id}"
name = cleanString(chapterName.joinToString(" "))
date_upload = parseDate(attr.publishAt)
scanlator = groups

View File

@ -7,7 +7,7 @@ data class ChapterListDto(
val limit: Int,
val offset: Int,
val total: Int,
val results: List<ChapterDto>,
val data: List<ChapterDataDto>,
)
@Serializable

View File

@ -11,7 +11,7 @@ data class MangaListDto(
val limit: Int,
val offset: Int,
val total: Int,
val results: List<MangaDto>,
val data: List<MangaDataDto>,
)
@Serializable