This commit is contained in:
@@ -425,38 +425,6 @@ replace_exact(
|
||||
|
||||
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)
|
||||
@@ -472,15 +440,6 @@ replace_exact(
|
||||
rawTitle
|
||||
}
|
||||
|
||||
val chapterUrl = if (
|
||||
pageCount != null &&
|
||||
pageCount > 0
|
||||
) {
|
||||
"$href#niadd-pages=$pageCount"
|
||||
} else {
|
||||
href
|
||||
}
|
||||
|
||||
MangaChapter(
|
||||
id = generateUid(href),
|
||||
title = chapterTitle.takeIf {
|
||||
@@ -488,7 +447,7 @@ replace_exact(
|
||||
},
|
||||
number = i + 1f,
|
||||
volume = 0,
|
||||
url = chapterUrl,
|
||||
url = href,
|
||||
uploadDate = parseChapterDateByLang(
|
||||
dateText.orEmpty()
|
||||
),
|
||||
@@ -641,42 +600,78 @@ replace_exact(
|
||||
''' override suspend fun getPages(
|
||||
chapter: MangaChapter,
|
||||
): List<MangaPage> {
|
||||
val chapterUrl = chapter.url
|
||||
.substringBefore("#")
|
||||
|
||||
val doc = webClient
|
||||
.httpGet(
|
||||
chapterUrl.toAbsoluteUrl(domain)
|
||||
)
|
||||
.parseHtml()
|
||||
|
||||
if (domain.endsWith("niadd.com")) {
|
||||
val originalUrl = chapter.url
|
||||
.substringBefore("#")
|
||||
.substringBefore("?")
|
||||
val pageLabelRegex = Regex(
|
||||
"""^\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$"""
|
||||
)
|
||||
|
||||
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 pageOptions = doc
|
||||
.select("option[value]")
|
||||
.mapNotNull { option ->
|
||||
val match = pageLabelRegex.matchEntire(
|
||||
option.text().trim()
|
||||
) ?: return@mapNotNull null
|
||||
|
||||
val normalizedUrl = originalUrl
|
||||
.removeSuffix("/")
|
||||
val pageNumber = match
|
||||
.groupValues
|
||||
.getOrNull(1)
|
||||
?.toIntOrNull()
|
||||
?: return@mapNotNull null
|
||||
|
||||
val baseUrl = if (
|
||||
normalizedUrl.endsWith(".html")
|
||||
) {
|
||||
normalizedUrl.removeSuffix(".html")
|
||||
} else {
|
||||
normalizedUrl
|
||||
}
|
||||
val totalPages = match
|
||||
.groupValues
|
||||
.getOrNull(2)
|
||||
?.toIntOrNull()
|
||||
?: return@mapNotNull null
|
||||
|
||||
return (1..totalPages).map { pageNumber ->
|
||||
val url = if (pageNumber == 1) {
|
||||
originalUrl
|
||||
} else {
|
||||
"$baseUrl-$pageNumber.html"
|
||||
val url = option.attr("value").trim()
|
||||
if (url.isEmpty()) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
|
||||
Triple(pageNumber, totalPages, url)
|
||||
}
|
||||
.distinctBy { (pageNumber, _, _) ->
|
||||
pageNumber
|
||||
}
|
||||
.sortedBy { (pageNumber, _, _) ->
|
||||
pageNumber
|
||||
}
|
||||
|
||||
val totalPages = pageOptions
|
||||
.firstOrNull()
|
||||
?.second
|
||||
?: error(
|
||||
"Cannot find Niadd page selector for $chapterUrl"
|
||||
)
|
||||
|
||||
check(
|
||||
pageOptions.all { (_, total, _) ->
|
||||
total == totalPages
|
||||
}
|
||||
) {
|
||||
"Inconsistent Niadd page count for $chapterUrl"
|
||||
}
|
||||
|
||||
check(
|
||||
pageOptions.size == totalPages &&
|
||||
pageOptions.map { it.first } ==
|
||||
(1..totalPages).toList()
|
||||
) {
|
||||
"Incomplete Niadd page selector for $chapterUrl: " +
|
||||
"found ${pageOptions.size} of $totalPages pages"
|
||||
}
|
||||
|
||||
return pageOptions.map { (_, _, url) ->
|
||||
MangaPage(
|
||||
id = generateUid(url),
|
||||
url = url,
|
||||
@@ -686,12 +681,6 @@ replace_exact(
|
||||
}
|
||||
}
|
||||
|
||||
val doc = webClient
|
||||
.httpGet(
|
||||
chapter.url.toAbsoluteUrl(domain)
|
||||
)
|
||||
.parseHtml()
|
||||
|
||||
return doc
|
||||
.body()
|
||||
.requireElementById("page")
|
||||
|
||||
Reference in New Issue
Block a user