[ImHentai] Fix pages parsing

master
Koitharu 1 year ago
parent ac163085e1
commit 275d7f5419
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -214,8 +214,9 @@ internal class ImHentai(context: MangaLoaderContext) :
val fullUrl = chapter.url.toAbsoluteUrl(domain) val fullUrl = chapter.url.toAbsoluteUrl(domain)
val doc = webClient.httpGet(fullUrl).parseHtml() val doc = webClient.httpGet(fullUrl).parseHtml()
val totalPages = doc.selectFirstOrThrow(".pages").text().replace("Pages: ", "").toInt() val totalPages = doc.selectFirstOrThrow(".pages").text().replace("Pages: ", "").toInt()
val baseUrl = doc.requireElementById("append_thumbs").selectFirstOrThrow("img").src() val baseImg = doc.requireElementById("append_thumbs").selectFirstOrThrow("img")
?.replace("/1t.", "/\$t.") ?: doc.parseFailed("Base page url not found") val baseUrl = baseImg.selectFirstParentOrThrow("a").attrAsRelativeUrl("href").replace("/1/", "/\$/")
val baseThumbUrl = baseImg.src()?.replace("/1t.", "/\$t.")
val pages = ArrayList<MangaPage>(totalPages) val pages = ArrayList<MangaPage>(totalPages)
repeat(totalPages) { i -> repeat(totalPages) { i ->
val url = baseUrl.replace("\$", (i + 1).toString()) val url = baseUrl.replace("\$", (i + 1).toString())
@ -223,11 +224,17 @@ internal class ImHentai(context: MangaLoaderContext) :
MangaPage( MangaPage(
id = generateUid(url), id = generateUid(url),
url = url, url = url,
preview = null, preview = baseThumbUrl?.replace("\$", (i + 1).toString()),
source = source, source = source,
), ),
) )
} }
return pages return pages
} }
override suspend fun getPageUrl(page: MangaPage): String {
val doc = webClient.httpGet(page.url.toAbsoluteUrl(domain)).parseHtml()
val img = doc.body().requireElementById("gimg")
return img.src() ?: doc.parseFailed("Cannot find image src")
}
} }

@ -142,6 +142,9 @@ public fun Element.selectFirstParent(query: String): Element? {
} }
} }
public fun Element.selectFirstParentOrThrow(query: String): Element =
selectFirstParent(query) ?: throw ParseException("Cannot find parent \"$query\"", baseUri())
/** /**
* Return a first non-empty attribute value of [names] or null if it is missing or empty * Return a first non-empty attribute value of [names] or null if it is missing or empty
*/ */

Loading…
Cancel
Save