fix pagecount
Build Futon with Niadd patch / Build Futon Niadd debug APK (push) Successful in 13m49s

This commit is contained in:
2026-08-10 00:18:47 +03:00
parent 24d71d9407
commit ffeaa412e8
+68 -36
View File
@@ -406,22 +406,57 @@ replace_exact(
val href = a.attrAsRelativeUrl("href")
.replace("%20", " ")
val anchorText = a.text().trim()
val rowText = a.parent()?.text().orEmpty().trim()
val rawTitle = a.ownText()
.trim()
.ifEmpty {
a.text().trim()
anchorText
}
val anchorDate = chapterDateRegex
.find(a.text())
.find(anchorText)
?.value
val rowDate = chapterDateRegex
.find(a.parent()?.text().orEmpty())
.find(rowText)
?.value
val dateText = anchorDate ?: rowDate
val metadataText = when {
anchorDate != null -> anchorText
rowDate != null -> rowText
else -> ""
}
val textBeforeDate = if (dateText != null) {
metadataText
.substringBefore(dateText)
.trim()
} else {
metadataText
}
/*
* Niadd exposes the page count immediately before
* the chapter date, for example:
*
* Падение русала 1 - 42 41 Aug 02, 2024
* ^^
*
* Store that number in a URL fragment. Fragments
* are local metadata and are not sent to the server.
*/
val pageCount = Regex(
"""\\s+(\\d+)\\s*$"""
)
.find(textBeforeDate)
?.groupValues
?.getOrNull(1)
?.toIntOrNull()
val chapterTitle = if (
dateText != null &&
rawTitle.contains(dateText)
@@ -437,6 +472,15 @@ replace_exact(
rawTitle
}
val chapterUrl = if (
pageCount != null &&
pageCount > 0
) {
"$href#niadd-pages=$pageCount"
} else {
href
}
MangaChapter(
id = generateUid(href),
title = chapterTitle.takeIf {
@@ -444,7 +488,7 @@ replace_exact(
},
number = i + 1f,
volume = 0,
url = href,
url = chapterUrl,
uploadDate = parseChapterDateByLang(
dateText.orEmpty()
),
@@ -597,42 +641,24 @@ replace_exact(
''' override suspend fun getPages(
chapter: MangaChapter,
): List<MangaPage> {
val doc = webClient
.httpGet(
chapter.url.toAbsoluteUrl(domain)
)
.parseHtml()
if (domain.endsWith("niadd.com")) {
val pageLabelRegex = Regex(
"""^\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$"""
)
val totalPages = doc
.select("option")
.mapNotNull { option ->
pageLabelRegex
.matchEntire(
option.text().trim()
)
?.groupValues
?.getOrNull(2)
?.toIntOrNull()
}
.maxOrNull()
?: error(
"Cannot find Niadd page count for ${chapter.url}"
)
if (totalPages <= 0) {
error(
"Invalid Niadd page count $totalPages for ${chapter.url}"
)
}
val originalUrl = chapter.url
.substringBefore("#")
.substringBefore("?")
val totalPages = chapter.url
.substringAfter(
"#niadd-pages=",
"",
)
.substringBefore("&")
.toIntOrNull()
?.takeIf { it > 0 }
?: error(
"Niadd page count is missing for ${chapter.url}. " +
"Refresh manga details and try again."
)
val normalizedUrl = originalUrl
.removeSuffix("/")
@@ -660,6 +686,12 @@ replace_exact(
}
}
val doc = webClient
.httpGet(
chapter.url.toAbsoluteUrl(domain)
)
.parseHtml()
return doc
.body()
.requireElementById("page")