[MintManga] Fix pages list
This commit is contained in:
@@ -38,7 +38,7 @@ kotlin {
|
||||
dependencies {
|
||||
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.1'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
|
||||
implementation 'com.squareup.okio:okio:3.0.0'
|
||||
implementation 'com.squareup.okio:okio:3.1.0'
|
||||
implementation 'org.jsoup:jsoup:1.14.3'
|
||||
implementation 'org.json:json:20220320'
|
||||
implementation 'androidx.collection:collection-ktx:1.2.0'
|
||||
|
||||
@@ -3,5 +3,5 @@ plugins {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.google.devtools.ksp:symbol-processing-api:1.6.20-1.0.5'
|
||||
implementation 'com.google.devtools.ksp:symbol-processing-api:1.6.21-1.0.5'
|
||||
}
|
||||
@@ -41,6 +41,7 @@ abstract class MangaLoaderContext {
|
||||
suspend fun httpPost(
|
||||
url: String,
|
||||
form: Map<String, String>,
|
||||
headers: Headers? = null,
|
||||
): Response {
|
||||
val body = FormBody.Builder()
|
||||
form.forEach { (k, v) ->
|
||||
@@ -49,12 +50,16 @@ abstract class MangaLoaderContext {
|
||||
val request = Request.Builder()
|
||||
.post(body.build())
|
||||
.url(url)
|
||||
if (headers != null) {
|
||||
request.headers(headers)
|
||||
}
|
||||
return httpClient.newCall(request.build()).await().ensureSuccess()
|
||||
}
|
||||
|
||||
suspend fun httpPost(
|
||||
url: String,
|
||||
payload: String,
|
||||
headers: Headers?,
|
||||
): Response {
|
||||
val body = FormBody.Builder()
|
||||
payload.split('&').forEach {
|
||||
@@ -68,6 +73,9 @@ abstract class MangaLoaderContext {
|
||||
val request = Request.Builder()
|
||||
.post(body.build())
|
||||
.url(url)
|
||||
if (headers != null) {
|
||||
request.headers(headers)
|
||||
}
|
||||
return httpClient.newCall(request.build()).await().ensureSuccess()
|
||||
}
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ private const val PAGE_SIZE = 70
|
||||
private const val PAGE_SIZE_SEARCH = 50
|
||||
private const val NSFW_ALERT = "сексуальные сцены"
|
||||
|
||||
internal abstract class GroupleParser(source: MangaSource) : MangaParser(source) {
|
||||
internal abstract class GroupleParser(source: MangaSource, userAgent: String) : MangaParser(source) {
|
||||
|
||||
private val headers = Headers.Builder()
|
||||
.add("User-Agent", "readmangafun")
|
||||
.add("User-Agent", userAgent)
|
||||
.build()
|
||||
|
||||
override val sortOrders: Set<SortOrder> = EnumSet.of(
|
||||
@@ -43,6 +43,7 @@ internal abstract class GroupleParser(source: MangaSource) : MangaParser(source)
|
||||
"q" to query.urlEncoded(),
|
||||
"offset" to (offset upBy PAGE_SIZE_SEARCH).toString(),
|
||||
),
|
||||
headers,
|
||||
)
|
||||
tags.isNullOrEmpty() -> context.httpGet(
|
||||
"https://$domain/list?sortType=${
|
||||
@@ -166,12 +167,17 @@ internal abstract class GroupleParser(source: MangaSource) : MangaParser(source)
|
||||
val scripts = doc.select("script")
|
||||
for (script in scripts) {
|
||||
val data = script.html()
|
||||
val pos = data.indexOf("rm_h.init")
|
||||
val pos = data.indexOf("rm_h.initReader(")
|
||||
if (pos == -1) {
|
||||
continue
|
||||
}
|
||||
val json = data.substring(pos).substringAfter('(').substringBefore('\n')
|
||||
val json = data.substring(pos)
|
||||
.substringAfter('(')
|
||||
.substringBefore('\n')
|
||||
.substringBeforeLast(')')
|
||||
if (json.isEmpty()) {
|
||||
continue
|
||||
}
|
||||
val ja = JSONArray("[$json]")
|
||||
val pages = ja.getJSONArray(1)
|
||||
val servers = ja.getJSONArray(4).mapJSON { it.getString("path") }
|
||||
@@ -199,11 +205,12 @@ internal abstract class GroupleParser(source: MangaSource) : MangaParser(source)
|
||||
val headers = Headers.headersOf("Referer", page.referer)
|
||||
for (server in servers) {
|
||||
val url = server + path
|
||||
if (context.httpHead(url, headers).isSuccessful) {
|
||||
if (tryHead(url, headers)) {
|
||||
return url
|
||||
}
|
||||
}
|
||||
throw IllegalArgumentException("Cannot find any page url")
|
||||
val fallbackServer = servers.firstOrNull() ?: parseFailed("Cannot find any page url")
|
||||
return fallbackServer + path
|
||||
}
|
||||
|
||||
override suspend fun getTags(): Set<MangaTag> {
|
||||
@@ -263,6 +270,10 @@ internal abstract class GroupleParser(source: MangaSource) : MangaParser(source)
|
||||
payload["s_sale"] = ""
|
||||
payload["years"] = "1900,2099"
|
||||
payload["+"] = "Искать".urlEncoded()
|
||||
return context.httpPost(url, payload)
|
||||
return context.httpPost(url, payload, headers)
|
||||
}
|
||||
|
||||
private suspend fun tryHead(url: String, headers: Headers): Boolean = runCatching {
|
||||
context.httpHead(url, headers).isSuccessful
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
@@ -6,7 +6,9 @@ import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
@MangaSourceParser("MINTMANGA", "MintManga", "ru")
|
||||
internal class MintMangaParser(override val context: MangaLoaderContext) : GroupleParser(MangaSource.MINTMANGA) {
|
||||
internal class MintMangaParser(
|
||||
override val context: MangaLoaderContext,
|
||||
) : GroupleParser(MangaSource.MINTMANGA, "mintmangafun") {
|
||||
|
||||
override val configKeyDomain = ConfigKey.Domain(
|
||||
"mintmanga.live",
|
||||
|
||||
@@ -6,7 +6,9 @@ import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
@MangaSourceParser("READMANGA_RU", "ReadManga", "ru")
|
||||
internal class ReadmangaParser(override val context: MangaLoaderContext) : GroupleParser(MangaSource.READMANGA_RU) {
|
||||
internal class ReadmangaParser(
|
||||
override val context: MangaLoaderContext,
|
||||
) : GroupleParser(MangaSource.READMANGA_RU, "readmangafun") {
|
||||
|
||||
override val configKeyDomain = ConfigKey.Domain(
|
||||
"readmanga.io",
|
||||
|
||||
@@ -6,7 +6,9 @@ import org.koitharu.kotatsu.parsers.config.ConfigKey
|
||||
import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
@MangaSourceParser("SELFMANGA", "SelfManga", "ru")
|
||||
internal class SelfMangaParser(override val context: MangaLoaderContext) : GroupleParser(MangaSource.SELFMANGA) {
|
||||
internal class SelfMangaParser(
|
||||
override val context: MangaLoaderContext,
|
||||
) : GroupleParser(MangaSource.SELFMANGA, "selfmangafun") {
|
||||
|
||||
override val configKeyDomain = ConfigKey.Domain("selfmanga.live", null)
|
||||
}
|
||||
Reference in New Issue
Block a user