|
|
|
|
@ -5,7 +5,6 @@ import okhttp3.Response
|
|
|
|
|
import org.json.JSONArray
|
|
|
|
|
import org.json.JSONException
|
|
|
|
|
import org.json.JSONObject
|
|
|
|
|
import org.jsoup.HttpStatusException
|
|
|
|
|
import org.koitharu.kotatsu.parsers.MangaLoaderContext
|
|
|
|
|
import org.koitharu.kotatsu.parsers.MangaParser
|
|
|
|
|
import org.koitharu.kotatsu.parsers.MangaParserAuthProvider
|
|
|
|
|
@ -113,12 +112,10 @@ internal class RemangaParser(
|
|
|
|
|
val domain = getDomain()
|
|
|
|
|
val slug = manga.url.find(regexLastUrlPath)
|
|
|
|
|
?: throw ParseException("Cannot obtain slug from ${manga.url}")
|
|
|
|
|
val data = catch401 {
|
|
|
|
|
context.httpGet(
|
|
|
|
|
val data = context.httpGet(
|
|
|
|
|
url = "https://api.$domain/api/titles/$slug/",
|
|
|
|
|
headers = getApiHeaders(),
|
|
|
|
|
)
|
|
|
|
|
}.parseJson()
|
|
|
|
|
).handle401().parseJson()
|
|
|
|
|
val content = try {
|
|
|
|
|
data.getJSONObject("content")
|
|
|
|
|
} catch (e: JSONException) {
|
|
|
|
|
@ -172,9 +169,9 @@ internal class RemangaParser(
|
|
|
|
|
|
|
|
|
|
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
|
|
|
|
|
val referer = "https://${getDomain()}/"
|
|
|
|
|
val content = catch401 {
|
|
|
|
|
context.httpGet(chapter.url.withDomain(subdomain = "api"), getApiHeaders())
|
|
|
|
|
}.parseJson()
|
|
|
|
|
val content = context.httpGet(chapter.url.withDomain(subdomain = "api"), getApiHeaders())
|
|
|
|
|
.handle401()
|
|
|
|
|
.parseJson()
|
|
|
|
|
.getJSONObject("content")
|
|
|
|
|
val pages = content.optJSONArray("pages")
|
|
|
|
|
if (pages == null) {
|
|
|
|
|
@ -213,12 +210,10 @@ internal class RemangaParser(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override suspend fun getUsername(): String {
|
|
|
|
|
val jo = catch401 {
|
|
|
|
|
context.httpGet(
|
|
|
|
|
val jo = context.httpGet(
|
|
|
|
|
url = "https://api.${getDomain()}/api/users/current/",
|
|
|
|
|
headers = getApiHeaders(),
|
|
|
|
|
)
|
|
|
|
|
}.parseJson()
|
|
|
|
|
).handle401().parseJson()
|
|
|
|
|
return jo.getJSONObject("content").getString("username")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -256,12 +251,10 @@ internal class RemangaParser(
|
|
|
|
|
val result = ArrayList<JSONObject>(100)
|
|
|
|
|
var page = 1
|
|
|
|
|
while (true) {
|
|
|
|
|
val content = catch401 {
|
|
|
|
|
context.httpGet(
|
|
|
|
|
val content = context.httpGet(
|
|
|
|
|
url = "https://api.$domain/api/titles/chapters/?branch_id=$branchId&page=$page&count=100",
|
|
|
|
|
headers = getApiHeaders(),
|
|
|
|
|
)
|
|
|
|
|
}.parseJson().getJSONArray("content")
|
|
|
|
|
).handle401().parseJson().getJSONArray("content")
|
|
|
|
|
val len = content.length()
|
|
|
|
|
if (len == 0) {
|
|
|
|
|
break
|
|
|
|
|
@ -275,13 +268,9 @@ internal class RemangaParser(
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private inline fun catch401(block: () -> Response): Response = try {
|
|
|
|
|
block()
|
|
|
|
|
} catch (e: HttpStatusException) {
|
|
|
|
|
if (e.statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
|
|
|
|
|
private fun Response.handle401() = apply {
|
|
|
|
|
if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
|
|
|
|
|
throw AuthRequiredException(source)
|
|
|
|
|
} else {
|
|
|
|
|
throw e
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|