Fix Remanga chapters parsing
This commit is contained in:
@@ -98,9 +98,7 @@ class RemangaRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposito
|
|||||||
}
|
}
|
||||||
val branchId = content.getJSONArray("branches").optJSONObject(0)
|
val branchId = content.getJSONArray("branches").optJSONObject(0)
|
||||||
?.getLong("id") ?: throw ParseException("No branches found")
|
?.getLong("id") ?: throw ParseException("No branches found")
|
||||||
val chapters = loaderContext.httpGet(
|
val chapters = grabChapters(domain, branchId)
|
||||||
url = "https://api.$domain/api/titles/chapters/?branch_id=$branchId"
|
|
||||||
).parseJson().getJSONArray("content")
|
|
||||||
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US)
|
||||||
return manga.copy(
|
return manga.copy(
|
||||||
description = content.getString("description"),
|
description = content.getString("description"),
|
||||||
@@ -123,7 +121,7 @@ class RemangaRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposito
|
|||||||
MangaChapter(
|
MangaChapter(
|
||||||
id = generateUid(id),
|
id = generateUid(id),
|
||||||
url = "/api/titles/chapters/$id/",
|
url = "/api/titles/chapters/$id/",
|
||||||
number = chapters.length() - i,
|
number = chapters.size - i,
|
||||||
name = buildString {
|
name = buildString {
|
||||||
append("Том ")
|
append("Том ")
|
||||||
append(jo.optString("tome", "0"))
|
append(jo.optString("tome", "0"))
|
||||||
@@ -211,6 +209,26 @@ class RemangaRepository(loaderContext: MangaLoaderContext) : RemoteMangaReposito
|
|||||||
source = source,
|
source = source,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private suspend fun grabChapters(domain: String, branchId: Long): List<JSONObject> {
|
||||||
|
val result = ArrayList<JSONObject>(100)
|
||||||
|
var page = 1
|
||||||
|
while (true) {
|
||||||
|
val content = loaderContext.httpGet(
|
||||||
|
"https://api.$domain/api/titles/chapters/?branch_id=$branchId&page=$page&count=100"
|
||||||
|
).parseJson().getJSONArray("content")
|
||||||
|
val len = content.length()
|
||||||
|
if (len == 0) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
result.ensureCapacity(result.size + len)
|
||||||
|
for (i in 0 until len) {
|
||||||
|
result.add(content.getJSONObject(i))
|
||||||
|
}
|
||||||
|
page++
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
private companion object {
|
private companion object {
|
||||||
|
|
||||||
const val PAGE_SIZE = 30
|
const val PAGE_SIZE = 30
|
||||||
|
|||||||
Reference in New Issue
Block a user