[Grouple] Fix relative page urls
This commit is contained in:
@@ -240,8 +240,8 @@ internal abstract class GroupleParser(
|
||||
val path = parts.last()
|
||||
val servers = parts.dropLast(1).toSet()
|
||||
val cachedServer = cachedPagesServer
|
||||
if (cachedServer != null && cachedServer in servers && tryHead(cachedServer + path)) {
|
||||
return cachedServer + path
|
||||
if (cachedServer != null && cachedServer in servers && tryHead(concatUrl(cachedServer, path))) {
|
||||
return concatUrl(cachedServer, path)
|
||||
}
|
||||
if (servers.isEmpty()) {
|
||||
throw ParseException("No servers found for page", page.url)
|
||||
@@ -250,7 +250,8 @@ internal abstract class GroupleParser(
|
||||
coroutineScope {
|
||||
servers.map { server ->
|
||||
async {
|
||||
if (tryHead(server + path)) server else null
|
||||
val host = server.trim().ifEmpty { "https://$domain/" }
|
||||
if (tryHead(concatUrl(host, path))) host else null
|
||||
}
|
||||
}.awaitFirst { it != null }
|
||||
}.also {
|
||||
@@ -259,7 +260,7 @@ internal abstract class GroupleParser(
|
||||
} catch (e: NoSuchElementException) {
|
||||
servers.random()
|
||||
}
|
||||
return checkNotNull(server) + path
|
||||
return concatUrl(checkNotNull(server), path)
|
||||
}
|
||||
|
||||
override suspend fun getTags(): Set<MangaTag> {
|
||||
@@ -352,7 +353,7 @@ internal abstract class GroupleParser(
|
||||
return webClient.httpPost(url, payload)
|
||||
}
|
||||
|
||||
suspend fun tryHead(url: String): Boolean = runCatchingCancellable {
|
||||
private suspend fun tryHead(url: String): Boolean = runCatchingCancellable {
|
||||
val response = webClient.httpHead(url)
|
||||
response.isSuccessful && response.headersContentLength() >= MIN_IMAGE_SIZE
|
||||
}.getOrDefault(false)
|
||||
|
||||
@@ -67,6 +67,16 @@ fun String.toAbsoluteUrl(domain: String): String = when {
|
||||
else -> this
|
||||
}
|
||||
|
||||
fun concatUrl(host: String, path: String): String {
|
||||
val hostWithSlash = host.endsWith('/')
|
||||
val pathWithSlash = path.startsWith('/')
|
||||
return when {
|
||||
hostWithSlash && pathWithSlash -> host + path.drop(1)
|
||||
!hostWithSlash && !pathWithSlash -> "$host/$path"
|
||||
else -> host + path
|
||||
}
|
||||
}
|
||||
|
||||
fun DateFormat.tryParse(str: String?): Long = if (str.isNullOrEmpty()) {
|
||||
assert(false) { "Date string is null or empty" }
|
||||
0L
|
||||
@@ -78,4 +88,4 @@ fun DateFormat.tryParse(str: String?): Long = if (str.isNullOrEmpty()) {
|
||||
}.getOrDefault(0L)
|
||||
}
|
||||
|
||||
private fun Response.requireBody(): ResponseBody = requireNotNull(body) { "Response body is null" }
|
||||
private fun Response.requireBody(): ResponseBody = requireNotNull(body) { "Response body is null" }
|
||||
|
||||
Reference in New Issue
Block a user