Migrate to the new mangadex list response
This commit is contained in:
parent
fcf6776fe4
commit
e38255e895
@ -7,8 +7,8 @@ data class ChapterListDto(
|
||||
override val limit: Int,
|
||||
override val offset: Int,
|
||||
override val total: Int,
|
||||
override val results: List<ChapterDto>,
|
||||
) : ListCallDto<ChapterDto>
|
||||
override val data: List<ChapterDataDto>,
|
||||
) : ListCallDto<ChapterDataDto>
|
||||
|
||||
@Serializable
|
||||
data class ChapterDto(
|
||||
@ -45,8 +45,8 @@ data class GroupListDto(
|
||||
override val limit: Int,
|
||||
override val offset: Int,
|
||||
override val total: Int,
|
||||
override val results: List<GroupDto>,
|
||||
) : ListCallDto<GroupDto>
|
||||
override val data: List<GroupDataDto>,
|
||||
) : ListCallDto<GroupDataDto>
|
||||
|
||||
@Serializable
|
||||
data class GroupDto(
|
||||
|
@ -4,5 +4,5 @@ interface ListCallDto<T> {
|
||||
val limit: Int
|
||||
val offset: Int
|
||||
val total: Int
|
||||
val results: List<T>
|
||||
val data: List<T>
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ data class MangaListDto(
|
||||
override val limit: Int,
|
||||
override val offset: Int,
|
||||
override val total: Int,
|
||||
override val results: List<MangaDto>,
|
||||
) : ListCallDto<MangaDto>
|
||||
override val data: List<MangaDataDto>
|
||||
) : ListCallDto<MangaDataDto>
|
||||
|
||||
@Serializable
|
||||
data class MangaDto(
|
||||
|
@ -3,6 +3,7 @@ package exh.md.handlers
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import exh.log.xLogE
|
||||
import exh.md.dto.ChapterDataDto
|
||||
import exh.md.dto.ChapterDto
|
||||
import exh.md.dto.MangaDto
|
||||
import exh.md.utils.MdConstants
|
||||
@ -189,7 +190,7 @@ class ApiMangaParser(
|
||||
else -> SManga.UNKNOWN
|
||||
}
|
||||
|
||||
fun chapterListParse(chapterListResponse: List<ChapterDto>, groupMap: Map<String, String>): List<ChapterInfo> {
|
||||
fun chapterListParse(chapterListResponse: List<ChapterDataDto>, groupMap: Map<String, String>): List<ChapterInfo> {
|
||||
val now = System.currentTimeMillis()
|
||||
|
||||
return chapterListResponse.asSequence()
|
||||
@ -207,11 +208,11 @@ class ApiMangaParser(
|
||||
fun StringBuilder.appends(string: String): StringBuilder = append("$string ")
|
||||
|
||||
private fun mapChapter(
|
||||
networkChapter: ChapterDto,
|
||||
networkChapter: ChapterDataDto,
|
||||
groups: Map<String, String>,
|
||||
): ChapterInfo {
|
||||
val attributes = networkChapter.data.attributes
|
||||
val key = MdUtil.chapterSuffix + networkChapter.data.id
|
||||
val attributes = networkChapter.attributes
|
||||
val key = MdUtil.chapterSuffix + networkChapter.id
|
||||
val chapterName = StringBuilder()
|
||||
// Build chapter name
|
||||
|
||||
@ -253,7 +254,7 @@ class ApiMangaParser(
|
||||
// Convert from unix time
|
||||
val dateUpload = MdUtil.parseDate(attributes.publishAt)
|
||||
|
||||
val scanlatorName = networkChapter.data.relationships
|
||||
val scanlatorName = networkChapter.relationships
|
||||
.filter {
|
||||
it.type == MdConstants.Types.scanlator
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import eu.kanade.tachiyomi.source.model.MetadataMangasPage
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import exh.md.dto.MangaDto
|
||||
import exh.md.dto.MangaDataDto
|
||||
import exh.md.dto.ReadingStatusDto
|
||||
import exh.md.service.MangaDexAuthService
|
||||
import exh.md.utils.FollowStatus
|
||||
@ -28,13 +28,13 @@ class FollowsHandler(
|
||||
return withIOContext {
|
||||
val follows = service.userFollowList(MdUtil.mangaLimit * page)
|
||||
|
||||
if (follows.results.isEmpty()) {
|
||||
if (follows.data.isEmpty()) {
|
||||
return@withIOContext MetadataMangasPage(emptyList(), false, emptyList())
|
||||
}
|
||||
|
||||
val hasMoreResults = follows.limit + follows.offset under follows.total
|
||||
val statusListResponse = service.readingStatusAllManga()
|
||||
val results = followsParseMangaPage(follows.results, statusListResponse.statuses)
|
||||
val results = followsParseMangaPage(follows.data, statusListResponse.statuses)
|
||||
|
||||
MetadataMangasPage(results.map { it.first }, hasMoreResults, results.map { it.second })
|
||||
}
|
||||
@ -45,7 +45,7 @@ class FollowsHandler(
|
||||
* used when multiple follows
|
||||
*/
|
||||
private fun followsParseMangaPage(
|
||||
response: List<MangaDto>,
|
||||
response: List<MangaDataDto>,
|
||||
statuses: Map<String, String?>
|
||||
): List<Pair<SManga, MangaDexSearchMetadata>> {
|
||||
val comparator = compareBy<Pair<SManga, MangaDexSearchMetadata>> { it.second.followStatus }
|
||||
@ -56,7 +56,7 @@ class FollowsHandler(
|
||||
it,
|
||||
lang
|
||||
).toSManga() to MangaDexSearchMetadata().apply {
|
||||
followStatus = FollowStatus.fromDex(statuses[it.data.id]).int
|
||||
followStatus = FollowStatus.fromDex(statuses[it.id]).int
|
||||
}
|
||||
}.sortedWith(comparator)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.util.lang.runAsObservable
|
||||
import eu.kanade.tachiyomi.util.lang.withIOContext
|
||||
import exh.md.dto.ChapterDto
|
||||
import exh.md.dto.ChapterDataDto
|
||||
import exh.md.service.MangaDexService
|
||||
import exh.md.utils.MdConstants
|
||||
import exh.md.utils.MdUtil
|
||||
@ -52,8 +52,8 @@ class MangaHandler(
|
||||
}
|
||||
}
|
||||
|
||||
private fun getGroupMap(results: List<ChapterDto>): Map<String, String> {
|
||||
return results.map { chapter -> chapter.data.relationships }
|
||||
private fun getGroupMap(results: List<ChapterDataDto>): Map<String, String> {
|
||||
return results.map { chapter -> chapter.relationships }
|
||||
.flatten()
|
||||
.filter { it.type == MdConstants.Types.scanlator }
|
||||
.map { it.id to it.attributes!!.name!! }
|
||||
|
@ -26,7 +26,7 @@ class SimilarHandler(
|
||||
it.id
|
||||
}
|
||||
|
||||
val mangaList = service.viewMangas(ids).results.map {
|
||||
val mangaList = service.viewMangas(ids).data.map {
|
||||
MdUtil.createMangaEntry(it, lang).toSManga()
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ suspend fun <T> mdListCall(request: suspend (offset: Int) -> ListCallDto<T>): Li
|
||||
|
||||
do {
|
||||
val list = request(offset)
|
||||
results += list.results
|
||||
results += list.data
|
||||
offset += list.limit
|
||||
} while (offset under list.total)
|
||||
|
||||
|
@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.online.all.MangaDex
|
||||
import exh.log.xLogD
|
||||
import exh.md.dto.LoginBodyTokenDto
|
||||
import exh.md.dto.MangaDto
|
||||
import exh.md.dto.MangaDataDto
|
||||
import exh.md.network.NoSessionException
|
||||
import exh.source.getMainSource
|
||||
import exh.util.floor
|
||||
@ -262,16 +262,16 @@ class MdUtil {
|
||||
fun parseDate(dateAsString: String): Long =
|
||||
dateFormatter.parse(dateAsString)?.time ?: 0
|
||||
|
||||
fun createMangaEntry(json: MangaDto, lang: String): MangaInfo {
|
||||
fun createMangaEntry(json: MangaDataDto, lang: String): MangaInfo {
|
||||
return MangaInfo(
|
||||
key = buildMangaUrl(json.data.id),
|
||||
title = cleanString(getTitle(json.data.attributes.title.asMdMap(), lang, json.data.attributes.originalLanguage)),
|
||||
cover = json.data.relationships
|
||||
key = buildMangaUrl(json.id),
|
||||
title = cleanString(getTitle(json.attributes.title.asMdMap(), lang, json.attributes.originalLanguage)),
|
||||
cover = json.relationships
|
||||
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
||||
?.attributes
|
||||
?.fileName
|
||||
?.let { coverFileName ->
|
||||
cdnCoverUrl(json.data.id, coverFileName)
|
||||
cdnCoverUrl(json.id, coverFileName)
|
||||
}.orEmpty()
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user