Update getpage for DamCoNuong parser (#2149)

* Update DamCoNuong.kt

* Update DamCoNuong.kt to fix "Can't find fallbackUrls"

* Update DamCoNuong.kt
master
Hoàng Phi Hùng 8 months ago committed by GitHub
parent 5a039acf82
commit 8a147dbdd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -186,33 +186,38 @@ internal class DamCoNuong(context: MangaLoaderContext) :
override suspend fun getPages(chapter: MangaChapter): List<MangaPage> { override suspend fun getPages(chapter: MangaChapter): List<MangaPage> {
val doc = webClient.httpGet(chapter.url.toAbsoluteUrl(domain)).parseHtml() val doc = webClient.httpGet(chapter.url.toAbsoluteUrl(domain)).parseHtml()
val scriptContent = doc.selectFirst("script:containsData(window.encryptionConfig)") doc.selectFirst("script:containsData(window.encryptionConfig)")?.data()?.let { scriptContent ->
?.data() val fallbackUrlsRegex = Regex(""""fallbackUrls"\s*:\s*(\[.*?\])""")
?: throw ParseException("Không tìm thấy script 'window.encryptionConfig'.", chapter.url) val arrayString = fallbackUrlsRegex.find(scriptContent)?.groupValues?.get(1) ?: return@let
val urlRegex = Regex("""(https?:\\?/\\?[^"]+\.(?:jpg|jpeg|png|webp|gif))""")
val fallbackUrlsRegex = Regex(""""fallbackUrls"\s*:\s*(\[.*?\])""") val scriptImages = urlRegex.findAll(arrayString).map {
val arrayString = fallbackUrlsRegex.find(scriptContent)?.groupValues?.get(1) it.groupValues[1].replace("\\/", "/")
?: throw ParseException("Không tìm thấy mảng 'fallbackUrls' trong script.", chapter.url) }.toList()
if (scriptImages.isNotEmpty()) {
return scriptImages.map { url ->
MangaPage(id = generateUid(url), url = url, preview = null, source = source)
}
}
}
val urlRegex = Regex("""(https?:\\?/\\?[^"]+\.(?:jpg|jpeg|png|webp|gif))""") val tagImagePages = doc.select("div#chapter-content img").mapNotNull { img ->
val imageUrls = urlRegex.findAll(arrayString).map { val imageUrl = (img.attr("abs:src").takeIf { it.isNotBlank() }
it.groupValues[1].replace("\\/", "/") ?: img.attr("abs:data-src").takeIf { it.isNotBlank() })
}.toList() ?.trim()
if (imageUrls.isEmpty()) { imageUrl?.let {
throw ParseException("Không tìm thấy URL ảnh hợp lệ nào trong 'fallbackUrls'.", chapter.url) MangaPage(id = generateUid(it), url = it, preview = null, source = source)
}
} }
return imageUrls.map { url -> if (tagImagePages.isNotEmpty()) {
MangaPage( return tagImagePages
id = generateUid(url),
url = url,
preview = null,
source = source,
)
}
} }
throw ParseException("Không tìm thấy bất kỳ nguồn ảnh nào (đã thử cả script và thẻ img).", chapter.url)
}
private fun parseChapterDate(date: String?): Long { private fun parseChapterDate(date: String?): Long {
if (date == null) return 0 if (date == null) return 0
return when { return when {

Loading…
Cancel
Save