[wpcomics/vi/nettruyen*] Fix fetch invaild format

This commit is contained in:
Draken
2025-02-07 12:15:09 +00:00
parent 319225d645
commit 576de54ef8
4 changed files with 100 additions and 36 deletions

View File

@@ -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<MangaPage> {
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()
}

View File

@@ -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<MangaPage> {
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()
}

View File

@@ -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<MangaPage> {
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()
}

View File

@@ -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<MangaPage> {
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()
}