diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ExHentaiParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ExHentaiParser.kt index 84a6ee10..076250b4 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ExHentaiParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/ExHentaiParser.kt @@ -6,6 +6,7 @@ import androidx.collection.set import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.Interceptor import okhttp3.Response +import okhttp3.internal.closeQuietly import okhttp3.internal.headersContentLength import org.jsoup.internal.StringUtil import org.jsoup.nodes.Element @@ -284,10 +285,11 @@ internal class ExHentaiParser( val response = chain.proceed(chain.request()) if (response.headersContentLength() <= 256) { val text = response.peekBody(256).string() - if (text.startsWith("Your IP address has been temporarily banned")) { + if (text.startsWith("Your IP address has been temporarily banned", ignoreCase = true)) { val hours = Regex("([0-9]+) hours?").find(text)?.groupValues?.getOrNull(1)?.toLongOrNull() ?: 0 val minutes = Regex("([0-9]+) minutes?").find(text)?.groupValues?.getOrNull(1)?.toLongOrNull() ?: 0 val seconds = Regex("([0-9]+) seconds?").find(text)?.groupValues?.getOrNull(1)?.toLongOrNull() ?: 0 + response.closeQuietly() throw TooManyRequestExceptions( url = response.request.url.toString(), retryAfter = TimeUnit.HOURS.toMillis(hours) diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt index ae2b53dc..06fe8ce1 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaFireParser.kt @@ -406,9 +406,8 @@ internal abstract class MangaFireParser( return response } - val offset = request.url.fragment!!.substringAfter("_").toInt() - return context.redrawImageResponse(response) { bitmap -> + val offset = request.url.fragment!!.substringAfter("_").toInt() val width = bitmap.width val height = bitmap.height diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaPlusParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaPlusParser.kt index 601e5092..ef20be77 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaPlusParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/all/MangaPlusParser.kt @@ -227,14 +227,11 @@ internal abstract class MangaPlusParser( return response } - val contentType = response.headers["Content-Type"] ?: "image/jpeg" - - val image = requireNotNull(response.body).bytes().decodeXorCipher(encryptionKey) - val body = image.toResponseBody(contentType.toMediaTypeOrNull()) - - return response.newBuilder() - .body(body) - .build() + return response.map { responseBody -> + val contentType = response.headers["Content-Type"] ?: "image/jpeg" + val image = responseBody.bytes().decodeXorCipher(encryptionKey) + image.toResponseBody(contentType.toMediaTypeOrNull()) + } } private fun ByteArray.decodeXorCipher(key: String): ByteArray { diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/pt/LuratoonScansParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/pt/LuratoonScansParser.kt index 2f28045a..e58848ab 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/pt/LuratoonScansParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/pt/LuratoonScansParser.kt @@ -128,9 +128,11 @@ internal class LuratoonScansParser(context: MangaLoaderContext) : override fun intercept(chain: Interceptor.Chain): Response { val response = chain.proceed(chain.request()) if (response.mimeType == "application/octet-stream") { - val (bytes, name) = ZipInputStream(checkNotNull(response.body).byteStream()).use { - val entry = it.nextEntry - it.readBytes() to entry?.name + val (bytes, name) = response.use { resp -> + ZipInputStream(resp.requireBody().byteStream()).use { + val entry = it.nextEntry + it.readBytes() to entry?.name + } } val type = if (name?.endsWith(".avif", ignoreCase = true) == true) { "image/avif" diff --git a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/CuuTruyenParser.kt b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/CuuTruyenParser.kt index 3018bd21..c6f5bc1a 100644 --- a/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/CuuTruyenParser.kt +++ b/src/main/kotlin/org/koitharu/kotatsu/parsers/site/vi/CuuTruyenParser.kt @@ -189,8 +189,8 @@ internal class CuuTruyenParser(context: MangaLoaderContext) : return response } - val drmData = fragment.substringAfter(DRM_DATA_KEY) return context.redrawImageResponse(response) { bitmap -> + val drmData = fragment.substringAfter(DRM_DATA_KEY) unscrambleImage(bitmap, drmData) } }