parent
8ffd960733
commit
15b3fc9866
|
@ -3,7 +3,7 @@ ext {
|
|||
extClass = '.MangasNoSekai'
|
||||
themePkg = 'madara'
|
||||
baseUrl = 'https://mangasnosekai.com'
|
||||
overrideVersionCode = 11
|
||||
overrideVersionCode = 12
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
|
|
@ -8,10 +8,12 @@ import eu.kanade.tachiyomi.source.model.MangasPage
|
|||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.decodeFromString
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
import java.text.SimpleDateFormat
|
||||
|
@ -178,7 +180,7 @@ class MangasNoSekai : Madara(
|
|||
intl["order_by_filter_new"] to "new-manga",
|
||||
)
|
||||
|
||||
private fun altChapterRequest(mangaId: String, page: Int, objects: List<Pair<String, String>>): Request {
|
||||
private fun altChapterRequest(url: String, mangaId: String, page: Int, objects: List<Pair<String, String>>): Request {
|
||||
val form = FormBody.Builder()
|
||||
.add("mangaid", mangaId)
|
||||
.add("page", page.toString())
|
||||
|
@ -187,7 +189,7 @@ class MangasNoSekai : Madara(
|
|||
form.add(key, value)
|
||||
}
|
||||
|
||||
return POST("$baseUrl/wp-admin/admin-ajax.php", xhrHeaders, form.build())
|
||||
return POST(baseUrl + url, xhrHeaders, form.build())
|
||||
}
|
||||
|
||||
private val altChapterListSelector = "body > div > div"
|
||||
|
@ -196,9 +198,13 @@ class MangasNoSekai : Madara(
|
|||
val document = response.asJsoup()
|
||||
launchIO { countViews(document) }
|
||||
|
||||
val mangaSlug = response.request.url.toString().substringAfter(baseUrl).removeSuffix("/")
|
||||
val coreScript = document.selectFirst("script#wp-manga-js")!!.attr("abs:src")
|
||||
val coreScriptBody = client.newCall(GET(coreScript, headers)).execute().body.string()
|
||||
|
||||
val url = URL_REGEX.find(coreScriptBody)?.groupValues?.get(1)
|
||||
?: throw Exception("No se pudo obtener la url del capítulo")
|
||||
|
||||
val data = DATA_REGEX.find(coreScriptBody)?.groupValues?.get(1)?.trim()
|
||||
?: throw Exception("No se pudo obtener la data del capítulo")
|
||||
|
||||
|
@ -218,9 +224,13 @@ class MangasNoSekai : Madara(
|
|||
val chapterElements = mutableListOf<Element>()
|
||||
var page = 1
|
||||
do {
|
||||
val xhrRequest = altChapterRequest(mangaId, page, objects)
|
||||
val xhrRequest = altChapterRequest(url, mangaId, page, objects)
|
||||
val xhrResponse = client.newCall(xhrRequest).execute()
|
||||
val xhrDocument = xhrResponse.asJsoup()
|
||||
val xhrBody = xhrResponse.body.string()
|
||||
if (xhrBody.startsWith("{")) {
|
||||
return chaptersFromJson(xhrBody, mangaSlug)
|
||||
}
|
||||
val xhrDocument = Jsoup.parse(xhrBody)
|
||||
chapterElements.addAll(xhrDocument.select(altChapterListSelector))
|
||||
page++
|
||||
} while (xhrDocument.select(altChapterListSelector).isNotEmpty())
|
||||
|
@ -236,8 +246,14 @@ class MangasNoSekai : Madara(
|
|||
} ?: 0
|
||||
}
|
||||
|
||||
private fun chaptersFromJson(jsonString: String, mangaSlug: String): List<SChapter> {
|
||||
val result = json.decodeFromString<PayloadDto>(jsonString)
|
||||
return result.manga.first().chapters.map { it.toSChapter(mangaSlug) }
|
||||
}
|
||||
|
||||
companion object {
|
||||
val DATA_REGEX = """function\s+loadMoreChapters[\s\S]*?\$.ajax[\s\S]*?data:\s*\{([\s\S]*?)\},?""".toRegex()
|
||||
val URL_REGEX = """function\s+loadMoreChapters[\s\S]*?\$.ajax[\s\S]*?url:\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 POST_ID_REGEX = """\"postId"\s*:\s*"(.*)\"""".toRegex()
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package eu.kanade.tachiyomi.extension.es.mangasnosekai
|
||||
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import java.text.ParseException
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
@Serializable
|
||||
data class PayloadDto(
|
||||
val manga: List<MangaDto>,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class MangaDto(
|
||||
val chapters: List<ChapterDto>,
|
||||
)
|
||||
|
||||
private val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale("es"))
|
||||
|
||||
@Serializable
|
||||
data class ChapterDto(
|
||||
@SerialName("chapter_name") private val name: String,
|
||||
@SerialName("chapter_slug") private val slug: String,
|
||||
@SerialName("date_gmt") private val date: String,
|
||||
) {
|
||||
|
||||
fun toSChapter(mangaSlug: String) = SChapter.create().apply {
|
||||
name = this@ChapterDto.name
|
||||
url = "$mangaSlug/$slug"
|
||||
date_upload = try {
|
||||
dateFormat.parse(date)?.time ?: 0
|
||||
} catch (e: ParseException) {
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue