SlimeRead: Fix "Unexpected JSON token" on pageList and choose apiUrl randomly (#1837)

* Fix pageList and update apiUrl (again)

* Random apiUrl

* Inline

---------

Co-authored-by: stevenyomi <95685115+stevenyomi@users.noreply.github.com>
This commit is contained in:
bapeey 2024-03-14 12:48:10 -05:00 committed by Draff
parent e10e72ad98
commit ca5365cc6c
2 changed files with 12 additions and 3 deletions

View File

@ -1,7 +1,7 @@
ext { ext {
extName = 'SlimeRead' extName = 'SlimeRead'
extClass = '.SlimeRead' extClass = '.SlimeRead'
extVersionCode = 4 extVersionCode = 5
isNsfw = true isNsfw = true
} }

View File

@ -15,6 +15,7 @@ import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SChapter
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream import kotlinx.serialization.json.decodeFromStream
import okhttp3.HttpUrl import okhttp3.HttpUrl
@ -30,7 +31,10 @@ class SlimeRead : HttpSource() {
override val baseUrl = "https://slimeread.com" override val baseUrl = "https://slimeread.com"
private val apiUrl = "https://old.slimeread.com:8443" private val apiUrl = run {
val apiList = arrayOf("free", "beta", "api", "data", "test", "dev", "staging", "prod", "old", "new")
"https://${apiList.random()}.slimeread.com:8443"
}
override val lang = "pt-BR" override val lang = "pt-BR"
@ -162,7 +166,12 @@ class SlimeRead : HttpSource() {
override fun pageListRequest(chapter: SChapter) = GET(apiUrl + chapter.url, headers) override fun pageListRequest(chapter: SChapter) = GET(apiUrl + chapter.url, headers)
override fun pageListParse(response: Response): List<Page> { override fun pageListParse(response: Response): List<Page> {
val pages = response.parseAs<List<PageListDto>>().flatMap { it.pages } val body = response.body.string()
val pages = if (body.startsWith("{")) {
json.decodeFromString<Map<String, PageListDto>>(body).values.flatMap { it.pages }
} else {
json.decodeFromString<List<PageListDto>>(body).flatMap { it.pages }
}
return pages.mapIndexed { index, item -> return pages.mapIndexed { index, item ->
Page(index, "", item.url) Page(index, "", item.url)