Japanread: fix image fetch requests (#12516)

This commit is contained in:
Vetle Ledaal 2022-07-10 22:09:24 +00:00 committed by GitHub
parent 0cfe8a9b49
commit 7f9d69f458
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -6,7 +6,7 @@ ext {
extName = 'Japanread'
pkgNameSuffix = 'fr.japanread'
extClass = '.Japanread'
extVersionCode = 9
extVersionCode = 10
isNsfw = true
}

View File

@ -14,6 +14,7 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Headers
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
@ -37,6 +38,9 @@ class Japanread : ParsedHttpSource() {
override val client: OkHttpClient = network.cloudflareClient
override fun headersBuilder(): Headers.Builder = Headers.Builder()
.add("Referer", "$baseUrl/")
// Generic (used by popular/latest/search)
private fun mangaListFromElement(element: Element): SManga {
return SManga.create().apply {
@ -111,8 +115,8 @@ class Japanread : ParsedHttpSource() {
}
}
private fun apiHeaders(refererURL: String) = headersBuilder().apply {
add("referer", refererURL)
private fun apiHeaders(refererURL: String) = headers.newBuilder().apply {
set("Referer", refererURL)
add("x-requested-with", "XMLHttpRequest")
// without this we get 404 but I don't know why, I cannot find any information about this 'a' header.
// In chrome the value is constantly changing on each request, but giving this fixed value seems to work
@ -235,7 +239,7 @@ class Japanread : ParsedHttpSource() {
override fun pageListParse(document: Document): List<Page> {
val chapterId = document.select("meta[data-chapter-id]").attr("data-chapter-id")
val apiRequest = GET("$baseUrl/api/?id=$chapterId&type=chapter", apiHeaders("${document.location()}"))
val apiRequest = GET("$baseUrl/api/?id=$chapterId&type=chapter", apiHeaders(document.location()))
val apiResponse = client.newCall(apiRequest).execute()
val jsonResult = json.parseToJsonElement(apiResponse.body!!.string()).jsonObject
@ -243,14 +247,18 @@ class Japanread : ParsedHttpSource() {
val baseImagesUrl = jsonResult["baseImagesUrl"]!!.jsonPrimitive.content
return jsonResult["page_array"]!!.jsonArray.mapIndexed { i, jsonEl ->
Page(i, baseUrl, "$baseUrl$baseImagesUrl/${jsonEl.jsonPrimitive.content}")
Page(i, document.location(), "$baseUrl$baseImagesUrl/${jsonEl.jsonPrimitive.content}")
}
}
override fun imageUrlParse(document: Document) = ""
override fun imageRequest(page: Page): Request {
return GET(page.imageUrl!!, headers)
val newHeaders = headers.newBuilder()
.set("Referer", page.url)
.build()
return GET(page.imageUrl!!, newHeaders)
}
// Filters