PTNF: fix mangaId, fix pagination, script order (#2964)

* PTNF: fix mangaId, fix pagination, script order

* actually use the most common mangaId
This commit is contained in:
Vetle Ledaal 2024-05-12 04:25:54 +00:00 committed by GitHub
parent b40e2ae5ec
commit 0315b3cc7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 12 deletions

View File

@ -1,7 +1,7 @@
ext {
extName = 'Plot Twist No Fansub'
extClass = '.PlotTwistNoFansub'
extVersionCode = 4
extVersionCode = 5
isNsfw = true
}

View File

@ -138,19 +138,26 @@ class PlotTwistNoFansub : ParsedHttpSource(), ConfigurableSource {
override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup()
val mangaId = document.selectFirst(".chapters-container .row.itemlist p[data-mangaid]")!!.attr("data-mangaid")
val mangaIds = listOfNotNull(
MANGAID1_REGEX.find(document.html())?.groupValues?.get(1),
document.selectFirst("link[rel=shortlink]")?.attr("href")?.substringAfterLast("="),
document.selectFirst("body")?.classNames()?.filter { it.startsWith("postid-") }?.getOrNull(0)?.substringAfterLast("-"),
document.selectFirst(".td-post-views span")?.classNames()?.filter { it.startsWith("td-nr-views-") }?.getOrNull(0)?.substringAfterLast("-"),
) + document.select("*[data-mangaid]").map { it.attr("data-mangaid") }
val mangaId = mangaIds.groupingBy { it }.eachCount().maxBy { it.value }.key
val key = getKey(document)
val url = "$baseUrl/wp-admin/admin-ajax.php"
val formBody = FormBody.Builder()
.add("action", key)
.add("manga_id", mangaId)
var page = 1
val chapterList = mutableListOf<SChapter>()
do {
val body = formBody
val body = FormBody.Builder()
.add("action", key)
.add("manga_id", mangaId)
.add("pageNumber", page.toString())
.build()
@ -217,21 +224,17 @@ class PlotTwistNoFansub : ParsedHttpSource(), ConfigurableSource {
private fun getKey(document: Document): String {
val customPriorityWant = listOf("custom")
val customPriorityJunk = listOf("bootstrap", "pagi", "reader", "jquery")
val customPriorityJunk2 = listOf("multilanguage-", "ad-", "td-", "bj-", "html-", "gd-")
document.select("script[src*=\"wp-content/plugins/\"]")
.asSequence()
.map { it.attr("src") }
.filterNot { it.contains("wp-content/plugins/multilanguage-") }
.filterNot { it.contains("wp-content/plugins/ad-") }
.filterNot { it.contains("wp-content/plugins/td-") }
.filterNot { it.contains("wp-content/plugins/bj-") }
.filterNot { it.contains("wp-content/plugins/html-") }
.filterNot { it.contains("wp-content/plugins/gd-") }
.sortedWith(
compareBy<String> { url ->
when {
customPriorityWant.any { url.contains(it) } -> 0
customPriorityJunk.any { url.contains(it) } -> 2
customPriorityJunk2.any { url.contains(it) } -> 3
else -> 1
}
},
@ -254,6 +257,7 @@ class PlotTwistNoFansub : ParsedHttpSource(), ConfigurableSource {
}
companion object {
private val MANGAID1_REGEX = ""","manid":"(\d+)",""".toRegex()
private val UNESCAPE_REGEX = """\\(.)""".toRegex()
private val CHAPTER_PAGES_REGEX = """obj\s*=\s*(.*)\s*;""".toRegex()
private val ACTION_REGEX = """action:\s*?(['"])([^\r\n]+?)\1""".toRegex()