fix pagecount
Build Futon with Niadd patch / Build Futon Niadd debug APK (push) Successful in 13m49s
Build Futon with Niadd patch / Build Futon Niadd debug APK (push) Successful in 13m49s
This commit is contained in:
1 file changed
+68
-36
@@ -406,22 +406,57 @@ replace_exact(
|
|||||||
val href = a.attrAsRelativeUrl("href")
|
val href = a.attrAsRelativeUrl("href")
|
||||||
.replace("%20", " ")
|
.replace("%20", " ")
|
||||||
|
|
||||||
|
val anchorText = a.text().trim()
|
||||||
|
val rowText = a.parent()?.text().orEmpty().trim()
|
||||||
|
|
||||||
val rawTitle = a.ownText()
|
val rawTitle = a.ownText()
|
||||||
.trim()
|
.trim()
|
||||||
.ifEmpty {
|
.ifEmpty {
|
||||||
a.text().trim()
|
anchorText
|
||||||
}
|
}
|
||||||
|
|
||||||
val anchorDate = chapterDateRegex
|
val anchorDate = chapterDateRegex
|
||||||
.find(a.text())
|
.find(anchorText)
|
||||||
?.value
|
?.value
|
||||||
|
|
||||||
val rowDate = chapterDateRegex
|
val rowDate = chapterDateRegex
|
||||||
.find(a.parent()?.text().orEmpty())
|
.find(rowText)
|
||||||
?.value
|
?.value
|
||||||
|
|
||||||
val dateText = anchorDate ?: rowDate
|
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 (
|
val chapterTitle = if (
|
||||||
dateText != null &&
|
dateText != null &&
|
||||||
rawTitle.contains(dateText)
|
rawTitle.contains(dateText)
|
||||||
@@ -437,6 +472,15 @@ replace_exact(
|
|||||||
rawTitle
|
rawTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val chapterUrl = if (
|
||||||
|
pageCount != null &&
|
||||||
|
pageCount > 0
|
||||||
|
) {
|
||||||
|
"$href#niadd-pages=$pageCount"
|
||||||
|
} else {
|
||||||
|
href
|
||||||
|
}
|
||||||
|
|
||||||
MangaChapter(
|
MangaChapter(
|
||||||
id = generateUid(href),
|
id = generateUid(href),
|
||||||
title = chapterTitle.takeIf {
|
title = chapterTitle.takeIf {
|
||||||
@@ -444,7 +488,7 @@ replace_exact(
|
|||||||
},
|
},
|
||||||
number = i + 1f,
|
number = i + 1f,
|
||||||
volume = 0,
|
volume = 0,
|
||||||
url = href,
|
url = chapterUrl,
|
||||||
uploadDate = parseChapterDateByLang(
|
uploadDate = parseChapterDateByLang(
|
||||||
dateText.orEmpty()
|
dateText.orEmpty()
|
||||||
),
|
),
|
||||||
@@ -597,42 +641,24 @@ replace_exact(
|
|||||||
''' override suspend fun getPages(
|
''' override suspend fun getPages(
|
||||||
chapter: MangaChapter,
|
chapter: MangaChapter,
|
||||||
): List<MangaPage> {
|
): List<MangaPage> {
|
||||||
val doc = webClient
|
|
||||||
.httpGet(
|
|
||||||
chapter.url.toAbsoluteUrl(domain)
|
|
||||||
)
|
|
||||||
.parseHtml()
|
|
||||||
|
|
||||||
if (domain.endsWith("niadd.com")) {
|
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
|
val originalUrl = chapter.url
|
||||||
|
.substringBefore("#")
|
||||||
.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
|
val normalizedUrl = originalUrl
|
||||||
.removeSuffix("/")
|
.removeSuffix("/")
|
||||||
|
|
||||||
@@ -660,6 +686,12 @@ replace_exact(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val doc = webClient
|
||||||
|
.httpGet(
|
||||||
|
chapter.url.toAbsoluteUrl(domain)
|
||||||
|
)
|
||||||
|
.parseHtml()
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
.body()
|
.body()
|
||||||
.requireElementById("page")
|
.requireElementById("page")
|
||||||
|
|||||||
Reference in new issue
Block a user