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(
|
data class ChapterDto(
|
||||||
val result: String,
|
val result: String,
|
||||||
val data: ChapterDataDto,
|
val data: ChapterDataDto,
|
||||||
val relationships: List<RelationshipDto>,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
@ -22,6 +21,7 @@ data class ChapterDataDto(
|
|||||||
val id: String,
|
val id: String,
|
||||||
val type: String,
|
val type: String,
|
||||||
val attributes: ChapterAttributesDto,
|
val attributes: ChapterAttributesDto,
|
||||||
|
val relationships: List<RelationshipDto>,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -15,11 +15,15 @@ data class MangaListDto(
|
|||||||
data class MangaDto(
|
data class MangaDto(
|
||||||
val result: String,
|
val result: String,
|
||||||
val data: MangaDataDto,
|
val data: MangaDataDto,
|
||||||
val relationships: List<RelationshipDto>,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@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
|
@Serializable
|
||||||
data class MangaAttributesDto(
|
data class MangaAttributesDto(
|
||||||
@ -106,12 +110,12 @@ data class CoverListDto(
|
|||||||
@Serializable
|
@Serializable
|
||||||
data class CoverDto(
|
data class CoverDto(
|
||||||
val data: CoverDataDto,
|
val data: CoverDataDto,
|
||||||
val relationships: List<RelationshipDto>,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class CoverDataDto(
|
data class CoverDataDto(
|
||||||
val attributes: CoverAttributesDto,
|
val attributes: CoverAttributesDto,
|
||||||
|
val relationships: List<RelationshipDto>,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
|
@ -59,7 +59,8 @@ class ApiMangaParser(
|
|||||||
title = MdUtil.cleanString(mangaAttributesDto.title.asMdMap().let { it[lang] ?: it["en"].orEmpty() })
|
title = MdUtil.cleanString(mangaAttributesDto.title.asMdMap().let { it[lang] ?: it["en"].orEmpty() })
|
||||||
altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty()
|
altTitles = mangaAttributesDto.altTitles.mapNotNull { it[lang] }.nullIfEmpty()
|
||||||
|
|
||||||
mangaDto.relationships
|
val mangaRelationshipsDto = mangaDto.data.relationships
|
||||||
|
mangaRelationshipsDto
|
||||||
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
||||||
?.attributes
|
?.attributes
|
||||||
?.fileName
|
?.fileName
|
||||||
@ -69,11 +70,11 @@ class ApiMangaParser(
|
|||||||
|
|
||||||
description = MdUtil.cleanDescription(mangaAttributesDto.description.asMdMap().let { it[lang] ?: it["en"].orEmpty() })
|
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)
|
relationshipDto.type.equals(MdConstants.Types.author, true)
|
||||||
}.mapNotNull { it.attributes!!.name }.distinct()
|
}.mapNotNull { it.attributes!!.name }.distinct()
|
||||||
|
|
||||||
artists = mangaDto.relationships.filter { relationshipDto ->
|
artists = mangaRelationshipsDto.filter { relationshipDto ->
|
||||||
relationshipDto.type.equals(MdConstants.Types.artist, true)
|
relationshipDto.type.equals(MdConstants.Types.artist, true)
|
||||||
}.mapNotNull { it.attributes!!.name }.distinct()
|
}.mapNotNull { it.attributes!!.name }.distinct()
|
||||||
|
|
||||||
@ -200,7 +201,7 @@ class ApiMangaParser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun chapterParseForMangaId(chapterDto: ChapterDto): String? {
|
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 ")
|
fun StringBuilder.appends(string: String): StringBuilder = append("$string ")
|
||||||
@ -252,7 +253,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.relationships
|
val scanlatorName = networkChapter.data.relationships
|
||||||
.filter {
|
.filter {
|
||||||
it.type == MdConstants.Types.scanlator
|
it.type == MdConstants.Types.scanlator
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class MangaHandler(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getGroupMap(results: List<ChapterDto>): Map<String, String> {
|
private fun getGroupMap(results: List<ChapterDto>): Map<String, String> {
|
||||||
return results.map { chapter -> chapter.relationships }
|
return results.map { chapter -> chapter.data.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!! }
|
||||||
|
@ -28,13 +28,17 @@ class MangaDexService(
|
|||||||
): MangaListDto {
|
): MangaListDto {
|
||||||
return client.newCall(
|
return client.newCall(
|
||||||
GET(
|
GET(
|
||||||
MdApi.manga.toHttpUrl().newBuilder().apply {
|
MdApi.manga.toHttpUrl()
|
||||||
|
.newBuilder()
|
||||||
|
.apply {
|
||||||
addQueryParameter("includes[]", MdConstants.Types.coverArt)
|
addQueryParameter("includes[]", MdConstants.Types.coverArt)
|
||||||
addQueryParameter("limit", ids.size.toString())
|
addQueryParameter("limit", ids.size.toString())
|
||||||
ids.forEach {
|
ids.forEach {
|
||||||
addQueryParameter("ids[]", it)
|
addQueryParameter("ids[]", it)
|
||||||
}
|
}
|
||||||
}.build().toString(),
|
}
|
||||||
|
.build()
|
||||||
|
.toString(),
|
||||||
cache = CacheControl.FORCE_NETWORK
|
cache = CacheControl.FORCE_NETWORK
|
||||||
)
|
)
|
||||||
).await().parseAs(MdUtil.jsonParser)
|
).await().parseAs(MdUtil.jsonParser)
|
||||||
@ -45,7 +49,16 @@ class MangaDexService(
|
|||||||
): MangaDto {
|
): MangaDto {
|
||||||
return client.newCall(
|
return client.newCall(
|
||||||
GET(
|
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
|
cache = CacheControl.FORCE_NETWORK
|
||||||
)
|
)
|
||||||
).await().parseAs(MdUtil.jsonParser)
|
).await().parseAs(MdUtil.jsonParser)
|
||||||
@ -56,12 +69,23 @@ class MangaDexService(
|
|||||||
translatedLanguage: String,
|
translatedLanguage: String,
|
||||||
offset: Int,
|
offset: Int,
|
||||||
): ChapterListDto {
|
): 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()
|
.newBuilder()
|
||||||
.apply {
|
.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("translatedLanguage[]", translatedLanguage)
|
||||||
addQueryParameter("offset", offset.toString())
|
addQueryParameter("offset", offset.toString())
|
||||||
}.build()
|
}
|
||||||
|
.build()
|
||||||
.toString()
|
.toString()
|
||||||
|
|
||||||
return client.newCall(
|
return client.newCall(
|
||||||
|
@ -266,7 +266,7 @@ class MdUtil {
|
|||||||
return MangaInfo(
|
return MangaInfo(
|
||||||
key = buildMangaUrl(json.data.id),
|
key = buildMangaUrl(json.data.id),
|
||||||
title = cleanString(json.data.attributes.title.asMdMap().let { it[lang] ?: it["en"].orEmpty() }),
|
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 }
|
.firstOrNull { relationshipDto -> relationshipDto.type == MdConstants.Types.coverArt }
|
||||||
?.attributes
|
?.attributes
|
||||||
?.fileName
|
?.fileName
|
||||||
@ -280,7 +280,10 @@ class MdUtil {
|
|||||||
return "$cdnUrl/covers/$dexId/$fileName"
|
return "$cdnUrl/covers/$dexId/$fileName"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLoginBody(preferences: PreferencesHelper, mdList: MdList) = preferences.trackToken(mdList).get().nullIfBlank()?.let {
|
fun getLoginBody(preferences: PreferencesHelper, mdList: MdList) = preferences.trackToken(mdList)
|
||||||
|
.get()
|
||||||
|
.nullIfBlank()
|
||||||
|
?.let {
|
||||||
try {
|
try {
|
||||||
jsonParser.decodeFromString<LoginBodyTokenDto>(it)
|
jsonParser.decodeFromString<LoginBodyTokenDto>(it)
|
||||||
} catch (e: SerializationException) {
|
} catch (e: SerializationException) {
|
||||||
@ -300,7 +303,10 @@ class MdUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getAuthHeaders(headers: Headers, preferences: PreferencesHelper, mdList: MdList) =
|
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? {
|
fun getEnabledMangaDex(preferences: PreferencesHelper, sourceManager: SourceManager = Injekt.get()): MangaDex? {
|
||||||
return getEnabledMangaDexs(preferences, sourceManager).let { mangadexs ->
|
return getEnabledMangaDexs(preferences, sourceManager).let { mangadexs ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user