diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/DamCoNuong.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/DamCoNuong.kt index 283d95e7b..1160f7d57 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/DamCoNuong.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/DamCoNuong.kt @@ -186,33 +186,38 @@ internal class DamCoNuong(context: MangaLoaderContext) : override suspend fun getPages(chapter: MangaChapter): List { val doc = webClient.httpGet(chapter.url.toAbsoluteUrl(domain)).parseHtml() - val scriptContent = doc.selectFirst("script:containsData(window.encryptionConfig)") - ?.data() - ?: throw ParseException("Không tìm thấy script 'window.encryptionConfig'.", chapter.url) - - val fallbackUrlsRegex = Regex(""""fallbackUrls"\s*:\s*(\[.*?\])""") - val arrayString = fallbackUrlsRegex.find(scriptContent)?.groupValues?.get(1) - ?: throw ParseException("Không tìm thấy mảng 'fallbackUrls' trong script.", chapter.url) + doc.selectFirst("script:containsData(window.encryptionConfig)")?.data()?.let { scriptContent -> + val fallbackUrlsRegex = Regex(""""fallbackUrls"\s*:\s*(\[.*?\])""") + val arrayString = fallbackUrlsRegex.find(scriptContent)?.groupValues?.get(1) ?: return@let + val urlRegex = Regex("""(https?:\\?/\\?[^"]+\.(?:jpg|jpeg|png|webp|gif))""") + val scriptImages = urlRegex.findAll(arrayString).map { + it.groupValues[1].replace("\\/", "/") + }.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 imageUrls = urlRegex.findAll(arrayString).map { - it.groupValues[1].replace("\\/", "/") - }.toList() + val tagImagePages = doc.select("div#chapter-content img").mapNotNull { img -> + val imageUrl = (img.attr("abs:src").takeIf { it.isNotBlank() } + ?: img.attr("abs:data-src").takeIf { it.isNotBlank() }) + ?.trim() - if (imageUrls.isEmpty()) { - throw ParseException("Không tìm thấy URL ảnh hợp lệ nào trong 'fallbackUrls'.", chapter.url) + imageUrl?.let { + MangaPage(id = generateUid(it), url = it, preview = null, source = source) + } } - return imageUrls.map { url -> - MangaPage( - id = generateUid(url), - url = url, - preview = null, - source = source, - ) - } + if (tagImagePages.isNotEmpty()) { + return tagImagePages } + 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 { if (date == null) return 0 return when {