diff --git a/multisrc/overrides/madara/dragontea/src/DragonTea.kt b/multisrc/overrides/madara/dragontea/src/DragonTea.kt index c30942433..755f67b34 100644 --- a/multisrc/overrides/madara/dragontea/src/DragonTea.kt +++ b/multisrc/overrides/madara/dragontea/src/DragonTea.kt @@ -1,7 +1,23 @@ package eu.kanade.tachiyomi.extension.en.dragontea +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Canvas +import android.graphics.Rect +import android.util.Log import eu.kanade.tachiyomi.multisrc.madara.Madara +import eu.kanade.tachiyomi.source.model.Page +import okhttp3.Headers +import okhttp3.Interceptor +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.OkHttpClient +import okhttp3.Protocol +import okhttp3.Response +import okhttp3.ResponseBody.Companion.toResponseBody +import org.jsoup.nodes.Document +import java.io.ByteArrayOutputStream import java.text.SimpleDateFormat +import java.util.concurrent.TimeUnit import java.util.Locale class DragonTea : Madara( @@ -10,5 +26,94 @@ class DragonTea : Madara( "en", dateFormat = SimpleDateFormat("MM/dd/yyyy", Locale.US) ) { + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .connectTimeout(10, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .addInterceptor(::begonepeconIntercept) + .build() + override val useNewChapterEndpoint = true + + private val begonepeconSelector: String = "div.begonepecon" + + private val peconholderSelector: String = "div.peconholder" + + override fun pageListParse(document: Document): List { + countViews(document) + + val hasSplitImages = document + .select(begonepeconSelector) + .firstOrNull() != null + + if (!hasSplitImages) { + return super.pageListParse(document) + } + + return document.select("div.page-break, li.blocks-gallery-item, $begonepeconSelector") + .mapIndexed { index, element -> + val imageUrl = if (element.select(peconholderSelector).firstOrNull() == null) { + element.select("img").first()?.let { it.absUrl(if (it.hasAttr("data-src")) "data-src" else "src") } + } else { + element.select("img").joinToString("|") { it.absUrl(if (it.hasAttr("data-src")) "data-src" else "src") } + BEGONEPECON_SUFFIX + } + Page(index, document.location(), imageUrl) + } + } + + private fun begonepeconIntercept(chain: Interceptor.Chain): Response { + if (!chain.request().url.toString().endsWith(BEGONEPECON_SUFFIX)) { + return chain.proceed(chain.request()) + } + + val imageUrls = chain.request().url.toString() + .removeSuffix(BEGONEPECON_SUFFIX) + .split("%7C") + + var width = 0 + var height = 0 + + val imageBitmaps = imageUrls.map { imageUrl -> + val request = chain.request().newBuilder().url(imageUrl).build() + val response = chain.proceed(request) + + val bitmap = BitmapFactory.decodeStream(response.body!!.byteStream()) + + width += bitmap.width + height = bitmap.height + + bitmap + } + + val result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888) + val canvas = Canvas(result) + + var left = 0 + + imageBitmaps.forEach { bitmap -> + val srcRect = Rect(0, 0, bitmap.width, bitmap.height) + val dstRect = Rect(left, 0, left + bitmap.width, bitmap.height) + + canvas.drawBitmap(bitmap, srcRect, dstRect, null) + + left += bitmap.width + } + + val output = ByteArrayOutputStream() + result.compress(Bitmap.CompressFormat.PNG, 100, output) + + val responseBody = output.toByteArray().toResponseBody(PNG_MEDIA_TYPE) + + return Response.Builder() + .code(200) + .protocol(Protocol.HTTP_1_1) + .request(chain.request()) + .message("OK") + .body(responseBody) + .build() + } + + companion object { + private const val BEGONEPECON_SUFFIX = "?begonepecon" + private val PNG_MEDIA_TYPE = "image/png".toMediaType() + } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt index 813051d6e..a10e7eae3 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/MadaraGenerator.kt @@ -70,7 +70,7 @@ class MadaraGenerator : ThemeSourceGenerator { SingleLang("Disaster Scans", "https://disasterscans.com", "en", overrideVersionCode = 1), SingleLang("Diskus Scan", "https://diskusscan.com", "pt-BR", overrideVersionCode = 1), SingleLang("DoujinHentai", "https://doujinhentai.net", "es", isNsfw = true, overrideVersionCode = 1), - SingleLang("DragonTea", "https://dragontea.ink/", "en", overrideVersionCode = 2), + SingleLang("DragonTea", "https://dragontea.ink", "en", overrideVersionCode = 3), SingleLang("Dream Manga", "https://en.ruyamanga.com", "en", overrideVersionCode = 2), SingleLang("Drope Scan", "https://dropescan.com", "pt-BR", overrideVersionCode = 3), SingleLang("Dream Union Scan", "https://www.dreamunionscan.com", "pt-BR", overrideVersionCode = 1),