Update to support the latest Mangadex API
This commit is contained in:
parent
402e494cf7
commit
baeec9e2e7
@ -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
|
||||
|
@ -15,11 +15,15 @@ data class MangaListDto(
|
||||
data class MangaDto(
|
||||
val result: String,
|
||||
val data: MangaDataDto,
|
||||
val relationships: List<RelationshipDto>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class MangaDataDto(val id: String, val type: String, val attributes: MangaAttributesDto)
|
||||
data class MangaDataDto(
|
||||
val id: String,
|
||||
val type: String,
|
||||
val attributes: MangaAttributesDto,
|
||||
val relationships: List<RelationshipDto>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class MangaAttributesDto(
|
||||
@ -106,12 +110,12 @@ data class CoverListDto(
|
||||
@Serializable
|
||||
data class CoverDto(
|
||||
val data: CoverDataDto,
|
||||
val relationships: List<RelationshipDto>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class CoverDataDto(
|
||||
val attributes: CoverAttributesDto,
|
||||
val relationships: List<RelationshipDto>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
@ -59,7 +59,8 @@ class ApiMangaParser(
|
||||
title = MdUtil.cleanString(mangaAttributesDto.title.asMdMap().let { it[lang] ?: it["en"].orEmpty() })
|
||||
altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty()
|
||||
|
||||
mangaDto.relationships
|
||||
val mangaRelationshipsDto = mangaDto.data.relationships
|
||||
mangaRelationshipsDto
|
||||
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
||||
?.attributes
|
||||
?.fileName
|
||||
@ -69,11 +70,11 @@ class ApiMangaParser(
|
||||
|
||||
description = MdUtil.cleanDescription(mangaAttributesDto.description.asMdMap().let { it[lang] ?: it["en"].orEmpty() })
|
||||
|
||||
authors = mangaDto.relationships.filter { relationshipDto ->
|
||||
authors = mangaRelationshipsDto.filter { relationshipDto ->
|
||||
relationshipDto.type.equals(MdConstants.Types.author, true)
|
||||
}.mapNotNull { it.attributes!!.name }.distinct()
|
||||
|
||||
artists = mangaDto.relationships.filter { relationshipDto ->
|
||||
artists = mangaRelationshipsDto.filter { relationshipDto ->
|
||||
relationshipDto.type.equals(MdConstants.Types.artist, true)
|
||||
}.mapNotNull { it.attributes!!.name }.distinct()
|
||||
|
||||
@ -200,7 +201,7 @@ class ApiMangaParser(
|
||||
}
|
||||
|
||||
fun chapterParseForMangaId(chapterDto: ChapterDto): String? {
|
||||
return chapterDto.relationships.find { it.type.equals("manga", true) }?.id
|
||||
return chapterDto.data.relationships.find { it.type.equals("manga", true) }?.id
|
||||
}
|
||||
|
||||
fun StringBuilder.appends(string: String): StringBuilder = append("$string ")
|
||||
@ -252,7 +253,7 @@ class ApiMangaParser(
|
||||
// Convert from unix time
|
||||
val dateUpload = MdUtil.parseDate(attributes.publishAt)
|
||||
|
||||
val scanlatorName = networkChapter.relationships
|
||||
val scanlatorName = networkChapter.data.relationships
|
||||
.filter {
|
||||
it.type == MdConstants.Types.scanlator
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class MangaHandler(
|
||||
}
|
||||
|
||||
private fun getGroupMap(results: List<ChapterDto>): Map<String, String> {
|
||||
return results.map { chapter -> chapter.relationships }
|
||||
return results.map { chapter -> chapter.data.relationships }
|
||||
.flatten()
|
||||
.filter { it.type == MdConstants.Types.scanlator }
|
||||
.map { it.id to it.attributes!!.name!! }
|
||||
|
@ -28,13 +28,17 @@ class MangaDexService(
|
||||
): MangaListDto {
|
||||
return client.newCall(
|
||||
GET(
|
||||
MdApi.manga.toHttpUrl().newBuilder().apply {
|
||||
addQueryParameter("includes[]", MdConstants.Types.coverArt)
|
||||
addQueryParameter("limit", ids.size.toString())
|
||||
ids.forEach {
|
||||
addQueryParameter("ids[]", it)
|
||||
MdApi.manga.toHttpUrl()
|
||||
.newBuilder()
|
||||
.apply {
|
||||
addQueryParameter("includes[]", MdConstants.Types.coverArt)
|
||||
addQueryParameter("limit", ids.size.toString())
|
||||
ids.forEach {
|
||||
addQueryParameter("ids[]", it)
|
||||
}
|
||||
}
|
||||
}.build().toString(),
|
||||
.build()
|
||||
.toString(),
|
||||
cache = CacheControl.FORCE_NETWORK
|
||||
)
|
||||
).await().parseAs(MdUtil.jsonParser)
|
||||
@ -45,7 +49,16 @@ class MangaDexService(
|
||||
): MangaDto {
|
||||
return client.newCall(
|
||||
GET(
|
||||
"${MdApi.manga}/$id?includes[]=${MdConstants.Types.coverArt}&includes[]=${MdConstants.Types.author}&includes[]=${MdConstants.Types.artist}",
|
||||
MdApi.manga.toHttpUrl()
|
||||
.newBuilder()
|
||||
.apply {
|
||||
addPathSegment(id)
|
||||
addQueryParameter("includes[]", MdConstants.Types.coverArt)
|
||||
addQueryParameter("includes[]", MdConstants.Types.author)
|
||||
addQueryParameter("includes[]", MdConstants.Types.artist)
|
||||
}
|
||||
.build()
|
||||
.toString(),
|
||||
cache = CacheControl.FORCE_NETWORK
|
||||
)
|
||||
).await().parseAs(MdUtil.jsonParser)
|
||||
@ -56,12 +69,23 @@ class MangaDexService(
|
||||
translatedLanguage: String,
|
||||
offset: Int,
|
||||
): ChapterListDto {
|
||||
val url = "${MdApi.manga}/$id/feed?limit=500&includes[]=${MdConstants.Types.scanlator}&order[volume]=desc&order[chapter]=desc".toHttpUrl()
|
||||
val url = MdApi.manga.toHttpUrl()
|
||||
.newBuilder()
|
||||
.apply {
|
||||
addPathSegment(id)
|
||||
addPathSegment("feed")
|
||||
addQueryParameter("limit", "500")
|
||||
addQueryParameter("includes[]", MdConstants.Types.scanlator)
|
||||
addQueryParameter("order[volume]", "desc")
|
||||
addQueryParameter("order[chapter]", "desc")
|
||||
addQueryParameter("contentRating[]", "safe")
|
||||
addQueryParameter("contentRating[]", "suggestive")
|
||||
addQueryParameter("contentRating[]", "erotica")
|
||||
addQueryParameter("contentRating[]", "pornographic")
|
||||
addQueryParameter("translatedLanguage[]", translatedLanguage)
|
||||
addQueryParameter("offset", offset.toString())
|
||||
}.build()
|
||||
}
|
||||
.build()
|
||||
.toString()
|
||||
|
||||
return client.newCall(
|
||||
|
@ -266,7 +266,7 @@ class MdUtil {
|
||||
return MangaInfo(
|
||||
key = buildMangaUrl(json.data.id),
|
||||
title = cleanString(json.data.attributes.title.asMdMap().let { it[lang] ?: it["en"].orEmpty() }),
|
||||
cover = json.relationships
|
||||
cover = json.data.relationships
|
||||
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
||||
?.attributes
|
||||
?.fileName
|
||||
@ -280,14 +280,17 @@ class MdUtil {
|
||||
return "$cdnUrl/covers/$dexId/$fileName"
|
||||
}
|
||||
|
||||
fun getLoginBody(preferences: PreferencesHelper, mdList: MdList) = preferences.trackToken(mdList).get().nullIfBlank()?.let {
|
||||
try {
|
||||
jsonParser.decodeFromString<LoginBodyTokenDto>(it)
|
||||
} catch (e: SerializationException) {
|
||||
xLogD("Unable to load login body")
|
||||
null
|
||||
fun getLoginBody(preferences: PreferencesHelper, mdList: MdList) = preferences.trackToken(mdList)
|
||||
.get()
|
||||
.nullIfBlank()
|
||||
?.let {
|
||||
try {
|
||||
jsonParser.decodeFromString<LoginBodyTokenDto>(it)
|
||||
} catch (e: SerializationException) {
|
||||
xLogD("Unable to load login body")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun sessionToken(preferences: PreferencesHelper, mdList: MdList) = getLoginBody(preferences, mdList)?.session
|
||||
|
||||
@ -300,7 +303,10 @@ class MdUtil {
|
||||
}
|
||||
|
||||
fun getAuthHeaders(headers: Headers, preferences: PreferencesHelper, mdList: MdList) =
|
||||
headers.newBuilder().add("Authorization", "Bearer ${sessionToken(preferences, mdList) ?: throw NoSessionException()}").build()
|
||||
headers.newBuilder().add(
|
||||
"Authorization",
|
||||
"Bearer " + (sessionToken(preferences, mdList) ?: throw NoSessionException())
|
||||
).build()
|
||||
|
||||
fun getEnabledMangaDex(preferences: PreferencesHelper, sourceManager: SourceManager = Injekt.get()): MangaDex? {
|
||||
return getEnabledMangaDexs(preferences, sourceManager).let { mangadexs ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user