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