Some suggestions

master
Draken 2 years ago committed by Koitharu
parent 69ee6be246
commit c6dc51bb5d

@ -19,9 +19,9 @@ import java.util.*
import java.util.zip.Inflater import java.util.zip.Inflater
@MangaSourceParser("CUUTRUYEN", "CuuTruyen", "vi") @MangaSourceParser("CUUTRUYEN", "CuuTruyen", "vi")
internal class CuuTruyenParser(context: MangaLoaderContext) : PagedMangaParser(context, MangaParserSource.CUUTRUYEN, 20) { internal class CuuTruyenParser(context: MangaLoaderContext) : PagedMangaParser(context, MangaParserSource.CUUTRUYEN, 20), Interceptor {
override val configKeyDomain = ConfigKey.Domain("cuutruyen.net", "nettrom.com", "hetcuutruyen.net", "cuutruyent9sv7.xyz") override val configKeyDomain = ConfigKey.Domain("cuutruyen.net")
override val availableSortOrders: Set<SortOrder> = EnumSet.of( override val availableSortOrders: Set<SortOrder> = EnumSet.of(
SortOrder.UPDATED, SortOrder.UPDATED,
@ -79,10 +79,10 @@ internal class CuuTruyenParser(context: MangaLoaderContext) : PagedMangaParser(c
altTitle = null, altTitle = null,
coverUrl = jo.getString("cover_url"), coverUrl = jo.getString("cover_url"),
largeCoverUrl = jo.getString("cover_mobile_url"), largeCoverUrl = jo.getString("cover_mobile_url"),
author = jo.optString("author_name", ""), author = jo.getStringOrNull("author_name"),
tags = emptySet(), tags = emptySet(),
state = null, state = null,
description = "", description = null,
isNsfw = false, isNsfw = false,
source = source, source = source,
rating = RATING_UNKNOWN, rating = RATING_UNKNOWN,
@ -128,53 +128,51 @@ internal class CuuTruyenParser(context: MangaLoaderContext) : PagedMangaParser(c
} }
} }
private inner class CuuTruyenImageInterceptor : Interceptor { override fun intercept(chain: Interceptor.Chain): Response {
override fun intercept(chain: Interceptor.Chain): Response { val request = chain.request()
val request = chain.request() val response = chain.proceed(request)
val response = chain.proceed(request)
if (!request.url.toString().contains(".cuutruyen.net")) { if (!request.url.toString().contains(".cuutruyen.net")) {
return response return response
} }
val body = response.body ?: return response
val contentType = body.contentType()
val bytes = body.bytes()
val decrypted = try {
decrypt(bytes)
} catch (e: Exception) {
bytes
}
val decompressed = try { val body = response.body ?: return response
decompress(decrypted) val contentType = body.contentType()
} catch (e: Exception) { val bytes = body.bytes()
decrypted
}
val newBody = decompressed.toResponseBody(contentType) val decrypted = try {
return response.newBuilder().body(newBody).build() decrypt(bytes)
} catch (e: Exception) {
bytes
} }
private fun decrypt(input: ByteArray): ByteArray { val decompressed = try {
val key = decryptionKey.toByteArray() decompress(decrypted)
return input.mapIndexed { index, byte -> } catch (e: Exception) {
(byte.toInt() xor key[index % key.size].toInt()).toByte() decrypted
}.toByteArray()
} }
private fun decompress(input: ByteArray): ByteArray { val newBody = decompressed.toResponseBody(contentType)
val inflater = Inflater() return response.newBuilder().body(newBody).build()
inflater.setInput(input, 0, input.size) }
val outputStream = ByteArrayOutputStream(input.size)
val buffer = ByteArray(1024) private fun decrypt(input: ByteArray): ByteArray {
while (!inflater.finished()) { val key = decryptionKey.toByteArray()
val count = inflater.inflate(buffer) return input.mapIndexed { index, byte ->
outputStream.write(buffer, 0, count) (byte.toInt() xor key[index % key.size].toInt()).toByte()
} }.toByteArray()
return outputStream.toByteArray() }
private fun decompress(input: ByteArray): ByteArray {
val inflater = Inflater()
inflater.setInput(input, 0, input.size)
val outputStream = ByteArrayOutputStream(input.size)
val buffer = ByteArray(1024)
while (!inflater.finished()) {
val count = inflater.inflate(buffer)
outputStream.write(buffer, 0, count)
} }
return outputStream.toByteArray()
} }
private fun parseChapterDate(dateString: String): Long { private fun parseChapterDate(dateString: String): Long {

Loading…
Cancel
Save