fix manga loading
Build Futon with Niadd patch / Build Futon Niadd debug APK (push) Successful in 14m25s
Build Futon with Niadd patch / Build Futon Niadd debug APK (push) Successful in 14m25s
This commit is contained in:
@@ -316,12 +316,6 @@ replace_exact(
|
||||
''',
|
||||
''' override suspend fun getDetails(manga: Manga): Manga {
|
||||
if (domain.endsWith("niadd.com")) {
|
||||
val detailsUrl = manga.url.toAbsoluteUrl(domain)
|
||||
|
||||
val detailsDoc = webClient.httpGet(
|
||||
"$detailsUrl?waring=1",
|
||||
).parseHtml()
|
||||
|
||||
val mangaPath = manga.url
|
||||
.substringBefore("?")
|
||||
.removeSuffix("/")
|
||||
@@ -336,6 +330,13 @@ replace_exact(
|
||||
chaptersPath.toAbsoluteUrl(domain) + "?waring=1",
|
||||
).parseHtml()
|
||||
|
||||
/*
|
||||
* Current Niadd chapters page already contains
|
||||
* manga title, status, authors, genres and language,
|
||||
* so avoid a second HTTP request to the details page.
|
||||
*/
|
||||
val detailsDoc = chaptersDoc
|
||||
|
||||
val heading = detailsDoc.selectFirst("h1")
|
||||
?.textOrNull()
|
||||
?.trim()
|
||||
@@ -607,87 +608,56 @@ replace_exact(
|
||||
"""^\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$"""
|
||||
)
|
||||
|
||||
val pageOptions = doc
|
||||
.select("option[value]")
|
||||
.filter { option ->
|
||||
pageLabelRegex.matches(
|
||||
option.text()
|
||||
) &&
|
||||
option.attr("value").isNotBlank()
|
||||
}
|
||||
.distinctBy { option ->
|
||||
option.attr("value")
|
||||
}
|
||||
|
||||
if (pageOptions.isNotEmpty()) {
|
||||
return pageOptions.map { option ->
|
||||
val url = option.attr("value")
|
||||
|
||||
MangaPage(
|
||||
id = generateUid(url),
|
||||
url = url,
|
||||
preview = null,
|
||||
source = source,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Fallback for a future Niadd layout where page
|
||||
* <option> elements stop containing values.
|
||||
*
|
||||
* Page URL structure currently is:
|
||||
*
|
||||
* page 1:
|
||||
* /chapter/3_81/5259607/
|
||||
* or
|
||||
* /chapter/2_80_2/5205144.html
|
||||
*
|
||||
* page 2:
|
||||
* /chapter/3_81/5259607-2.html
|
||||
*/
|
||||
val totalPages = doc
|
||||
.select("option")
|
||||
.mapNotNull { option ->
|
||||
pageLabelRegex
|
||||
.matchEntire(option.text())
|
||||
.matchEntire(
|
||||
option.text().trim()
|
||||
)
|
||||
?.groupValues
|
||||
?.getOrNull(2)
|
||||
?.toIntOrNull()
|
||||
}
|
||||
.maxOrNull()
|
||||
?: error(
|
||||
"Cannot find Niadd page count for ${chapter.url}"
|
||||
)
|
||||
|
||||
if (totalPages != null && totalPages > 0) {
|
||||
val originalUrl = chapter.url
|
||||
.substringBefore("?")
|
||||
|
||||
val baseUrl = originalUrl
|
||||
.replace(
|
||||
Regex("""-\\d+\\.html$"""),
|
||||
"",
|
||||
)
|
||||
.removeSuffix(".html")
|
||||
.removeSuffix("/")
|
||||
|
||||
return (1..totalPages).map { pageNumber ->
|
||||
val url = if (pageNumber == 1) {
|
||||
originalUrl
|
||||
} else {
|
||||
"$baseUrl-$pageNumber.html"
|
||||
}
|
||||
|
||||
MangaPage(
|
||||
id = generateUid(url),
|
||||
url = url,
|
||||
preview = null,
|
||||
source = source,
|
||||
)
|
||||
}
|
||||
if (totalPages <= 0) {
|
||||
error(
|
||||
"Invalid Niadd page count $totalPages for ${chapter.url}"
|
||||
)
|
||||
}
|
||||
|
||||
error(
|
||||
"Cannot find Niadd page selector for ${chapter.url}"
|
||||
)
|
||||
val originalUrl = chapter.url
|
||||
.substringBefore("?")
|
||||
|
||||
val normalizedUrl = originalUrl
|
||||
.removeSuffix("/")
|
||||
|
||||
val baseUrl = if (
|
||||
normalizedUrl.endsWith(".html")
|
||||
) {
|
||||
normalizedUrl.removeSuffix(".html")
|
||||
} else {
|
||||
normalizedUrl
|
||||
}
|
||||
|
||||
return (1..totalPages).map { pageNumber ->
|
||||
val url = if (pageNumber == 1) {
|
||||
originalUrl
|
||||
} else {
|
||||
"$baseUrl-$pageNumber.html"
|
||||
}
|
||||
|
||||
MangaPage(
|
||||
id = generateUid(url),
|
||||
url = url,
|
||||
preview = null,
|
||||
source = source,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return doc
|
||||
@@ -746,16 +716,17 @@ replace_exact(
|
||||
val root = doc.body()
|
||||
|
||||
if (domain.endsWith("niadd.com")) {
|
||||
val imageUrlRegex = Regex(
|
||||
"""(?i)\\.(?:jpe?g|png|gif|webp|avif)(?:\\?|$)"""
|
||||
val readerImageLinkRegex = Regex(
|
||||
"""^\\s*\\d+\\s+of\\s+\\d+\\s*$""",
|
||||
RegexOption.IGNORE_CASE,
|
||||
)
|
||||
|
||||
val imageAnchor = root
|
||||
.select("a[href]")
|
||||
.firstOrNull { element ->
|
||||
val href = element.attr("href")
|
||||
|
||||
imageUrlRegex.containsMatchIn(href)
|
||||
readerImageLinkRegex.matches(
|
||||
element.text()
|
||||
)
|
||||
}
|
||||
|
||||
if (imageAnchor != null) {
|
||||
@@ -764,12 +735,22 @@ replace_exact(
|
||||
)
|
||||
}
|
||||
|
||||
/*
|
||||
* Fallback in case Niadd removes the "N of M"
|
||||
* image link but leaves the actual image element.
|
||||
*/
|
||||
val imageUrlRegex = Regex(
|
||||
"""(?i)\\.(?:jpe?g|png|gif|webp|avif)(?:\\?|$)"""
|
||||
)
|
||||
|
||||
val image = root
|
||||
.select("img[src]")
|
||||
.firstOrNull { element ->
|
||||
val src = element.attr("src")
|
||||
|
||||
imageUrlRegex.containsMatchIn(src)
|
||||
imageUrlRegex.containsMatchIn(src) &&
|
||||
!src.contains("logo", ignoreCase = true) &&
|
||||
!src.contains("avatar", ignoreCase = true)
|
||||
}
|
||||
|
||||
if (image != null) {
|
||||
@@ -777,7 +758,7 @@ replace_exact(
|
||||
}
|
||||
|
||||
error(
|
||||
"Cannot find Niadd page image for ${page.url}"
|
||||
"Cannot find Niadd reader image for ${page.url}"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user