MNS: FIx no chapters found (#2360)

wtf
This commit is contained in:
bapeey 2024-04-11 21:45:52 -05:00 committed by Draff
parent 46aa7fd5cf
commit 9d43ba0711
2 changed files with 19 additions and 9 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.MangasNoSekai' extClass = '.MangasNoSekai'
themePkg = 'madara' themePkg = 'madara'
baseUrl = 'https://mangasnosekai.com' baseUrl = 'https://mangasnosekai.com'
overrideVersionCode = 10 overrideVersionCode = 11
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View File

@ -178,14 +178,16 @@ class MangasNoSekai : Madara(
intl["order_by_filter_new"] to "new-manga", intl["order_by_filter_new"] to "new-manga",
) )
private fun altChapterRequest(mangaId: String, page: Int, action: String): Request { private fun altChapterRequest(mangaId: String, page: Int, objects: List<Pair<String, String>>): Request {
val form = FormBody.Builder() val form = FormBody.Builder()
.add("action", action)
.add("mangaid", mangaId) .add("mangaid", mangaId)
.add("page", page.toString()) .add("page", page.toString())
.build()
return POST("$baseUrl/wp-admin/admin-ajax.php", xhrHeaders, form) objects.forEach { (key, value) ->
form.add(key, value)
}
return POST("$baseUrl/wp-admin/admin-ajax.php", xhrHeaders, form.build())
} }
private val altChapterListSelector = "body > div > div" private val altChapterListSelector = "body > div > div"
@ -197,8 +199,15 @@ class MangasNoSekai : Madara(
val coreScript = document.selectFirst("script#wp-manga-js")!!.attr("abs:src") val coreScript = document.selectFirst("script#wp-manga-js")!!.attr("abs:src")
val coreScriptBody = client.newCall(GET(coreScript, headers)).execute().body.string() val coreScriptBody = client.newCall(GET(coreScript, headers)).execute().body.string()
val action = ACTION_REGEX.find(coreScriptBody)?.groupValues?.get(1) val data = DATA_REGEX.find(coreScriptBody)?.groupValues?.get(1)?.trim()
?: throw Exception("No se pudo obtener la acción de carga de capítulos") ?: throw Exception("No se pudo obtener la data del capítulo")
val objects = DATA_OBJECTS_REGEX.findAll(data)
.mapNotNull { matchResult ->
val key = matchResult.groupValues[1]
val value = matchResult.groupValues.getOrNull(2)
if (!value.isNullOrEmpty()) key to value else null
}.toList()
val mangaId = document.selectFirst("script#wp-manga-js-extra")?.data() val mangaId = document.selectFirst("script#wp-manga-js-extra")?.data()
?.let { MANGA_ID_REGEX.find(it)?.groupValues?.get(1) } ?.let { MANGA_ID_REGEX.find(it)?.groupValues?.get(1) }
@ -209,7 +218,7 @@ class MangasNoSekai : Madara(
val chapterElements = mutableListOf<Element>() val chapterElements = mutableListOf<Element>()
var page = 1 var page = 1
do { do {
val xhrRequest = altChapterRequest(mangaId, page, action) val xhrRequest = altChapterRequest(mangaId, page, objects)
val xhrResponse = client.newCall(xhrRequest).execute() val xhrResponse = client.newCall(xhrRequest).execute()
val xhrDocument = xhrResponse.asJsoup() val xhrDocument = xhrResponse.asJsoup()
chapterElements.addAll(xhrDocument.select(altChapterListSelector)) chapterElements.addAll(xhrDocument.select(altChapterListSelector))
@ -228,7 +237,8 @@ class MangasNoSekai : Madara(
} }
companion object { companion object {
val ACTION_REGEX = """function\s+loadMoreChapters[\s\S]*?\$.ajax[\s\S]*?data[\s\S]*?action:\s*(?:["'](.*?)["'])""".toRegex() val DATA_REGEX = """function\s+loadMoreChapters[\s\S]*?\$.ajax[\s\S]*?data:\s*\{([\s\S]*?)\},?""".toRegex()
val DATA_OBJECTS_REGEX = """\s*(\w+)\s*:\s*(?:(?:'([^']*)'|([^,\r\n]+))\s*,?\s*)""".toRegex()
val MANGA_ID_REGEX = """\"manga_id"\s*:\s*"(.*)\"""".toRegex() val MANGA_ID_REGEX = """\"manga_id"\s*:\s*"(.*)\"""".toRegex()
val POST_ID_REGEX = """\"postId"\s*:\s*"(.*)\"""".toRegex() val POST_ID_REGEX = """\"postId"\s*:\s*"(.*)\"""".toRegex()
} }