diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenFE.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenFE.kt index 42abd4ce..b02fb89b 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenFE.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenFE.kt @@ -1,5 +1,9 @@ package org.koitharu.kotatsu.parsers.site.wpcomics.vi +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope +import org.jsoup.nodes.Element import androidx.collection.ArrayMap import kotlinx.coroutines.sync.withLock import org.koitharu.kotatsu.parsers.MangaLoaderContext @@ -134,14 +138,26 @@ internal class NetTruyenFE(context: MangaLoaderContext) : override suspend fun getPages(chapter: MangaChapter): List { val fullUrl = chapter.url.toAbsoluteUrl(domain) val doc = webClient.httpGet(fullUrl).parseHtml() - return doc.select(selectPage).map { url -> - var img = url.attr("data-original").toRelativeUrl(domain) - MangaPage( - id = generateUid(img), - url = img, - preview = null, - source = source, - ) + return coroutineScope { + doc.select(selectPage).map { img -> + async { fetchPage(img) } + }.awaitAll().filterNotNull() } } -} + + private suspend fun fetchPage(img: Element): MangaPage? = runCatchingCancellable { + val url = img.attrAsRelativeUrlOrNull("data-original") ?: return@runCatchingCancellable null + webClient.httpHead(url).use { response -> + if (response.mimeType?.startsWith("image/") == true) { + MangaPage( + id = generateUid(url), + url = url, + preview = null, + source = source, + ) + } else { + null + } + } + }.getOrNull() +} \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenLL.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenLL.kt index 6cc08b9d..f38f3242 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenLL.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenLL.kt @@ -1,5 +1,9 @@ package org.koitharu.kotatsu.parsers.site.wpcomics.vi +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope +import org.jsoup.nodes.Element import androidx.collection.ArrayMap import kotlinx.coroutines.sync.withLock import org.koitharu.kotatsu.parsers.MangaLoaderContext @@ -134,14 +138,26 @@ internal class NetTruyenLL(context: MangaLoaderContext) : override suspend fun getPages(chapter: MangaChapter): List { val fullUrl = chapter.url.toAbsoluteUrl(domain) val doc = webClient.httpGet(fullUrl).parseHtml() - return doc.select(selectPage).map { url -> - var img = url.attr("data-original").toRelativeUrl(domain) - MangaPage( - id = generateUid(img), - url = img, - preview = null, - source = source, - ) + return coroutineScope { + doc.select(selectPage).map { img -> + async { fetchPage(img) } + }.awaitAll().filterNotNull() } } -} + + private suspend fun fetchPage(img: Element): MangaPage? = runCatchingCancellable { + val url = img.attrAsRelativeUrlOrNull("data-original") ?: return@runCatchingCancellable null + webClient.httpHead(url).use { response -> + if (response.mimeType?.startsWith("image/") == true) { + MangaPage( + id = generateUid(url), + url = url, + preview = null, + source = source, + ) + } else { + null + } + } + }.getOrNull() +} \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenSSR.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenSSR.kt index 6b9d0db2..bd9588f5 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenSSR.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenSSR.kt @@ -1,5 +1,9 @@ package org.koitharu.kotatsu.parsers.site.wpcomics.vi +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope +import org.jsoup.nodes.Element import androidx.collection.ArrayMap import kotlinx.coroutines.sync.withLock import org.koitharu.kotatsu.parsers.MangaLoaderContext @@ -134,14 +138,26 @@ internal class NetTruyenSSR(context: MangaLoaderContext) : override suspend fun getPages(chapter: MangaChapter): List { val fullUrl = chapter.url.toAbsoluteUrl(domain) val doc = webClient.httpGet(fullUrl).parseHtml() - return doc.select(selectPage).map { url -> - var img = url.attr("data-original").toRelativeUrl(domain) - MangaPage( - id = generateUid(img), - url = img, - preview = null, - source = source, - ) + return coroutineScope { + doc.select(selectPage).map { img -> + async { fetchPage(img) } + }.awaitAll().filterNotNull() } } -} + + private suspend fun fetchPage(img: Element): MangaPage? = runCatchingCancellable { + val url = img.attrAsRelativeUrlOrNull("data-original") ?: return@runCatchingCancellable null + webClient.httpHead(url).use { response -> + if (response.mimeType?.startsWith("image/") == true) { + MangaPage( + id = generateUid(url), + url = url, + preview = null, + source = source, + ) + } else { + null + } + } + }.getOrNull() +} \ No newline at end of file diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenUU.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenUU.kt index 318112f5..8e1cc40f 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenUU.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/wpcomics/vi/NetTruyenUU.kt @@ -1,5 +1,9 @@ package org.koitharu.kotatsu.parsers.site.wpcomics.vi +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll +import kotlinx.coroutines.coroutineScope +import org.jsoup.nodes.Element import androidx.collection.ArrayMap import kotlinx.coroutines.sync.withLock import org.koitharu.kotatsu.parsers.MangaLoaderContext @@ -134,14 +138,26 @@ internal class NetTruyenUU(context: MangaLoaderContext) : override suspend fun getPages(chapter: MangaChapter): List { val fullUrl = chapter.url.toAbsoluteUrl(domain) val doc = webClient.httpGet(fullUrl).parseHtml() - return doc.select(selectPage).map { url -> - var img = url.attr("data-original").toRelativeUrl(domain) - MangaPage( - id = generateUid(img), - url = img, - preview = null, - source = source, - ) + return coroutineScope { + doc.select(selectPage).map { img -> + async { fetchPage(img) } + }.awaitAll().filterNotNull() } } -} + + private suspend fun fetchPage(img: Element): MangaPage? = runCatchingCancellable { + val url = img.attrAsRelativeUrlOrNull("data-original") ?: return@runCatchingCancellable null + webClient.httpHead(url).use { response -> + if (response.mimeType?.startsWith("image/") == true) { + MangaPage( + id = generateUid(url), + url = url, + preview = null, + source = source, + ) + } else { + null + } + } + }.getOrNull() +} \ No newline at end of file