Fix Kumanga (#15867)
* Fix Kumanga * Fix Kumanga * Refresh token in searchRequest
This commit is contained in:
parent
7a10d877d2
commit
19126a34f6
|
@ -6,7 +6,7 @@ ext {
|
||||||
extName = 'Kumanga'
|
extName = 'Kumanga'
|
||||||
pkgNameSuffix = 'es.kumanga'
|
pkgNameSuffix = 'es.kumanga'
|
||||||
extClass = '.Kumanga'
|
extClass = '.Kumanga'
|
||||||
extVersionCode = 7
|
extVersionCode = 8
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
|
|
@ -17,6 +17,7 @@ import kotlinx.serialization.json.int
|
||||||
import kotlinx.serialization.json.jsonArray
|
import kotlinx.serialization.json.jsonArray
|
||||||
import kotlinx.serialization.json.jsonObject
|
import kotlinx.serialization.json.jsonObject
|
||||||
import kotlinx.serialization.json.jsonPrimitive
|
import kotlinx.serialization.json.jsonPrimitive
|
||||||
|
import okhttp3.FormBody
|
||||||
import okhttp3.Headers
|
import okhttp3.Headers
|
||||||
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
|
@ -24,6 +25,7 @@ import okhttp3.Request
|
||||||
import okhttp3.Response
|
import okhttp3.Response
|
||||||
import org.jsoup.nodes.Element
|
import org.jsoup.nodes.Element
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
import java.net.URL
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
@ -57,11 +59,7 @@ class Kumanga : HttpSource() {
|
||||||
private val json: Json by injectLazy()
|
private val json: Json by injectLazy()
|
||||||
|
|
||||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||||
.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0")
|
|
||||||
|
|
||||||
private val chapterImagesHeaders = headersBuilder()
|
|
||||||
.add("Referer", baseUrl)
|
.add("Referer", baseUrl)
|
||||||
.build()
|
|
||||||
|
|
||||||
private var kumangaToken = ""
|
private var kumangaToken = ""
|
||||||
|
|
||||||
|
@ -83,7 +81,7 @@ class Kumanga : HttpSource() {
|
||||||
return kumangaToken
|
return kumangaToken
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMangaCover(mangaId: String) = "https://static.kumanga.com/manga_covers/$mangaId.jpg?w=201"
|
private fun getMangaCover(mangaId: String) = "$baseUrl/kumathumb.php?src=$mangaId"
|
||||||
|
|
||||||
private fun getMangaUrl(mangaId: String, mangaSlug: String, page: Int) = "/manga/$mangaId/p/$page/$mangaSlug#cl"
|
private fun getMangaUrl(mangaId: String, mangaSlug: String, page: Int) = "/manga/$mangaId/p/$page/$mangaSlug#cl"
|
||||||
|
|
||||||
|
@ -97,6 +95,7 @@ class Kumanga : HttpSource() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun popularMangaRequest(page: Int): Request {
|
override fun popularMangaRequest(page: Int): Request {
|
||||||
|
getKumangaToken() // Get new token every request (prevent http 400)
|
||||||
return POST("$baseUrl/backend/ajax/searchengine.php?page=$page&perPage=10&keywords=&retrieveCategories=true&retrieveAuthors=false&contentType=manga&token=$kumangaToken", headers)
|
return POST("$baseUrl/backend/ajax/searchengine.php?page=$page&perPage=10&keywords=&retrieveCategories=true&retrieveAuthors=false&contentType=manga&token=$kumangaToken", headers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +116,7 @@ class Kumanga : HttpSource() {
|
||||||
|
|
||||||
override fun mangaDetailsParse(response: Response) = SManga.create().apply {
|
override fun mangaDetailsParse(response: Response) = SManga.create().apply {
|
||||||
val body = response.asJsoup()
|
val body = response.asJsoup()
|
||||||
|
thumbnail_url = body.selectFirst("div.km-img-gral-2 img")?.attr("abs:src")
|
||||||
body.select("div#tab2").let {
|
body.select("div#tab2").let {
|
||||||
status = parseStatus(it.select("span").text().orEmpty())
|
status = parseStatus(it.select("span").text().orEmpty())
|
||||||
author = it.select("p:nth-child(3) > a").text()
|
author = it.select("p:nth-child(3) > a").text()
|
||||||
|
@ -171,6 +170,16 @@ class Kumanga : HttpSource() {
|
||||||
|
|
||||||
override fun pageListParse(response: Response): List<Page> {
|
override fun pageListParse(response: Response): List<Page> {
|
||||||
val document = response.asJsoup()
|
val document = response.asJsoup()
|
||||||
|
val form = document.selectFirst("form#myForm[action]")
|
||||||
|
if (form != null) {
|
||||||
|
val url = form.attr("action")
|
||||||
|
val bodyBuilder = FormBody.Builder()
|
||||||
|
val inputs = form.select("input")
|
||||||
|
inputs.map { input ->
|
||||||
|
bodyBuilder.add(input.attr("name"), input.attr("value"))
|
||||||
|
}
|
||||||
|
return pageListParse(client.newCall(POST(url, headers, bodyBuilder.build())).execute())
|
||||||
|
} else {
|
||||||
val imagesJsonRaw = document.select("script:containsData(var pUrl=)").firstOrNull()
|
val imagesJsonRaw = document.select("script:containsData(var pUrl=)").firstOrNull()
|
||||||
?.data()
|
?.data()
|
||||||
?.substringAfter("var pUrl=")
|
?.substringAfter("var pUrl=")
|
||||||
|
@ -183,16 +192,24 @@ class Kumanga : HttpSource() {
|
||||||
return jsonResult.mapIndexed { i, jsonEl ->
|
return jsonResult.mapIndexed { i, jsonEl ->
|
||||||
val jsonObj = jsonEl.jsonObject
|
val jsonObj = jsonEl.jsonObject
|
||||||
val imagePath = jsonObj["imgURL"]!!.jsonPrimitive.content.replace("\\", "")
|
val imagePath = jsonObj["imgURL"]!!.jsonPrimitive.content.replace("\\", "")
|
||||||
|
val docUrl = document.location()
|
||||||
Page(i, "", baseUrl + imagePath)
|
val baseUrl = URL(docUrl).protocol + "://" + URL(docUrl).host // For some reason baseUri returns the full url
|
||||||
|
Page(i, baseUrl, "$baseUrl/$imagePath")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun imageRequest(page: Page) = GET(page.imageUrl!!, chapterImagesHeaders)
|
override fun imageRequest(page: Page): Request {
|
||||||
|
val imageHeaders = Headers.Builder()
|
||||||
|
.add("Referer", page.url)
|
||||||
|
.build()
|
||||||
|
return GET(page.imageUrl!!, imageHeaders)
|
||||||
|
}
|
||||||
|
|
||||||
override fun imageUrlParse(response: Response) = throw Exception("Not Used")
|
override fun imageUrlParse(response: Response) = throw Exception("Not Used")
|
||||||
|
|
||||||
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
|
||||||
|
getKumangaToken()
|
||||||
val url = "$baseUrl/backend/ajax/searchengine.php?page=$page&perPage=10&keywords=$query&retrieveCategories=true&retrieveAuthors=false&contentType=manga&token=$kumangaToken".toHttpUrlOrNull()!!.newBuilder()
|
val url = "$baseUrl/backend/ajax/searchengine.php?page=$page&perPage=10&keywords=$query&retrieveCategories=true&retrieveAuthors=false&contentType=manga&token=$kumangaToken".toHttpUrlOrNull()!!.newBuilder()
|
||||||
|
|
||||||
filters.forEach { filter ->
|
filters.forEach { filter ->
|
||||||
|
|
Loading…
Reference in New Issue