Fix DesuMe parser

This commit is contained in:
Koitharu
2021-02-01 20:37:41 +02:00
parent c25ee93ccb
commit 1f2f40f077
3 changed files with 13 additions and 6 deletions

View File

@@ -27,6 +27,9 @@ class DesuMeRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
sortOrder: SortOrder?,
tag: MangaTag?
): List<Manga> {
if (query != null && offset != 0) {
return emptyList()
}
val domain = getDomain()
val url = buildString {
append("https://")
@@ -76,6 +79,8 @@ class DesuMeRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
val json = loaderContext.httpGet(url).parseJson().getJSONObject("response")
?: throw ParseException("Invalid response")
val baseChapterUrl = manga.url + "/chapter/"
val chaptersList = json.getJSONObject("chapters").getJSONArray("list")
val totalChapters = chaptersList.length()
return manga.copy(
tags = json.getJSONArray("genres").mapToSet {
MangaTag(
@@ -85,16 +90,16 @@ class DesuMeRepository(loaderContext: MangaLoaderContext) : RemoteMangaRepositor
)
},
description = json.getString("description"),
chapters = json.getJSONObject("chapters").getJSONArray("list").mapIndexed { i, it ->
chapters = chaptersList.mapIndexed { i, it ->
val chid = it.getLong("id")
MangaChapter(
id = generateUid(chid),
source = manga.source,
url = "$baseChapterUrl$chid",
name = it.optString("title", "${manga.title} #${it.getDouble("ch")}"),
number = i + 1
name = it.getStringOrNull("title") ?: "${manga.title} #${it.getDouble("ch")}",
number = totalChapters - i
)
}
}.reversed()
)
}

View File

@@ -61,7 +61,7 @@ class MangaIndex(source: String?) {
)
}.getOrNull()
fun getCoverEntry(): String? = json.optString("cover_entry")
fun getCoverEntry(): String? = json.getStringOrNull("cover_entry")
fun addChapter(chapter: MangaChapter) {
val chapters = json.getJSONObject("chapters")

View File

@@ -30,7 +30,9 @@ fun <T> JSONArray.mapIndexed(block: (Int, JSONObject) -> T): List<T> {
return result
}
fun JSONObject.getStringOrNull(name: String): String? = opt(name)?.toString()
fun JSONObject.getStringOrNull(name: String): String? = opt(name)?.takeUnless {
it === JSONObject.NULL
}?.toString()
operator fun JSONArray.iterator(): Iterator<JSONObject> = JSONIterator(this)