From a599f54b8c3b00635612e40ebbc640277eacc845 Mon Sep 17 00:00:00 2001 From: Eshlender <35057681+e-shl@users.noreply.github.com> Date: Tue, 13 Jun 2023 00:00:14 +0500 Subject: [PATCH] [RU]LibGroup optimize-clean (#16719) * LibGroup more merge multisrc * LibGroup increase rateLimit for checkImage * url chapter no static * only delays access * sutoclean --- .../libgroup/hentailib/src/HentaiLib.kt | 16 ---------------- .../overrides/libgroup/mangalib/src/MangaLib.kt | 16 ---------------- .../overrides/libgroup/yaoilib/src/YaoiLib.kt | 16 ---------------- .../tachiyomi/multisrc/libgroup/LibGenerator.kt | 2 +- .../tachiyomi/multisrc/libgroup/LibGroup.kt | 14 ++++++-------- 5 files changed, 7 insertions(+), 57 deletions(-) diff --git a/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt b/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt index f3aea1844..82bc0025a 100644 --- a/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt +++ b/multisrc/overrides/libgroup/hentailib/src/HentaiLib.kt @@ -8,8 +8,6 @@ import eu.kanade.tachiyomi.multisrc.libgroup.LibGroup import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList -import okhttp3.Headers -import okhttp3.OkHttpClient import okhttp3.Request import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -25,20 +23,6 @@ class HentaiLib : LibGroup("HentaiLib", "https://v1.hentailib.org", "ru") { private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!! override val baseUrl: String = domain - override val client: OkHttpClient = super.client.newBuilder() - .addInterceptor(::imageContentTypeIntercept) - .build() - - private var csrfToken: String = "" - - private fun catalogHeaders() = Headers.Builder() - .apply { - add("Accept", "application/json, text/plain, */*") - add("X-Requested-With", "XMLHttpRequest") - add("x-csrf-token", csrfToken) - } - .build() - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { if (csrfToken.isEmpty()) { val tokenResponse = client.newCall(popularMangaRequest(page)).execute() diff --git a/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt b/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt index c676706ca..6efa9b2ff 100644 --- a/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt +++ b/multisrc/overrides/libgroup/mangalib/src/MangaLib.kt @@ -9,8 +9,6 @@ import eu.kanade.tachiyomi.multisrc.libgroup.LibGroup import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList -import okhttp3.Headers -import okhttp3.OkHttpClient import okhttp3.Request import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -28,20 +26,6 @@ class MangaLib : LibGroup("MangaLib", "https://mangalib.me", "ru") { private var domain: String? = preferences.getString(DOMAIN_PREF, baseOrig) override val baseUrl: String = domain.toString() - override val client: OkHttpClient = super.client.newBuilder() - .addInterceptor(::imageContentTypeIntercept) - .build() - - private var csrfToken: String = "" - - private fun catalogHeaders() = Headers.Builder() - .apply { - add("Accept", "application/json, text/plain, */*") - add("X-Requested-With", "XMLHttpRequest") - add("x-csrf-token", csrfToken) - } - .build() - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { if (csrfToken.isEmpty()) { val tokenResponse = client.newCall(popularMangaRequest(page)).execute() diff --git a/multisrc/overrides/libgroup/yaoilib/src/YaoiLib.kt b/multisrc/overrides/libgroup/yaoilib/src/YaoiLib.kt index 96d05e9d4..fdbfefeb2 100644 --- a/multisrc/overrides/libgroup/yaoilib/src/YaoiLib.kt +++ b/multisrc/overrides/libgroup/yaoilib/src/YaoiLib.kt @@ -8,8 +8,6 @@ import eu.kanade.tachiyomi.multisrc.libgroup.LibGroup import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.model.Filter import eu.kanade.tachiyomi.source.model.FilterList -import okhttp3.Headers -import okhttp3.OkHttpClient import okhttp3.Request import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -23,20 +21,6 @@ class YaoiLib : LibGroup("YaoiLib", "https://v1.slashlib.me", "ru") { private var domain: String = preferences.getString(DOMAIN_TITLE, DOMAIN_DEFAULT)!! override val baseUrl: String = domain - override val client: OkHttpClient = super.client.newBuilder() - .addInterceptor(::imageContentTypeIntercept) - .build() - - private var csrfToken: String = "" - - private fun catalogHeaders() = Headers.Builder() - .apply { - add("Accept", "application/json, text/plain, */*") - add("X-Requested-With", "XMLHttpRequest") - add("x-csrf-token", csrfToken) - } - .build() - override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { if (csrfToken.isEmpty()) { val tokenResponse = client.newCall(popularMangaRequest(page)).execute() diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt index 834423917..102f6f549 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGenerator.kt @@ -9,7 +9,7 @@ class LibGenerator : ThemeSourceGenerator { override val themeClass = "LibGroup" - override val baseVersionCode: Int = 19 + override val baseVersionCode: Int = 20 override val sources = listOf( SingleLang("MangaLib", "https://mangalib.me", "ru", overrideVersionCode = 74), diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt index 91b3a4d93..d8359112f 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/libgroup/LibGroup.kt @@ -45,7 +45,6 @@ import uy.kohesive.injekt.injectLazy import java.io.IOException import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit import kotlin.math.absoluteValue import kotlin.random.Random @@ -63,7 +62,7 @@ abstract class LibGroup( override val supportsLatest = true - protected fun imageContentTypeIntercept(chain: Interceptor.Chain): Response { + private fun imageContentTypeIntercept(chain: Interceptor.Chain): Response { val originalRequest = chain.request() val response = chain.proceed(originalRequest) val urlRequest = originalRequest.url.toString() @@ -77,9 +76,8 @@ abstract class LibGroup( } } override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(20, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) - .rateLimit(2) + .rateLimit(3) + .addNetworkInterceptor { imageContentTypeIntercept(it) } .addInterceptor { chain -> val response = chain.proceed(chain.request()) if (response.code == 419) { @@ -101,9 +99,9 @@ abstract class LibGroup( private val userAgentRandomizer = "${Random.nextInt().absoluteValue}" - private var csrfToken: String = "" + protected var csrfToken: String = "" - private fun catalogHeaders() = Headers.Builder() + protected fun catalogHeaders() = Headers.Builder() .apply { add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.$userAgentRandomizer") add("Accept", "application/json, text/plain, */*") @@ -395,7 +393,7 @@ abstract class LibGroup( val teamId = if (teamIdParam != null) "&bid=$teamIdParam" else "" - val url = "$baseUrl/$slug/v$volume/c$number?ui=$userId$teamId" + val url = "/$slug/v$volume/c$number?ui=$userId$teamId" chapter.setUrlWithoutDomain(url)