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:
1 file changed
+46
-65
@@ -316,12 +316,6 @@ replace_exact(
|
|||||||
''',
|
''',
|
||||||
''' override suspend fun getDetails(manga: Manga): Manga {
|
''' override suspend fun getDetails(manga: Manga): Manga {
|
||||||
if (domain.endsWith("niadd.com")) {
|
if (domain.endsWith("niadd.com")) {
|
||||||
val detailsUrl = manga.url.toAbsoluteUrl(domain)
|
|
||||||
|
|
||||||
val detailsDoc = webClient.httpGet(
|
|
||||||
"$detailsUrl?waring=1",
|
|
||||||
).parseHtml()
|
|
||||||
|
|
||||||
val mangaPath = manga.url
|
val mangaPath = manga.url
|
||||||
.substringBefore("?")
|
.substringBefore("?")
|
||||||
.removeSuffix("/")
|
.removeSuffix("/")
|
||||||
@@ -336,6 +330,13 @@ replace_exact(
|
|||||||
chaptersPath.toAbsoluteUrl(domain) + "?waring=1",
|
chaptersPath.toAbsoluteUrl(domain) + "?waring=1",
|
||||||
).parseHtml()
|
).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")
|
val heading = detailsDoc.selectFirst("h1")
|
||||||
?.textOrNull()
|
?.textOrNull()
|
||||||
?.trim()
|
?.trim()
|
||||||
@@ -607,68 +608,42 @@ replace_exact(
|
|||||||
"""^\\s*(\\d+)\\s*/\\s*(\\d+)\\s*$"""
|
"""^\\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
|
val totalPages = doc
|
||||||
.select("option")
|
.select("option")
|
||||||
.mapNotNull { option ->
|
.mapNotNull { option ->
|
||||||
pageLabelRegex
|
pageLabelRegex
|
||||||
.matchEntire(option.text())
|
.matchEntire(
|
||||||
|
option.text().trim()
|
||||||
|
)
|
||||||
?.groupValues
|
?.groupValues
|
||||||
?.getOrNull(2)
|
?.getOrNull(2)
|
||||||
?.toIntOrNull()
|
?.toIntOrNull()
|
||||||
}
|
}
|
||||||
.maxOrNull()
|
.maxOrNull()
|
||||||
|
?: error(
|
||||||
|
"Cannot find Niadd page count for ${chapter.url}"
|
||||||
|
)
|
||||||
|
|
||||||
|
if (totalPages <= 0) {
|
||||||
|
error(
|
||||||
|
"Invalid Niadd page count $totalPages for ${chapter.url}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (totalPages != null && totalPages > 0) {
|
|
||||||
val originalUrl = chapter.url
|
val originalUrl = chapter.url
|
||||||
.substringBefore("?")
|
.substringBefore("?")
|
||||||
|
|
||||||
val baseUrl = originalUrl
|
val normalizedUrl = originalUrl
|
||||||
.replace(
|
|
||||||
Regex("""-\\d+\\.html$"""),
|
|
||||||
"",
|
|
||||||
)
|
|
||||||
.removeSuffix(".html")
|
|
||||||
.removeSuffix("/")
|
.removeSuffix("/")
|
||||||
|
|
||||||
|
val baseUrl = if (
|
||||||
|
normalizedUrl.endsWith(".html")
|
||||||
|
) {
|
||||||
|
normalizedUrl.removeSuffix(".html")
|
||||||
|
} else {
|
||||||
|
normalizedUrl
|
||||||
|
}
|
||||||
|
|
||||||
return (1..totalPages).map { pageNumber ->
|
return (1..totalPages).map { pageNumber ->
|
||||||
val url = if (pageNumber == 1) {
|
val url = if (pageNumber == 1) {
|
||||||
originalUrl
|
originalUrl
|
||||||
@@ -685,11 +660,6 @@ replace_exact(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
error(
|
|
||||||
"Cannot find Niadd page selector for ${chapter.url}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
.body()
|
.body()
|
||||||
.requireElementById("page")
|
.requireElementById("page")
|
||||||
@@ -746,16 +716,17 @@ replace_exact(
|
|||||||
val root = doc.body()
|
val root = doc.body()
|
||||||
|
|
||||||
if (domain.endsWith("niadd.com")) {
|
if (domain.endsWith("niadd.com")) {
|
||||||
val imageUrlRegex = Regex(
|
val readerImageLinkRegex = Regex(
|
||||||
"""(?i)\\.(?:jpe?g|png|gif|webp|avif)(?:\\?|$)"""
|
"""^\\s*\\d+\\s+of\\s+\\d+\\s*$""",
|
||||||
|
RegexOption.IGNORE_CASE,
|
||||||
)
|
)
|
||||||
|
|
||||||
val imageAnchor = root
|
val imageAnchor = root
|
||||||
.select("a[href]")
|
.select("a[href]")
|
||||||
.firstOrNull { element ->
|
.firstOrNull { element ->
|
||||||
val href = element.attr("href")
|
readerImageLinkRegex.matches(
|
||||||
|
element.text()
|
||||||
imageUrlRegex.containsMatchIn(href)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageAnchor != null) {
|
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
|
val image = root
|
||||||
.select("img[src]")
|
.select("img[src]")
|
||||||
.firstOrNull { element ->
|
.firstOrNull { element ->
|
||||||
val src = element.attr("src")
|
val src = element.attr("src")
|
||||||
|
|
||||||
imageUrlRegex.containsMatchIn(src)
|
imageUrlRegex.containsMatchIn(src) &&
|
||||||
|
!src.contains("logo", ignoreCase = true) &&
|
||||||
|
!src.contains("avatar", ignoreCase = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
@@ -777,7 +758,7 @@ replace_exact(
|
|||||||
}
|
}
|
||||||
|
|
||||||
error(
|
error(
|
||||||
"Cannot find Niadd page image for ${page.url}"
|
"Cannot find Niadd reader image for ${page.url}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user