Some suggestions

This commit is contained in:
Draken
2024-08-31 20:50:52 +07:00
committed by Koitharu
parent 69ee6be246
commit c6dc51bb5d

View File

@@ -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 {
decompress(decrypted)
} catch (e: Exception) {
decrypted
}
val newBody = decompressed.toResponseBody(contentType)
return response.newBuilder().body(newBody).build()
} }
private fun decrypt(input: ByteArray): ByteArray { val body = response.body ?: return response
val key = decryptionKey.toByteArray() val contentType = body.contentType()
return input.mapIndexed { index, byte -> val bytes = body.bytes()
(byte.toInt() xor key[index % key.size].toInt()).toByte()
}.toByteArray() val decrypted = try {
decrypt(bytes)
} catch (e: Exception) {
bytes
} }
private fun decompress(input: ByteArray): ByteArray { val decompressed = try {
val inflater = Inflater() decompress(decrypted)
inflater.setInput(input, 0, input.size) } catch (e: Exception) {
val outputStream = ByteArrayOutputStream(input.size) decrypted
val buffer = ByteArray(1024)
while (!inflater.finished()) {
val count = inflater.inflate(buffer)
outputStream.write(buffer, 0, count)
}
return outputStream.toByteArray()
} }
val newBody = decompressed.toResponseBody(contentType)
return response.newBuilder().body(newBody).build()
}
private fun decrypt(input: ByteArray): ByteArray {
val key = decryptionKey.toByteArray()
return input.mapIndexed { index, byte ->
(byte.toInt() xor key[index % key.size].toInt()).toByte()
}.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 {