This commit is contained in:
@@ -425,38 +425,6 @@ replace_exact(
|
|||||||
|
|
||||||
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)
|
||||||
@@ -472,15 +440,6 @@ 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 {
|
||||||
@@ -488,7 +447,7 @@ replace_exact(
|
|||||||
},
|
},
|
||||||
number = i + 1f,
|
number = i + 1f,
|
||||||
volume = 0,
|
volume = 0,
|
||||||
url = chapterUrl,
|
url = href,
|
||||||
uploadDate = parseChapterDateByLang(
|
uploadDate = parseChapterDateByLang(
|
||||||
dateText.orEmpty()
|
dateText.orEmpty()
|
||||||
),
|
),
|
||||||
@@ -641,42 +600,78 @@ replace_exact(
|
|||||||
''' override suspend fun getPages(
|
''' override suspend fun getPages(
|
||||||
chapter: MangaChapter,
|
chapter: MangaChapter,
|
||||||
): List<MangaPage> {
|
): List<MangaPage> {
|
||||||
|
val chapterUrl = chapter.url
|
||||||
|
.substringBefore("#")
|
||||||
|
|
||||||
|
val doc = webClient
|
||||||
|
.httpGet(
|
||||||
|
chapterUrl.toAbsoluteUrl(domain)
|
||||||
|
)
|
||||||
|
.parseHtml()
|
||||||
|
|
||||||
if (domain.endsWith("niadd.com")) {
|
if (domain.endsWith("niadd.com")) {
|
||||||
val originalUrl = chapter.url
|
val pageLabelRegex = Regex(
|
||||||
.substringBefore("#")
|
"""^\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$"""
|
||||||
.substringBefore("?")
|
)
|
||||||
|
|
||||||
val totalPages = chapter.url
|
val pageOptions = doc
|
||||||
.substringAfter(
|
.select("option[value]")
|
||||||
"#niadd-pages=",
|
.mapNotNull { option ->
|
||||||
"",
|
val match = pageLabelRegex.matchEntire(
|
||||||
)
|
option.text().trim()
|
||||||
.substringBefore("&")
|
) ?: return@mapNotNull null
|
||||||
.toIntOrNull()
|
|
||||||
?.takeIf { it > 0 }
|
|
||||||
?: error(
|
|
||||||
"Niadd page count is missing for ${chapter.url}. " +
|
|
||||||
"Refresh manga details and try again."
|
|
||||||
)
|
|
||||||
|
|
||||||
val normalizedUrl = originalUrl
|
val pageNumber = match
|
||||||
.removeSuffix("/")
|
.groupValues
|
||||||
|
.getOrNull(1)
|
||||||
|
?.toIntOrNull()
|
||||||
|
?: return@mapNotNull null
|
||||||
|
|
||||||
val baseUrl = if (
|
val totalPages = match
|
||||||
normalizedUrl.endsWith(".html")
|
.groupValues
|
||||||
) {
|
.getOrNull(2)
|
||||||
normalizedUrl.removeSuffix(".html")
|
?.toIntOrNull()
|
||||||
} else {
|
?: return@mapNotNull null
|
||||||
normalizedUrl
|
|
||||||
}
|
|
||||||
|
|
||||||
return (1..totalPages).map { pageNumber ->
|
val url = option.attr("value").trim()
|
||||||
val url = if (pageNumber == 1) {
|
if (url.isEmpty()) {
|
||||||
originalUrl
|
return@mapNotNull null
|
||||||
} else {
|
}
|
||||||
"$baseUrl-$pageNumber.html"
|
|
||||||
|
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(
|
MangaPage(
|
||||||
id = generateUid(url),
|
id = generateUid(url),
|
||||||
url = url,
|
url = url,
|
||||||
@@ -686,12 +681,6 @@ 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