From 50b5d3361413c60272621596eb04d9050e113ec1 Mon Sep 17 00:00:00 2001 From: AwkwardPeak7 <48650614+AwkwardPeak7@users.noreply.github.com> Date: Sun, 16 Jul 2023 03:52:35 +0500 Subject: [PATCH] Random User-Agent Refactor (#17059) * lib-randomua * NHentai: Random mobile ua * Madara random UA overhaul * MangaThemesia random UA overhaul * MangaHub random UA overhaul * build errors and warnings * remove preference from Constellar * change to singleton object * network.client * fix copy paste and chapter deep link * exit early * use data class and enum options * missing import * suggested changes Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * re-add empty check to filters * convert to interceptor * update comment Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * update error message * initialize client by lazy * dont check on excluded Filters Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * newlines * move preference helper function into lib * move preference helper function into lib x2 * move check to lib too * move defaultRandomUserAgentType to constructor * rename the interceptor * organize the interceptor and preference stuff in different files * hide custom ua setting when random ua is enabled * English Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * catch specific exception Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> * setVisible() fresh stuff * setVisible() fresh stuff * change summary * workaround * Update error message Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> * Update comment Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> Co-authored-by: Alessandro Jean <14254807+alessandrojean@users.noreply.github.com> --- lib/randomua/build.gradle.kts | 23 +++ .../randomua/RandomUserAgentInterceptor.kt | 121 ++++++++++++ .../lib/randomua/RandomUserAgentPreference.kt | 83 +++++++++ .../madara/anisamanga/src/AnisaManga.kt | 9 - .../src/BokugenTranslation.kt | 6 +- .../madara/default/additional.gradle | 5 +- .../madara/doodmanga/src/Doodmanga.kt | 6 +- .../firstkissmanga/src/FirstKissManga.kt | 5 +- .../src/FirstKissMangaClub.kt | 2 +- .../src/FirstKissMangaLove.kt | 2 +- .../firstkissmanhua/src/FirstKissManhua.kt | 2 +- .../madara/fleurblanche/src/FleurBlanche.kt | 3 - .../madara/hentaiteca/src/HentaiTeca.kt | 4 - .../src/IchirinNoHanaYuri.kt | 3 - .../madara/manga18fx/src/Manga18fx.kt | 2 - .../madara/mangastarz/src/MangaStarz.kt | 4 - .../overrides/madara/manhuaga/src/Manhuaga.kt | 5 +- .../madara/mixedmanga/src/MixedManga.kt | 5 +- .../madara/shieldmanga/src/ShieldManga.kt | 5 +- .../madara/topmanhua/src/TopManhua.kt | 3 - .../madara/yanpfansub/src/YANPFansub.kt | 2 +- .../madara/yaoitoshokan/src/YaoiToshokan.kt | 6 +- .../madara/yugenmangas/src/YugenMangas.kt | 17 +- .../mangahub/default/additional.gradle | 3 + .../asurascans/src/AsuraScansEn.kt | 7 +- .../asurascans/src/AsuraScansTr.kt | 5 +- .../mangathemesia/boosei/src/Boosei.kt | 5 +- .../constellarscans/src/ConstellarScans.kt | 3 + .../mangathemesia/default/additional.gradle | 3 + .../mangathemesia/dojingnet/src/DojingNet.kt | 5 +- .../flamescans/src/FlameScans.kt | 5 +- .../franxxmangas/src/FranxxMangas.kt | 2 +- .../mangathemesia/kiryuu/src/Kiryuu.kt | 5 +- .../mangathemesia/komikav/src/KomikAV.kt | 5 +- .../mangathemesia/komikcast/src/KomikCast.kt | 9 +- .../komikdewasa/src/KomikDewasa.kt | 5 +- .../komikindoco/src/KomikindoCo.kt | 5 +- .../komikmanhwa/src/KomikManhwa.kt | 5 +- .../komikstation/src/KomikStation.kt | 5 +- .../mangathemesia/kumapoi/src/KumaPoi.kt | 5 +- .../mangathemesia/kumascans/src/KumaScans.kt | 5 +- .../mangathemesia/lianscans/src/LianScans.kt | 5 +- .../mangathemesia/mangakyo/src/Mangakyo.kt | 5 +- .../mangaraworg/src/MangaRawOrg.kt | 5 +- .../mangaschan/src/MangasChan.kt | 2 +- .../mangathemesia/mangayaro/src/Mangayaro.kt | 5 +- .../mangathemesia/mangceh/src/Mareceh.kt | 5 +- .../mangathemesia/mangkomik/src/MangKomik.kt | 2 +- .../manhwadesu/src/ManhwaDesu.kt | 5 +- .../manhwafreak/src/ManhwaFreak.kt | 2 +- .../manhwaindo/src/ManhwaIndo.kt | 2 +- .../manhwalandmom/src/ManhwaLandMom.kt | 5 +- .../manhwalist/src/ManhwaList.kt | 5 +- .../masterkomik/src/MasterKomik.kt | 5 +- .../mirrordesu/src/MirrorDesu.kt | 5 +- .../modescanlator/src/ModeScanlator.kt | 2 +- .../mangathemesia/nekomik/src/Nekomik.kt | 5 +- .../origamiorpheans/src/OrigamiOrpheans.kt | 2 +- .../mangathemesia/rawkuma/src/Rawkuma.kt | 5 +- .../mangathemesia/readkomik/src/ReadKomik.kt | 5 +- .../ryukonesia/src/Ryukonesia.kt | 5 +- .../sektedoujin/src/SekteDoujin.kt | 5 +- .../mangathemesia/sheamanga/src/SheaManga.kt | 5 +- .../silencescan/src/SilenceScan.kt | 4 +- .../src/TsundokuTraducoes.kt | 2 +- .../mangathemesia/westmanga/src/WestManga.kt | 5 +- .../xcalibrscans/src/xCaliBRScans.kt | 5 +- .../tachiyomi/multisrc/madara/Madara.kt | 172 ++---------------- .../multisrc/madara/MadaraGenerator.kt | 2 +- .../tachiyomi/multisrc/mangahub/MangaHub.kt | 40 +--- .../multisrc/mangahub/MangaHubGenerator.kt | 2 +- .../multisrc/mangathemesia/MangaThemesia.kt | 159 ++-------------- .../mangathemesia/MangaThemesiaGenerator.kt | 2 +- settings.gradle.kts | 8 +- src/all/nhentai/build.gradle | 6 +- .../extension/all/nhentai/NHentai.kt | 24 +-- 76 files changed, 370 insertions(+), 563 deletions(-) create mode 100644 lib/randomua/build.gradle.kts create mode 100644 lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentInterceptor.kt create mode 100644 lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentPreference.kt delete mode 100644 multisrc/overrides/madara/anisamanga/src/AnisaManga.kt create mode 100644 multisrc/overrides/mangahub/default/additional.gradle create mode 100644 multisrc/overrides/mangathemesia/default/additional.gradle diff --git a/lib/randomua/build.gradle.kts b/lib/randomua/build.gradle.kts new file mode 100644 index 000000000..5c46699c4 --- /dev/null +++ b/lib/randomua/build.gradle.kts @@ -0,0 +1,23 @@ +plugins { + id("com.android.library") + kotlin("android") + id("kotlinx-serialization") +} + +android { + compileSdk = AndroidConfig.compileSdk + namespace = "eu.kanade.tachiyomi.lib.randomua" + + defaultConfig { + minSdk = AndroidConfig.minSdk + targetSdk = AndroidConfig.targetSdk + } +} + +repositories { + mavenCentral() +} + +dependencies { + compileOnly(libs.bundles.common) +} diff --git a/lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentInterceptor.kt b/lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentInterceptor.kt new file mode 100644 index 000000000..0d36add8a --- /dev/null +++ b/lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentInterceptor.kt @@ -0,0 +1,121 @@ +package eu.kanade.tachiyomi.lib.randomua + +import eu.kanade.tachiyomi.network.GET +import eu.kanade.tachiyomi.network.NetworkHelper +import kotlinx.serialization.Serializable +import kotlinx.serialization.decodeFromString +import kotlinx.serialization.json.Json +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import okhttp3.Response +import uy.kohesive.injekt.injectLazy +import java.io.IOException + +private class RandomUserAgentInterceptor( + private val userAgentType: UserAgentType, + private val customUA: String?, + private val filterInclude: List, + private val filterExclude: List, +) : Interceptor { + + private var userAgent: String? = null + + private val json: Json by injectLazy() + + private val network: NetworkHelper by injectLazy() + + private val client = network.client + + override fun intercept(chain: Interceptor.Chain): Response { + try { + val originalRequest = chain.request() + + val newUserAgent = getUserAgent() + ?: return chain.proceed(originalRequest) + + val originalHeaders = originalRequest.headers + + val modifiedHeaders = originalHeaders.newBuilder() + .set("User-Agent", newUserAgent) + .build() + + return chain.proceed( + originalRequest.newBuilder() + .headers(modifiedHeaders) + .build() + ) + } catch (e: Exception) { + throw IOException(e.message) + } + } + + private fun getUserAgent(): String? { + if (userAgentType == UserAgentType.OFF) { + return customUA?.ifBlank { null } + } + + if (!userAgent.isNullOrEmpty()) return userAgent + + val uaResponse = client.newCall(GET(UA_DB_URL)).execute() + + if (!uaResponse.isSuccessful) { + uaResponse.close() + return null + } + + val userAgentList = uaResponse.use { json.decodeFromString(it.body.string()) } + + return when (userAgentType) { + UserAgentType.DESKTOP -> userAgentList.desktop + UserAgentType.MOBILE -> userAgentList.mobile + else -> error("Expected UserAgentType.DESKTOP or UserAgentType.MOBILE but got UserAgentType.${userAgentType.name} instead") + } + .filter { + filterInclude.isEmpty() || filterInclude.any { filter -> + it.contains(filter, ignoreCase = true) + } + } + .filterNot { + filterExclude.any { filter -> + it.contains(filter, ignoreCase = true) + } + } + .randomOrNull() + .also { userAgent = it } + } + + companion object { + private const val UA_DB_URL = "https://tachiyomiorg.github.io/user-agents/user-agents.json" + } +} + +/** + * Helper function to add a latest random user agent interceptor. + * The interceptor will added at the first position in the chain, + * so the CloudflareInterceptor in the app will be able to make usage of it. + * + * @param userAgentType User Agent type one of (DESKTOP, MOBILE, OFF) + * @param customUA Optional custom user agent used when userAgentType is OFF + * @param filterInclude Filter to only include User Agents containing these strings + * @param filterExclude Filter to exclude User Agents containing these strings + */ +fun OkHttpClient.Builder.setRandomUserAgent( + userAgentType: UserAgentType, + customUA: String? = null, + filterInclude: List = emptyList(), + filterExclude: List = emptyList(), +) = apply { + interceptors().add(0, RandomUserAgentInterceptor(userAgentType, customUA, filterInclude, filterExclude)) +} + +enum class UserAgentType { + MOBILE, + DESKTOP, + OFF +} + +@Serializable +private data class UserAgentList( + val desktop: List, + val mobile: List +) diff --git a/lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentPreference.kt b/lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentPreference.kt new file mode 100644 index 000000000..931209ebd --- /dev/null +++ b/lib/randomua/src/main/java/eu/kanade/tachiyomi/lib/randomua/RandomUserAgentPreference.kt @@ -0,0 +1,83 @@ +package eu.kanade.tachiyomi.lib.randomua + +import android.content.SharedPreferences +import android.widget.Toast +import androidx.preference.EditTextPreference +import androidx.preference.ListPreference +import androidx.preference.PreferenceScreen +import okhttp3.Headers + +class RandomUserAgentPreference( + private val preferences: SharedPreferences, +) { + /** + * Helper function to return UserAgentType based on SharedPreference value + */ + fun getPrefUAType(): UserAgentType { + return when (preferences.getString(PREF_KEY_RANDOM_UA, "off")) { + "mobile" -> UserAgentType.MOBILE + "desktop" -> UserAgentType.DESKTOP + else -> UserAgentType.OFF + } + } + + /** + * Helper function to return custom UserAgent from SharedPreference + */ + fun getPrefCustomUA(): String? { + return preferences.getString(PREF_KEY_CUSTOM_UA, null) + } + + /** + * Helper function to add Random User-Agent settings to SharedPreference + * + * @param screen, PreferenceScreen from `setupPreferenceScreen` + */ + fun addPreferenceToScreen( + screen: PreferenceScreen, + ) { + val customUA = EditTextPreference(screen.context).apply { + key = PREF_KEY_CUSTOM_UA + title = TITLE_CUSTOM_UA + summary = CUSTOM_UA_SUMMARY + setVisible(getPrefUAType() == UserAgentType.OFF) + setOnPreferenceChangeListener { _, newValue -> + try { + Headers.Builder().add("User-Agent", newValue as String).build() + true + } catch (e: IllegalArgumentException) { + Toast.makeText(screen.context, "User Agent invalid:${e.message}", Toast.LENGTH_LONG).show() + false + } + } + } + + val randomUA = ListPreference(screen.context).apply { + key = PREF_KEY_RANDOM_UA + title = TITLE_RANDOM_UA + entries = RANDOM_UA_ENTRIES + entryValues = RANDOM_UA_VALUES + summary = "%s" + setDefaultValue("off") + setOnPreferenceChangeListener { _, newVal -> + val showCustomUAPref = newVal as String == "off" + customUA.setVisible(showCustomUAPref) + true + } + } + + screen.addPreference(randomUA) + screen.addPreference(customUA) + } + + companion object { + const val TITLE_RANDOM_UA = "Random User-Agent (Requires Restart)" + const val PREF_KEY_RANDOM_UA = "pref_key_random_ua_" + val RANDOM_UA_ENTRIES = arrayOf("OFF", "Desktop", "Mobile") + val RANDOM_UA_VALUES = arrayOf("off", "desktop", "mobile") + + const val TITLE_CUSTOM_UA = "Custom User-Agent" + const val PREF_KEY_CUSTOM_UA = "pref_key_custom_ua_" + const val CUSTOM_UA_SUMMARY = "Leave blank to use application default user-agent. (Requires Restart)" + } +} diff --git a/multisrc/overrides/madara/anisamanga/src/AnisaManga.kt b/multisrc/overrides/madara/anisamanga/src/AnisaManga.kt deleted file mode 100644 index eaa2547ca..000000000 --- a/multisrc/overrides/madara/anisamanga/src/AnisaManga.kt +++ /dev/null @@ -1,9 +0,0 @@ -package eu.kanade.tachiyomi.extension.tr.anisamanga - -import eu.kanade.tachiyomi.multisrc.madara.Madara -import okhttp3.Headers - -class AnisaManga : Madara("Anisa Manga", "https://anisamanga.com", "tr") { - override fun headersBuilder(): Headers.Builder = super.headersBuilder() - .add("Referer", "https://anisamanga.com") -} diff --git a/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt b/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt index f45bd0d4b..4e0443609 100644 --- a/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt +++ b/multisrc/overrides/madara/bokugentranslation/src/BokugenTranslation.kt @@ -14,7 +14,6 @@ import uy.kohesive.injekt.api.get import java.text.SimpleDateFormat import java.util.Locale import java.util.concurrent.CountDownLatch -import java.util.concurrent.TimeUnit class BokugenTranslation : Madara( "BokugenTranslation", @@ -23,8 +22,7 @@ class BokugenTranslation : Madara( dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("es")), ) { private var loadWebView = true - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .addInterceptor(uaIntercept) + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor { chain -> val request = chain.request() val url = request.url.toString() @@ -56,8 +54,6 @@ class BokugenTranslation : Madara( } chain.proceed(request) } - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) .rateLimit(1, 1) .build() diff --git a/multisrc/overrides/madara/default/additional.gradle b/multisrc/overrides/madara/default/additional.gradle index 06abd18c6..214a0df0e 100644 --- a/multisrc/overrides/madara/default/additional.gradle +++ b/multisrc/overrides/madara/default/additional.gradle @@ -1,3 +1,4 @@ dependencies { - implementation(project(':lib-cryptoaes')) -} \ No newline at end of file + implementation(project(":lib-cryptoaes")) + implementation(project(":lib-randomua")) +} diff --git a/multisrc/overrides/madara/doodmanga/src/Doodmanga.kt b/multisrc/overrides/madara/doodmanga/src/Doodmanga.kt index 232fdfd2a..682f5c672 100644 --- a/multisrc/overrides/madara/doodmanga/src/Doodmanga.kt +++ b/multisrc/overrides/madara/doodmanga/src/Doodmanga.kt @@ -7,16 +7,12 @@ import okhttp3.OkHttpClient import org.jsoup.nodes.Document import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit class Doodmanga : Madara("Doodmanga", "https://www.doodmanga.com", "th", SimpleDateFormat("dd MMMMM yyyy", Locale("th"))) { override val filterNonMangaItems = false - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .addInterceptor(uaIntercept) + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(ScrambledImageInterceptor) - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) .build() override val pageListParseSelector = "div.text-center > p > img, div.text-center > img, div.text-center > script" diff --git a/multisrc/overrides/madara/firstkissmanga/src/FirstKissManga.kt b/multisrc/overrides/madara/firstkissmanga/src/FirstKissManga.kt index c8c6887ff..c170b72bc 100644 --- a/multisrc/overrides/madara/firstkissmanga/src/FirstKissManga.kt +++ b/multisrc/overrides/madara/firstkissmanga/src/FirstKissManga.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.extension.en.firstkissmanga import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit -import okhttp3.Headers import java.util.concurrent.TimeUnit class FirstKissManga : Madara( @@ -10,9 +9,7 @@ class FirstKissManga : Madara( "https://1stkissmanga.me", "en", ) { - override fun headersBuilder(): Headers.Builder = super.headersBuilder().add("Referer", baseUrl) - - override val client = network.cloudflareClient.newBuilder() + override val client = super.client.newBuilder() .rateLimit(1, 3, TimeUnit.SECONDS) .build() } diff --git a/multisrc/overrides/madara/firstkissmangaclub/src/FirstKissMangaClub.kt b/multisrc/overrides/madara/firstkissmangaclub/src/FirstKissMangaClub.kt index 71b2e1916..1f9e3d3b8 100644 --- a/multisrc/overrides/madara/firstkissmangaclub/src/FirstKissMangaClub.kt +++ b/multisrc/overrides/madara/firstkissmangaclub/src/FirstKissMangaClub.kt @@ -10,7 +10,7 @@ class FirstKissMangaClub : Madara( "en", ) { - override val client = network.cloudflareClient.newBuilder() + override val client = super.client.newBuilder() .rateLimit(1, 3, TimeUnit.SECONDS) .build() } diff --git a/multisrc/overrides/madara/firstkissmangalove/src/FirstKissMangaLove.kt b/multisrc/overrides/madara/firstkissmangalove/src/FirstKissMangaLove.kt index 3e4ce1588..d121332e3 100644 --- a/multisrc/overrides/madara/firstkissmangalove/src/FirstKissMangaLove.kt +++ b/multisrc/overrides/madara/firstkissmangalove/src/FirstKissMangaLove.kt @@ -10,7 +10,7 @@ class FirstKissMangaLove : Madara( "en", ) { - override val client = network.cloudflareClient.newBuilder() + override val client = super.client.newBuilder() .rateLimit(1, 3, TimeUnit.SECONDS) .build() } diff --git a/multisrc/overrides/madara/firstkissmanhua/src/FirstKissManhua.kt b/multisrc/overrides/madara/firstkissmanhua/src/FirstKissManhua.kt index 9afdeb94f..728bdbb66 100644 --- a/multisrc/overrides/madara/firstkissmanhua/src/FirstKissManhua.kt +++ b/multisrc/overrides/madara/firstkissmanhua/src/FirstKissManhua.kt @@ -16,7 +16,7 @@ class FirstKissManhua : Madara( SimpleDateFormat("d MMM yyyy", Locale.US), ) { - override val client = network.cloudflareClient.newBuilder() + override val client = super.client.newBuilder() .rateLimit(1, 3, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/madara/fleurblanche/src/FleurBlanche.kt b/multisrc/overrides/madara/fleurblanche/src/FleurBlanche.kt index 5f3635289..336d6c8a5 100644 --- a/multisrc/overrides/madara/fleurblanche/src/FleurBlanche.kt +++ b/multisrc/overrides/madara/fleurblanche/src/FleurBlanche.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.extension.pt.fleurblanche import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit -import okhttp3.Headers import okhttp3.Interceptor import okhttp3.OkHttpClient import okhttp3.Response @@ -25,8 +24,6 @@ class FleurBlanche : Madara( override val useNewChapterEndpoint = true - override fun headersBuilder(): Headers.Builder = Headers.Builder() - private fun authWarningIntercept(chain: Interceptor.Chain): Response { val response = chain.proceed(chain.request()) diff --git a/multisrc/overrides/madara/hentaiteca/src/HentaiTeca.kt b/multisrc/overrides/madara/hentaiteca/src/HentaiTeca.kt index 5689d18f5..f63de0c24 100644 --- a/multisrc/overrides/madara/hentaiteca/src/HentaiTeca.kt +++ b/multisrc/overrides/madara/hentaiteca/src/HentaiTeca.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.extension.pt.hentaiteca import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit -import okhttp3.Headers import okhttp3.OkHttpClient import java.text.SimpleDateFormat import java.util.Locale @@ -18,7 +17,4 @@ class HentaiTeca : Madara( override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() - - override fun headersBuilder(): Headers.Builder = Headers.Builder() - .add("Referer", "$baseUrl/") } diff --git a/multisrc/overrides/madara/ichirinnohanayuri/src/IchirinNoHanaYuri.kt b/multisrc/overrides/madara/ichirinnohanayuri/src/IchirinNoHanaYuri.kt index 9c5987f09..140ed31f7 100644 --- a/multisrc/overrides/madara/ichirinnohanayuri/src/IchirinNoHanaYuri.kt +++ b/multisrc/overrides/madara/ichirinnohanayuri/src/IchirinNoHanaYuri.kt @@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.extension.pt.ichirinnohanayuri import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit -import okhttp3.Headers import okhttp3.OkHttpClient import java.io.IOException import java.text.SimpleDateFormat @@ -30,8 +29,6 @@ class IchirinNoHanaYuri : Madara( } .build() - override fun headersBuilder(): Headers.Builder = Headers.Builder() - companion object { private const val BLOCKING_MESSAGE = "O site está bloqueando o Tachiyomi. " + "Migre para outra fonte caso o problema persistir." diff --git a/multisrc/overrides/madara/manga18fx/src/Manga18fx.kt b/multisrc/overrides/madara/manga18fx/src/Manga18fx.kt index 43592535d..87c54b9ea 100644 --- a/multisrc/overrides/madara/manga18fx/src/Manga18fx.kt +++ b/multisrc/overrides/madara/manga18fx/src/Manga18fx.kt @@ -26,8 +26,6 @@ class Manga18fx : Madara( ) { override val id = 3157287889751723714 - override val client = network.client - override val fetchGenres = false override val sendViewCount = false diff --git a/multisrc/overrides/madara/mangastarz/src/MangaStarz.kt b/multisrc/overrides/madara/mangastarz/src/MangaStarz.kt index 330b4c595..e084ed8fd 100644 --- a/multisrc/overrides/madara/mangastarz/src/MangaStarz.kt +++ b/multisrc/overrides/madara/mangastarz/src/MangaStarz.kt @@ -2,14 +2,10 @@ package eu.kanade.tachiyomi.extension.ar.mangastarz import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.source.model.SManga -import okhttp3.Headers import org.jsoup.nodes.Element class MangaStarz : Madara("Manga Starz", "https://mangastarz.com", "ar") { - override fun headersBuilder(): Headers.Builder = Headers.Builder() - .add("Referer", baseUrl) - override fun popularMangaFromElement(element: Element): SManga { val manga = SManga.create() diff --git a/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt b/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt index f10b60c7e..9e8ddf99d 100644 --- a/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt +++ b/multisrc/overrides/madara/manhuaga/src/Manhuaga.kt @@ -2,12 +2,9 @@ package eu.kanade.tachiyomi.extension.en.manhuaga import eu.kanade.tachiyomi.multisrc.madara.Madara import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Manhuaga : Madara("Manhuaga", "https://manhuaga.com", "en") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor { chain -> val originalRequest = chain.request() chain.proceed(originalRequest).let { response -> diff --git a/multisrc/overrides/madara/mixedmanga/src/MixedManga.kt b/multisrc/overrides/madara/mixedmanga/src/MixedManga.kt index 13c9f8934..136b989af 100644 --- a/multisrc/overrides/madara/mixedmanga/src/MixedManga.kt +++ b/multisrc/overrides/madara/mixedmanga/src/MixedManga.kt @@ -1,10 +1,7 @@ package eu.kanade.tachiyomi.extension.en.mixedmanga import eu.kanade.tachiyomi.multisrc.madara.Madara -import okhttp3.Headers import java.text.SimpleDateFormat import java.util.Locale -class MixedManga : Madara("Mixed Manga", "https://mixedmanga.com", "en", SimpleDateFormat("d MMM yyyy", Locale.US)) { - override fun headersBuilder(): Headers.Builder = super.headersBuilder().add("Referer", baseUrl) -} +class MixedManga : Madara("Mixed Manga", "https://mixedmanga.com", "en", SimpleDateFormat("d MMM yyyy", Locale.US)) diff --git a/multisrc/overrides/madara/shieldmanga/src/ShieldManga.kt b/multisrc/overrides/madara/shieldmanga/src/ShieldManga.kt index 6aa6a9ef9..e33716ae3 100644 --- a/multisrc/overrides/madara/shieldmanga/src/ShieldManga.kt +++ b/multisrc/overrides/madara/shieldmanga/src/ShieldManga.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.en.shieldmanga import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class ShieldManga : Madara("Shield Manga", "https://shieldmanga.io", "en") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1) .build() diff --git a/multisrc/overrides/madara/topmanhua/src/TopManhua.kt b/multisrc/overrides/madara/topmanhua/src/TopManhua.kt index c27d6e19c..4a8b4a366 100644 --- a/multisrc/overrides/madara/topmanhua/src/TopManhua.kt +++ b/multisrc/overrides/madara/topmanhua/src/TopManhua.kt @@ -1,13 +1,10 @@ package eu.kanade.tachiyomi.extension.en.topmanhua import eu.kanade.tachiyomi.multisrc.madara.Madara -import okhttp3.Headers import java.text.SimpleDateFormat import java.util.Locale class TopManhua : Madara("Top Manhua", "https://topmanhua.com", "en", SimpleDateFormat("MM/dd/yy", Locale.US)) { - override fun headersBuilder(): Headers.Builder = super.headersBuilder().add("Referer", baseUrl) - // The website does not flag the content. override val filterNonMangaItems = false } diff --git a/multisrc/overrides/madara/yanpfansub/src/YANPFansub.kt b/multisrc/overrides/madara/yanpfansub/src/YANPFansub.kt index 1963f693f..6b468f1ef 100644 --- a/multisrc/overrides/madara/yanpfansub/src/YANPFansub.kt +++ b/multisrc/overrides/madara/yanpfansub/src/YANPFansub.kt @@ -20,7 +20,7 @@ class YANPFansub : Madara( // Scanlator changed the theme from WpMangaReader to Madara. override val versionId: Int = 2 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .addInterceptor(::checkPasswordProtectedIntercept) .build() diff --git a/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt b/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt index 5855a24f7..cb76122da 100644 --- a/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt +++ b/multisrc/overrides/madara/yaoitoshokan/src/YaoiToshokan.kt @@ -4,7 +4,6 @@ import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.source.model.Page -import okhttp3.Headers import okhttp3.OkHttpClient import okhttp3.Request import org.jsoup.nodes.Document @@ -19,10 +18,7 @@ class YaoiToshokan : Madara( SimpleDateFormat("dd MMM yyyy", Locale("pt", "BR")), ) { - override fun headersBuilder(): Headers.Builder = super.headersBuilder() - .removeAll("User-Agent") - - override val client: OkHttpClient = network.client.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/madara/yugenmangas/src/YugenMangas.kt b/multisrc/overrides/madara/yugenmangas/src/YugenMangas.kt index dc62d586a..0163cc160 100644 --- a/multisrc/overrides/madara/yugenmangas/src/YugenMangas.kt +++ b/multisrc/overrides/madara/yugenmangas/src/YugenMangas.kt @@ -1,9 +1,11 @@ package eu.kanade.tachiyomi.extension.pt.yugenmangas +import androidx.preference.PreferenceScreen +import eu.kanade.tachiyomi.lib.randomua.UserAgentType +import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent import eu.kanade.tachiyomi.multisrc.madara.Madara import eu.kanade.tachiyomi.network.interceptor.rateLimit import eu.kanade.tachiyomi.source.model.SChapter -import okhttp3.Headers import okhttp3.OkHttpClient import org.jsoup.nodes.Element import java.text.SimpleDateFormat @@ -17,14 +19,17 @@ class YugenMangas : Madara( SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")), ) { - override val client: OkHttpClient = super.client.newBuilder() - .addInterceptor(uaIntercept) + override val client: OkHttpClient = network.cloudflareClient.newBuilder() + .setRandomUserAgent( + UserAgentType.DESKTOP, + ) + .connectTimeout(10, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) .rateLimit(1, 3, TimeUnit.SECONDS) .build() - override fun headersBuilder(): Headers.Builder = Headers.Builder() + override fun headersBuilder() = super.headersBuilder() .add("Origin", baseUrl) - .add("Referer", "$baseUrl/") override val useNewChapterEndpoint: Boolean = true @@ -41,5 +46,5 @@ class YugenMangas : Madara( ) } - override val useRandomUserAgentByDefault: Boolean = true + override fun setupPreferenceScreen(screen: PreferenceScreen) { } } diff --git a/multisrc/overrides/mangahub/default/additional.gradle b/multisrc/overrides/mangahub/default/additional.gradle new file mode 100644 index 000000000..57807a7d0 --- /dev/null +++ b/multisrc/overrides/mangahub/default/additional.gradle @@ -0,0 +1,3 @@ +dependencies { + implementation(project(":lib-randomua")) +} diff --git a/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansEn.kt b/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansEn.kt index c9b473d19..19308ecee 100644 --- a/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansEn.kt +++ b/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansEn.kt @@ -35,11 +35,8 @@ class AsuraScansEn : MangaThemesia( private val preferences = Injekt.get().getSharedPreferences("source_$id", 0x0000) - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(::urlChangeInterceptor) - .addInterceptor(uaIntercept) - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) .rateLimit(1, 3, TimeUnit.SECONDS) .build() @@ -232,7 +229,7 @@ class AsuraScansEn : MangaThemesia( setDefaultValue(true) }.also(screen::addPreference) - addRandomAndCustomUserAgentPreferences(screen) + super.setupPreferenceScreen(screen) } private val SharedPreferences.permaUrlPref diff --git a/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansTr.kt b/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansTr.kt index 433569bf3..6a0365439 100644 --- a/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansTr.kt +++ b/multisrc/overrides/mangathemesia/asurascans/src/AsuraScansTr.kt @@ -19,10 +19,7 @@ class AsuraScansTr : MangaThemesia( "tr", dateFormat = SimpleDateFormat("MMM d, yyyy", Locale("tr")), ) { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .addInterceptor(uaIntercept) - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 3, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/mangathemesia/boosei/src/Boosei.kt b/multisrc/overrides/mangathemesia/boosei/src/Boosei.kt index 20a9a4989..33d0a6169 100644 --- a/multisrc/overrides/mangathemesia/boosei/src/Boosei.kt +++ b/multisrc/overrides/mangathemesia/boosei/src/Boosei.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.boosei import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Boosei : MangaThemesia("Boosei", "https://boosei.net", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt b/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt index 7e96a214d..888a2c78b 100644 --- a/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt +++ b/multisrc/overrides/mangathemesia/constellarscans/src/ConstellarScans.kt @@ -10,6 +10,7 @@ import android.webkit.ConsoleMessage import android.webkit.JavascriptInterface import android.webkit.WebChromeClient import android.webkit.WebView +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.lib.dataimage.DataImageInterceptor import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.GET @@ -149,6 +150,8 @@ class ConstellarScans : MangaThemesia("Constellar Scans", "https://constellarsca .header("Sec-Fetch-Site", "same-origin") .build() + override fun setupPreferenceScreen(screen: PreferenceScreen) { } + companion object { const val UA_DB_URL = "https://cdn.jsdelivr.net/gh/mimmi20/browscap-helper@30a83c095688f40b9eaca0165a479c661e5a7fbe/tests/0002999.json" diff --git a/multisrc/overrides/mangathemesia/default/additional.gradle b/multisrc/overrides/mangathemesia/default/additional.gradle new file mode 100644 index 000000000..57807a7d0 --- /dev/null +++ b/multisrc/overrides/mangathemesia/default/additional.gradle @@ -0,0 +1,3 @@ +dependencies { + implementation(project(":lib-randomua")) +} diff --git a/multisrc/overrides/mangathemesia/dojingnet/src/DojingNet.kt b/multisrc/overrides/mangathemesia/dojingnet/src/DojingNet.kt index bd326bbf5..60e000315 100644 --- a/multisrc/overrides/mangathemesia/dojingnet/src/DojingNet.kt +++ b/multisrc/overrides/mangathemesia/dojingnet/src/DojingNet.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.dojingnet import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class DojingNet : MangaThemesia("Dojing.net", "https://dojing.net", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/flamescans/src/FlameScans.kt b/multisrc/overrides/mangathemesia/flamescans/src/FlameScans.kt index a36616de8..50e78b8aa 100644 --- a/multisrc/overrides/mangathemesia/flamescans/src/FlameScans.kt +++ b/multisrc/overrides/mangathemesia/flamescans/src/FlameScans.kt @@ -28,7 +28,6 @@ import uy.kohesive.injekt.api.get import java.io.ByteArrayOutputStream import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit open class FlameScans( override val baseUrl: String, @@ -48,9 +47,7 @@ open class FlameScans( Injekt.get().getSharedPreferences("source_$id", 0x0000) } - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(::composedImageIntercept) .build() diff --git a/multisrc/overrides/mangathemesia/franxxmangas/src/FranxxMangas.kt b/multisrc/overrides/mangathemesia/franxxmangas/src/FranxxMangas.kt index 1c5733419..1baec64a9 100644 --- a/multisrc/overrides/mangathemesia/franxxmangas/src/FranxxMangas.kt +++ b/multisrc/overrides/mangathemesia/franxxmangas/src/FranxxMangas.kt @@ -14,7 +14,7 @@ class FranxxMangas : MangaThemesia( dateFormat = SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")), ) { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/mangathemesia/kiryuu/src/Kiryuu.kt b/multisrc/overrides/mangathemesia/kiryuu/src/Kiryuu.kt index 74d2c613a..1d5df8691 100644 --- a/multisrc/overrides/mangathemesia/kiryuu/src/Kiryuu.kt +++ b/multisrc/overrides/mangathemesia/kiryuu/src/Kiryuu.kt @@ -6,15 +6,12 @@ import okhttp3.OkHttpClient import org.jsoup.nodes.Document import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit class Kiryuu : MangaThemesia("Kiryuu", "https://kiryuu.id", "id", dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale("id"))) { // Formerly "Kiryuu (WP Manga Stream)" override val id = 3639673976007021338 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/komikav/src/KomikAV.kt b/multisrc/overrides/mangathemesia/komikav/src/KomikAV.kt index c2c577036..1802c3398 100644 --- a/multisrc/overrides/mangathemesia/komikav/src/KomikAV.kt +++ b/multisrc/overrides/mangathemesia/komikav/src/KomikAV.kt @@ -8,7 +8,6 @@ import okhttp3.OkHttpClient import okhttp3.Request import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit class KomikAV : MangaThemesia( "Komik AV (WP Manga Stream)", @@ -19,9 +18,7 @@ class KomikAV : MangaThemesia( // Formerly "Komik AV (WP Manga Stream)" override val id = 7875815514004535629 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/komikcast/src/KomikCast.kt b/multisrc/overrides/mangathemesia/komikcast/src/KomikCast.kt index 7a0fbdd21..02d9eed2a 100644 --- a/multisrc/overrides/mangathemesia/komikcast/src/KomikCast.kt +++ b/multisrc/overrides/mangathemesia/komikcast/src/KomikCast.kt @@ -17,7 +17,6 @@ import org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.nodes.Element import java.util.Calendar -import java.util.concurrent.TimeUnit class KomikCast : MangaThemesia( "Komik Cast", @@ -28,13 +27,11 @@ class KomikCast : MangaThemesia( // Formerly "Komik Cast (WP Manga Stream)" override val id = 972717448578983812 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(3) .build() - override fun headersBuilder(): Headers.Builder = Headers.Builder() + override fun headersBuilder(): Headers.Builder = super.headersBuilder() .add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9") .add("Accept-language", "en-US,en;q=0.9,id;q=0.8") .add("Referer", baseUrl) @@ -76,7 +73,7 @@ class KomikCast : MangaThemesia( override fun chapterFromElement(element: Element) = SChapter.create().apply { val urlElements = element.select("a") setUrlWithoutDomain(urlElements.attr("href")) - name = element.select(".lch a, .chapternum")!!.text().ifBlank { urlElements.first()!!.text() } + name = element.select(".lch a, .chapternum").text().ifBlank { urlElements.first()!!.text() } date_upload = parseChapterDate2(element.select(".chapter-link-time").text()) } diff --git a/multisrc/overrides/mangathemesia/komikdewasa/src/KomikDewasa.kt b/multisrc/overrides/mangathemesia/komikdewasa/src/KomikDewasa.kt index 98380340d..75b799fdd 100644 --- a/multisrc/overrides/mangathemesia/komikdewasa/src/KomikDewasa.kt +++ b/multisrc/overrides/mangathemesia/komikdewasa/src/KomikDewasa.kt @@ -3,12 +3,9 @@ package eu.kanade.tachiyomi.extension.id.komikdewasa import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class KomikDewasa : MangaThemesia("KomikDewasa", "https://komikdewasa.org", "id", "/komik") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/komikindoco/src/KomikindoCo.kt b/multisrc/overrides/mangathemesia/komikindoco/src/KomikindoCo.kt index 9a6c96240..1744757e7 100644 --- a/multisrc/overrides/mangathemesia/komikindoco/src/KomikindoCo.kt +++ b/multisrc/overrides/mangathemesia/komikindoco/src/KomikindoCo.kt @@ -5,15 +5,12 @@ import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit class KomikindoCo : MangaThemesia("KomikIndo.co", "https://komikindo.co", "id", dateFormat = SimpleDateFormat("MMM dd, yyyy", Locale("id"))) { // Formerly "Komikindo.co" override val id = 734619124437406170 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/komikmanhwa/src/KomikManhwa.kt b/multisrc/overrides/mangathemesia/komikmanhwa/src/KomikManhwa.kt index 65105ec82..bfd0fc6e1 100644 --- a/multisrc/overrides/mangathemesia/komikmanhwa/src/KomikManhwa.kt +++ b/multisrc/overrides/mangathemesia/komikmanhwa/src/KomikManhwa.kt @@ -3,12 +3,9 @@ package eu.kanade.tachiyomi.extension.id.komikmanhwa import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class KomikManhwa : MangaThemesia("KomikManhwa", "https://komikmanhwa.me", "id", "/series") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() } diff --git a/multisrc/overrides/mangathemesia/komikstation/src/KomikStation.kt b/multisrc/overrides/mangathemesia/komikstation/src/KomikStation.kt index 51437f642..44c0c8244 100644 --- a/multisrc/overrides/mangathemesia/komikstation/src/KomikStation.kt +++ b/multisrc/overrides/mangathemesia/komikstation/src/KomikStation.kt @@ -3,15 +3,12 @@ package eu.kanade.tachiyomi.extension.id.komikstation import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class KomikStation : MangaThemesia("Komik Station", "https://komikstation.co", "id") { // Formerly "Komik Station (WP Manga Stream)" override val id = 6148605743576635261 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/kumapoi/src/KumaPoi.kt b/multisrc/overrides/mangathemesia/kumapoi/src/KumaPoi.kt index 316d091b7..3ddba7cc5 100644 --- a/multisrc/overrides/mangathemesia/kumapoi/src/KumaPoi.kt +++ b/multisrc/overrides/mangathemesia/kumapoi/src/KumaPoi.kt @@ -3,12 +3,9 @@ package eu.kanade.tachiyomi.extension.id.kumapoi import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class KumaPoi : MangaThemesia("KumaPoi", "https://kumapoi.club", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/kumascans/src/KumaScans.kt b/multisrc/overrides/mangathemesia/kumascans/src/KumaScans.kt index 4a0bde580..2c2bdf41c 100644 --- a/multisrc/overrides/mangathemesia/kumascans/src/KumaScans.kt +++ b/multisrc/overrides/mangathemesia/kumascans/src/KumaScans.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.en.kumascans import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class KumaScans : MangaThemesia("Kuma Scans (Kuma Translation)", "https://kumascans.com", "en") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/lianscans/src/LianScans.kt b/multisrc/overrides/mangathemesia/lianscans/src/LianScans.kt index 3b6a2a119..7bdb98e22 100644 --- a/multisrc/overrides/mangathemesia/lianscans/src/LianScans.kt +++ b/multisrc/overrides/mangathemesia/lianscans/src/LianScans.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.lianscans import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class LianScans : MangaThemesia("LianScans", "https://www.lianscans.my.id", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/mangakyo/src/Mangakyo.kt b/multisrc/overrides/mangathemesia/mangakyo/src/Mangakyo.kt index 1bf4ea3d8..8b41ea82c 100644 --- a/multisrc/overrides/mangathemesia/mangakyo/src/Mangakyo.kt +++ b/multisrc/overrides/mangathemesia/mangakyo/src/Mangakyo.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.mangakyo import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Mangakyo : MangaThemesia("Mangakyo", "https://mangakyo.id", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/mangaraworg/src/MangaRawOrg.kt b/multisrc/overrides/mangathemesia/mangaraworg/src/MangaRawOrg.kt index 224359a25..4cfed65b6 100644 --- a/multisrc/overrides/mangathemesia/mangaraworg/src/MangaRawOrg.kt +++ b/multisrc/overrides/mangathemesia/mangaraworg/src/MangaRawOrg.kt @@ -15,14 +15,11 @@ import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element import rx.Observable -import java.util.concurrent.TimeUnit class MangaRawOrg : MangaThemesia("Manga Raw.org", "https://mangaraw.org", "ja") { override val id = 6223520752496636410 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt b/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt index 20823174d..69c3cf5b8 100644 --- a/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt +++ b/multisrc/overrides/mangathemesia/mangaschan/src/MangasChan.kt @@ -14,7 +14,7 @@ class MangasChan : MangaThemesia( dateFormat = SimpleDateFormat("MMMMM dd, yyyy", Locale("pt", "BR")), ) { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/mangathemesia/mangayaro/src/Mangayaro.kt b/multisrc/overrides/mangathemesia/mangayaro/src/Mangayaro.kt index 34fd4e158..c0bcefb4a 100644 --- a/multisrc/overrides/mangathemesia/mangayaro/src/Mangayaro.kt +++ b/multisrc/overrides/mangathemesia/mangayaro/src/Mangayaro.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.mangayaro import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Mangayaro : MangaThemesia("Mangayaro", "https://mangayaro.net", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() } diff --git a/multisrc/overrides/mangathemesia/mangceh/src/Mareceh.kt b/multisrc/overrides/mangathemesia/mangceh/src/Mareceh.kt index 891845d19..8af860434 100644 --- a/multisrc/overrides/mangathemesia/mangceh/src/Mareceh.kt +++ b/multisrc/overrides/mangathemesia/mangceh/src/Mareceh.kt @@ -3,15 +3,12 @@ package eu.kanade.tachiyomi.extension.id.mangceh import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Mareceh : MangaThemesia("Mareceh", "https://mareceh.com", "id") { override val versionId = 2 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/mangkomik/src/MangKomik.kt b/multisrc/overrides/mangathemesia/mangkomik/src/MangKomik.kt index 29181369d..4f067ffbe 100644 --- a/multisrc/overrides/mangathemesia/mangkomik/src/MangKomik.kt +++ b/multisrc/overrides/mangathemesia/mangkomik/src/MangKomik.kt @@ -10,7 +10,7 @@ class MangKomik : MangaThemesia("MangKomik", "https://mangkomik.net", "id") { override fun pageListParse(document: Document): List { // Get external JS for image urls - val scriptEl = document.selectFirst("script[data-minify]")!! + val scriptEl = document.selectFirst("script[data-minify]") val scriptUrl = scriptEl?.attr("src") if (scriptUrl.isNullOrEmpty()) { return super.pageListParse(document) diff --git a/multisrc/overrides/mangathemesia/manhwadesu/src/ManhwaDesu.kt b/multisrc/overrides/mangathemesia/manhwadesu/src/ManhwaDesu.kt index 56c0de275..b6669bb50 100644 --- a/multisrc/overrides/mangathemesia/manhwadesu/src/ManhwaDesu.kt +++ b/multisrc/overrides/mangathemesia/manhwadesu/src/ManhwaDesu.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.manhwadesu import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class ManhwaDesu : MangaThemesia("ManhwaDesu", "https://manhwadesu.org", "id", "/komik") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() } diff --git a/multisrc/overrides/mangathemesia/manhwafreak/src/ManhwaFreak.kt b/multisrc/overrides/mangathemesia/manhwafreak/src/ManhwaFreak.kt index 0ad450efc..c9334e50b 100644 --- a/multisrc/overrides/mangathemesia/manhwafreak/src/ManhwaFreak.kt +++ b/multisrc/overrides/mangathemesia/manhwafreak/src/ManhwaFreak.kt @@ -51,7 +51,7 @@ class ManhwaFreak : MangaThemesia("Manhwa Freak", "https://manhwafreak.com", "en override fun chapterFromElement(element: Element) = SChapter.create().apply { val urlElements = element.select("a") setUrlWithoutDomain(urlElements.attr("href")) - name = element.select(".chapter-info p:nth-child(1)")!!.text().ifBlank { urlElements.first()!!.text() } + name = element.select(".chapter-info p:nth-child(1)").text().ifBlank { urlElements.first()!!.text() } date_upload = element.selectFirst(".chapter-info p:nth-child(2)")?.text().parseChapterDate() } diff --git a/multisrc/overrides/mangathemesia/manhwaindo/src/ManhwaIndo.kt b/multisrc/overrides/mangathemesia/manhwaindo/src/ManhwaIndo.kt index 365a2d8b5..2a6266576 100644 --- a/multisrc/overrides/mangathemesia/manhwaindo/src/ManhwaIndo.kt +++ b/multisrc/overrides/mangathemesia/manhwaindo/src/ManhwaIndo.kt @@ -14,7 +14,7 @@ class ManhwaIndo : MangaThemesia( SimpleDateFormat("MMMM dd, yyyy", Locale("id")), ) { - override fun headersBuilder(): Headers.Builder = Headers.Builder() + override fun headersBuilder(): Headers.Builder = super.headersBuilder() .add("Referer", baseUrl) override fun mangaDetailsParse(document: Document) = super.mangaDetailsParse(document).apply { diff --git a/multisrc/overrides/mangathemesia/manhwalandmom/src/ManhwaLandMom.kt b/multisrc/overrides/mangathemesia/manhwalandmom/src/ManhwaLandMom.kt index fcab46328..5ef7a524f 100644 --- a/multisrc/overrides/mangathemesia/manhwalandmom/src/ManhwaLandMom.kt +++ b/multisrc/overrides/mangathemesia/manhwalandmom/src/ManhwaLandMom.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.manhwalandmom import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class ManhwaLandMom : MangaThemesia("ManhwaLand.mom", "https://manhwaland.us", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() } diff --git a/multisrc/overrides/mangathemesia/manhwalist/src/ManhwaList.kt b/multisrc/overrides/mangathemesia/manhwalist/src/ManhwaList.kt index ba3a8b088..67411c519 100644 --- a/multisrc/overrides/mangathemesia/manhwalist/src/ManhwaList.kt +++ b/multisrc/overrides/mangathemesia/manhwalist/src/ManhwaList.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.manhwalist import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class ManhwaList : MangaThemesia("ManhwaList", "https://manhwalist.xyz", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/masterkomik/src/MasterKomik.kt b/multisrc/overrides/mangathemesia/masterkomik/src/MasterKomik.kt index e9082ffb6..99a2bd887 100644 --- a/multisrc/overrides/mangathemesia/masterkomik/src/MasterKomik.kt +++ b/multisrc/overrides/mangathemesia/masterkomik/src/MasterKomik.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.masterkomik import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class MasterKomik : MangaThemesia("MasterKomik", "https://masterkomik.com", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/mirrordesu/src/MirrorDesu.kt b/multisrc/overrides/mangathemesia/mirrordesu/src/MirrorDesu.kt index c1c007c77..3703c33a2 100644 --- a/multisrc/overrides/mangathemesia/mirrordesu/src/MirrorDesu.kt +++ b/multisrc/overrides/mangathemesia/mirrordesu/src/MirrorDesu.kt @@ -3,12 +3,9 @@ package eu.kanade.tachiyomi.extension.id.mirrordesu import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class MirrorDesu : MangaThemesia("MirrorDesu", "https://mirrordesu.me", "id", "/komik") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/modescanlator/src/ModeScanlator.kt b/multisrc/overrides/mangathemesia/modescanlator/src/ModeScanlator.kt index fc7300559..295f2d6e8 100644 --- a/multisrc/overrides/mangathemesia/modescanlator/src/ModeScanlator.kt +++ b/multisrc/overrides/mangathemesia/modescanlator/src/ModeScanlator.kt @@ -18,7 +18,7 @@ class ModeScanlator : MangaThemesia( // Site changed from Madara to WpMangaReader. override val versionId: Int = 2 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/mangathemesia/nekomik/src/Nekomik.kt b/multisrc/overrides/mangathemesia/nekomik/src/Nekomik.kt index 513409e49..e396c0e02 100644 --- a/multisrc/overrides/mangathemesia/nekomik/src/Nekomik.kt +++ b/multisrc/overrides/mangathemesia/nekomik/src/Nekomik.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.nekomik import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Nekomik : MangaThemesia("Nekomik", "https://nekomik.com", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/origamiorpheans/src/OrigamiOrpheans.kt b/multisrc/overrides/mangathemesia/origamiorpheans/src/OrigamiOrpheans.kt index d437bb177..60c5d5063 100644 --- a/multisrc/overrides/mangathemesia/origamiorpheans/src/OrigamiOrpheans.kt +++ b/multisrc/overrides/mangathemesia/origamiorpheans/src/OrigamiOrpheans.kt @@ -17,7 +17,7 @@ class OrigamiOrpheans : MangaThemesia( // Scanlator migrated from Madara to WpMangaReader. override val versionId = 2 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/mangathemesia/rawkuma/src/Rawkuma.kt b/multisrc/overrides/mangathemesia/rawkuma/src/Rawkuma.kt index bce788723..3bc87fcbe 100644 --- a/multisrc/overrides/mangathemesia/rawkuma/src/Rawkuma.kt +++ b/multisrc/overrides/mangathemesia/rawkuma/src/Rawkuma.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.ja.rawkuma import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Rawkuma : MangaThemesia("Rawkuma", "https://rawkuma.com/", "ja") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() } diff --git a/multisrc/overrides/mangathemesia/readkomik/src/ReadKomik.kt b/multisrc/overrides/mangathemesia/readkomik/src/ReadKomik.kt index 98a881a7f..d1b8c7531 100644 --- a/multisrc/overrides/mangathemesia/readkomik/src/ReadKomik.kt +++ b/multisrc/overrides/mangathemesia/readkomik/src/ReadKomik.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.en.readkomik import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class ReadKomik : MangaThemesia("Readkomik", "https://readkomik.com", "en") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/ryukonesia/src/Ryukonesia.kt b/multisrc/overrides/mangathemesia/ryukonesia/src/Ryukonesia.kt index 4e19d66e5..f6a1540aa 100644 --- a/multisrc/overrides/mangathemesia/ryukonesia/src/Ryukonesia.kt +++ b/multisrc/overrides/mangathemesia/ryukonesia/src/Ryukonesia.kt @@ -3,13 +3,10 @@ package eu.kanade.tachiyomi.extension.id.ryukonesia import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class Ryukonesia : MangaThemesia("Ryukonesia", "https://ryukonesia.net", "id") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() } diff --git a/multisrc/overrides/mangathemesia/sektedoujin/src/SekteDoujin.kt b/multisrc/overrides/mangathemesia/sektedoujin/src/SekteDoujin.kt index 92df0e544..dcac72f8a 100644 --- a/multisrc/overrides/mangathemesia/sektedoujin/src/SekteDoujin.kt +++ b/multisrc/overrides/mangathemesia/sektedoujin/src/SekteDoujin.kt @@ -5,13 +5,10 @@ import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit class SekteDoujin : MangaThemesia("Sekte Doujin", "https://sektedoujin.lol", "id", dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.forLanguageTag("id"))) { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() } diff --git a/multisrc/overrides/mangathemesia/sheamanga/src/SheaManga.kt b/multisrc/overrides/mangathemesia/sheamanga/src/SheaManga.kt index fb19b54e8..70b8b4676 100644 --- a/multisrc/overrides/mangathemesia/sheamanga/src/SheaManga.kt +++ b/multisrc/overrides/mangathemesia/sheamanga/src/SheaManga.kt @@ -6,7 +6,6 @@ import okhttp3.Dns import okhttp3.OkHttpClient import java.text.SimpleDateFormat import java.util.Locale -import java.util.concurrent.TimeUnit class SheaManga : MangaThemesia( "Shea Manga", @@ -15,9 +14,7 @@ class SheaManga : MangaThemesia( dateFormat = SimpleDateFormat("MMMM dd, yyyy", Locale.forLanguageTag("id")), ) { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .dns(Dns.SYSTEM) .build() diff --git a/multisrc/overrides/mangathemesia/silencescan/src/SilenceScan.kt b/multisrc/overrides/mangathemesia/silencescan/src/SilenceScan.kt index da1b6dcfe..b845bc22f 100644 --- a/multisrc/overrides/mangathemesia/silencescan/src/SilenceScan.kt +++ b/multisrc/overrides/mangathemesia/silencescan/src/SilenceScan.kt @@ -17,9 +17,7 @@ class SilenceScan : MangaThemesia( override val versionId: Int = 2 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/mangathemesia/tsundokutraducoes/src/TsundokuTraducoes.kt b/multisrc/overrides/mangathemesia/tsundokutraducoes/src/TsundokuTraducoes.kt index 66e4a8bda..3211e6c8a 100644 --- a/multisrc/overrides/mangathemesia/tsundokutraducoes/src/TsundokuTraducoes.kt +++ b/multisrc/overrides/mangathemesia/tsundokutraducoes/src/TsundokuTraducoes.kt @@ -14,7 +14,7 @@ class TsundokuTraducoes : MangaThemesia( dateFormat = SimpleDateFormat("MMMMM d, yyyy", Locale("pt", "BR")), ) { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(1, 2, TimeUnit.SECONDS) .build() diff --git a/multisrc/overrides/mangathemesia/westmanga/src/WestManga.kt b/multisrc/overrides/mangathemesia/westmanga/src/WestManga.kt index 2d460ba15..a3181f471 100644 --- a/multisrc/overrides/mangathemesia/westmanga/src/WestManga.kt +++ b/multisrc/overrides/mangathemesia/westmanga/src/WestManga.kt @@ -3,15 +3,12 @@ package eu.kanade.tachiyomi.extension.id.westmanga import eu.kanade.tachiyomi.multisrc.mangathemesia.MangaThemesia import eu.kanade.tachiyomi.network.interceptor.rateLimit import okhttp3.OkHttpClient -import java.util.concurrent.TimeUnit class WestManga : MangaThemesia("West Manga", "https://westmanga.info", "id") { // Formerly "West Manga (WP Manga Stream)" override val id = 8883916630998758688 - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .rateLimit(4) .build() diff --git a/multisrc/overrides/mangathemesia/xcalibrscans/src/xCaliBRScans.kt b/multisrc/overrides/mangathemesia/xcalibrscans/src/xCaliBRScans.kt index 00c8ca811..4cb3f9e3b 100644 --- a/multisrc/overrides/mangathemesia/xcalibrscans/src/xCaliBRScans.kt +++ b/multisrc/overrides/mangathemesia/xcalibrscans/src/xCaliBRScans.kt @@ -8,13 +8,10 @@ import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.OkHttpClient import org.jsoup.nodes.Document import org.jsoup.nodes.Element -import java.util.concurrent.TimeUnit class xCaliBRScans : MangaThemesia("xCaliBR Scans", "https://xcalibrscans.com", "en") { - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .connectTimeout(10, TimeUnit.SECONDS) - .readTimeout(30, TimeUnit.SECONDS) + override val client: OkHttpClient = super.client.newBuilder() .addInterceptor(AntiScrapInterceptor()) .rateLimit(2) .build() diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt index 249fd7724..40580d4ee 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/madara/Madara.kt @@ -3,12 +3,10 @@ package eu.kanade.tachiyomi.multisrc.madara import android.app.Application import android.content.SharedPreferences import android.util.Base64 -import android.util.Log -import android.widget.Toast -import androidx.preference.EditTextPreference import androidx.preference.PreferenceScreen -import androidx.preference.SwitchPreferenceCompat import eu.kanade.tachiyomi.lib.cryptoaes.CryptoAES +import eu.kanade.tachiyomi.lib.randomua.RandomUserAgentPreference +import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.asObservable @@ -21,17 +19,13 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import okhttp3.CacheControl import okhttp3.FormBody -import okhttp3.Headers import okhttp3.HttpUrl.Companion.toHttpUrlOrNull -import okhttp3.Interceptor -import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -40,7 +34,6 @@ import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy -import java.io.IOException import java.text.ParseException import java.text.SimpleDateFormat import java.util.Calendar @@ -58,91 +51,24 @@ abstract class Madara( Injekt.get().getSharedPreferences("source_$id", 0x0000) } + private val randomUAPrefHelper: RandomUserAgentPreference by lazy { + RandomUserAgentPreference(preferences) + } + override val supportsLatest = true - // override with true if you want useRandomUserAgentByDefault to be on by default for some source - protected open val useRandomUserAgentByDefault: Boolean = false - - /** - * override include/exclude user-agent string if needed - * some example: - * listOf("chrome") - * listOf("linux", "windows") - * listOf("108") - */ - protected open val filterIncludeUserAgent: List = listOf() - protected open val filterExcludeUserAgent: List = listOf() - - private var userAgent: String? = null - private var checkedUa = false - - private val hasUaIntercept by lazy { - client.interceptors.toString().contains("uaIntercept") - } - - protected val uaIntercept = object : Interceptor { - override fun intercept(chain: Interceptor.Chain): Response { - val useRandomUa = preferences.getBoolean(PREF_KEY_RANDOM_UA, false) - val customUa = preferences.getString(PREF_KEY_CUSTOM_UA, "") - - try { - if (hasUaIntercept && (useRandomUa || customUa!!.isNotBlank())) { - Log.i("Extension_setting", "$TITLE_RANDOM_UA or $TITLE_CUSTOM_UA option is ENABLED") - - if (customUa!!.isNotBlank() && useRandomUa.not()) { - userAgent = customUa - } - - if (userAgent.isNullOrBlank() && !checkedUa) { - val uaResponse = chain.proceed(GET(UA_DB_URL)) - - if (uaResponse.isSuccessful) { - var listUserAgentString = - json.decodeFromString>>(uaResponse.body.string())["desktop"] - - if (filterIncludeUserAgent.isNotEmpty()) { - listUserAgentString = listUserAgentString!!.filter { - filterIncludeUserAgent.any { filter -> - it.contains(filter, ignoreCase = true) - } - } - } - if (filterExcludeUserAgent.isNotEmpty()) { - listUserAgentString = listUserAgentString!!.filterNot { - filterExcludeUserAgent.any { filter -> - it.contains(filter, ignoreCase = true) - } - } - } - userAgent = listUserAgentString!!.random() - checkedUa = true - } - - uaResponse.close() - } - - if (userAgent.isNullOrBlank().not()) { - val newRequest = chain.request().newBuilder() - .header("User-Agent", userAgent!!.trim()) - .build() - - return chain.proceed(newRequest) - } - } - - return chain.proceed(chain.request()) - } catch (e: Exception) { - throw IOException(e.message) - } - } - } - - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .addInterceptor(uaIntercept) + override val client = network.cloudflareClient.newBuilder() + .setRandomUserAgent( + randomUAPrefHelper.getPrefUAType(), + randomUAPrefHelper.getPrefCustomUA(), + ) .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .build() + override fun headersBuilder() = super.headersBuilder() + .add("Referer", "$baseUrl/") + protected open val json: Json by injectLazy() /** @@ -187,9 +113,6 @@ abstract class Madara( */ protected open val mangaSubString = "manga" - override fun headersBuilder(): Headers.Builder = Headers.Builder() - .add("Referer", "$baseUrl/") - // Popular Manga override fun popularMangaParse(response: Response): MangasPage { @@ -1017,57 +940,6 @@ abstract class Madara( } } - override fun setupPreferenceScreen(screen: PreferenceScreen) { - if (hasUaIntercept) { - val prefUserAgent = SwitchPreferenceCompat(screen.context).apply { - key = PREF_KEY_RANDOM_UA - title = TITLE_RANDOM_UA - summary = if (preferences.getBoolean(PREF_KEY_RANDOM_UA, useRandomUserAgentByDefault)) userAgent else "" - setDefaultValue(useRandomUserAgentByDefault) - - setOnPreferenceChangeListener { _, newValue -> - val useRandomUa = newValue as Boolean - preferences.edit().putBoolean(PREF_KEY_RANDOM_UA, useRandomUa).apply() - if (!useRandomUa) { - Toast.makeText(screen.context, RESTART_APP_STRING, Toast.LENGTH_LONG).show() - } else { - userAgent = null - if (preferences.getString(PREF_KEY_CUSTOM_UA, "").isNullOrBlank().not()) { - Toast.makeText(screen.context, SUMMARY_CLEANING_CUSTOM_UA, Toast.LENGTH_LONG).show() - } - } - - preferences.edit().putString(PREF_KEY_CUSTOM_UA, "").apply() - // prefCustomUserAgent.summary = "" - true - } - } - screen.addPreference(prefUserAgent) - - val prefCustomUserAgent = EditTextPreference(screen.context).apply { - key = PREF_KEY_CUSTOM_UA - title = TITLE_CUSTOM_UA - summary = preferences.getString(PREF_KEY_CUSTOM_UA, "")!!.trim() - setOnPreferenceChangeListener { _, newValue -> - val customUa = newValue as String - preferences.edit().putString(PREF_KEY_CUSTOM_UA, customUa).apply() - if (customUa.isBlank()) { - Toast.makeText(screen.context, RESTART_APP_STRING, Toast.LENGTH_LONG).show() - } else { - userAgent = null - } - summary = customUa.trim() - prefUserAgent.summary = "" - prefUserAgent.isChecked = false - true - } - } - screen.addPreference(prefCustomUserAgent) - } else { - Toast.makeText(screen.context, DOESNOT_SUPPORT_STRING, Toast.LENGTH_LONG).show() - } - } - // https://stackoverflow.com/a/66614516 private fun String.decodeHex(): ByteArray { check(length % 2 == 0) { "Must have an even length" } @@ -1077,20 +949,12 @@ abstract class Madara( .toByteArray() } + override fun setupPreferenceScreen(screen: PreferenceScreen) { + randomUAPrefHelper.addPreferenceToScreen(screen) + } + companion object { - const val TITLE_RANDOM_UA = "Use Random Latest User-Agent" - const val PREF_KEY_RANDOM_UA = "pref_key_random_ua" - - const val TITLE_CUSTOM_UA = "Custom User-Agent" - const val PREF_KEY_CUSTOM_UA = "pref_key_custom_ua" - - const val SUMMARY_CLEANING_CUSTOM_UA = "$TITLE_CUSTOM_UA cleared." - - const val RESTART_APP_STRING = "Restart Tachiyomi to apply new setting." - const val DOESNOT_SUPPORT_STRING = "This extension doesn't support User-Agent options." const val URL_SEARCH_PREFIX = "slug:" - private const val UA_DB_URL = "https://tachiyomiorg.github.io/user-agents/user-agents.json" - val SALTED = "Salted__".toByteArray(Charsets.UTF_8) } } 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 9fa4c01ae..5d199187d 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 @@ -10,7 +10,7 @@ class MadaraGenerator : ThemeSourceGenerator { override val themeClass = "Madara" - override val baseVersionCode: Int = 30 + override val baseVersionCode: Int = 31 override val sources = listOf( MultiLang("Atlantis Scan", "https://atlantisscan.com", listOf("es", "pt-BR"), isNsfw = true), diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHub.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHub.kt index 00df4ebdc..7589f1ef0 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHub.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHub.kt @@ -1,5 +1,7 @@ package eu.kanade.tachiyomi.multisrc.mangahub +import eu.kanade.tachiyomi.lib.randomua.UserAgentType +import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.interceptor.rateLimit @@ -48,7 +50,10 @@ abstract class MangaHub( private var baseCdnUrl = "https://imgx.mghubcdn.com" override val client: OkHttpClient = super.client.newBuilder() - .addInterceptor(::uaIntercept) + .setRandomUserAgent( + userAgentType = UserAgentType.DESKTOP, + filterInclude = listOf("chrome"), + ) .addInterceptor(::apiAuthInterceptor) .rateLimit(1) .build() @@ -65,35 +70,6 @@ abstract class MangaHub( open val json: Json by injectLazy() - private var userAgent: String? = null - private var checkedUa = false - - private fun uaIntercept(chain: Interceptor.Chain): Response { - if (userAgent == null && !checkedUa) { - val uaResponse = chain.proceed(GET(UA_DB_URL)) - - if (uaResponse.isSuccessful) { - // only using desktop chromium-based browsers, apparently they refuse to load(403) if not chrome(ium) - val uaList = json.decodeFromString>>(uaResponse.body.string()) - val chromeUserAgentString = uaList["desktop"]!!.filter { it.contains("chrome", ignoreCase = true) } - userAgent = chromeUserAgentString.random() - checkedUa = true - } - - uaResponse.close() - } - - if (userAgent != null) { - val newRequest = chain.request().newBuilder() - .header("User-Agent", userAgent!!) - .build() - - return chain.proceed(newRequest) - } - - return chain.proceed(chain.request()) - } - private fun apiAuthInterceptor(chain: Interceptor.Chain): Response { val originalRequest = chain.request() @@ -514,8 +490,4 @@ abstract class MangaHub( Genre("Wuxia", "wuxia"), Genre("Yuri", "yuri"), ) - - companion object { - private const val UA_DB_URL = "https://tachiyomiorg.github.io/user-agents/user-agents.json" - } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHubGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHubGenerator.kt index 43279683a..3b05e98df 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHubGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangahub/MangaHubGenerator.kt @@ -9,7 +9,7 @@ class MangaHubGenerator : ThemeSourceGenerator { override val themeClass = "MangaHub" - override val baseVersionCode: Int = 21 + override val baseVersionCode: Int = 22 override val sources = listOf( // SingleLang("1Manga.co", "https://1manga.co", "en", isNsfw = true, className = "OneMangaCo"), diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt index d29b8fb2a..cb0a97ca8 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesia.kt @@ -2,11 +2,9 @@ package eu.kanade.tachiyomi.multisrc.mangathemesia import android.app.Application import android.content.SharedPreferences -import android.util.Log -import android.widget.Toast -import androidx.preference.EditTextPreference import androidx.preference.PreferenceScreen -import androidx.preference.SwitchPreferenceCompat +import eu.kanade.tachiyomi.lib.randomua.RandomUserAgentPreference +import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.source.ConfigurableSource @@ -18,7 +16,6 @@ import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup -import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonPrimitive @@ -26,8 +23,6 @@ import okhttp3.FormBody import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull -import okhttp3.Interceptor -import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -37,7 +32,6 @@ import rx.Observable import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy -import java.io.IOException import java.lang.IllegalArgumentException import java.text.SimpleDateFormat import java.util.Locale @@ -56,82 +50,19 @@ abstract class MangaThemesia( Injekt.get().getSharedPreferences("source_$id", 0x0000) } + private val randomUAPrefHelper: RandomUserAgentPreference by lazy { + RandomUserAgentPreference(preferences) + } + protected open val json: Json by injectLazy() override val supportsLatest = true - // override with true if you want useRandomUserAgentByDefault to be on by default for some source - protected open val useRandomUserAgentByDefault: Boolean = false - - protected open val filterIncludeUserAgent: List = listOf() - protected open val filterExcludeUserAgent: List = listOf() - - private var userAgent: String? = null - private var checkedUa = false - - protected val hasUaIntercept by lazy { - client.interceptors.toString().contains("uaIntercept") - } - - protected val uaIntercept = object : Interceptor { - override fun intercept(chain: Interceptor.Chain): Response { - val useRandomUa = preferences.getBoolean(PREF_KEY_RANDOM_UA, false) - val customUa = preferences.getString(PREF_KEY_CUSTOM_UA, "") - - try { - if (hasUaIntercept && (useRandomUa || customUa!!.isNotBlank())) { - Log.i("Extension_setting", "$TITLE_RANDOM_UA or $TITLE_CUSTOM_UA option is ENABLED") - - if (customUa!!.isNotBlank() && useRandomUa.not()) { - userAgent = customUa - } - - if (userAgent.isNullOrBlank() && !checkedUa) { - val uaResponse = chain.proceed(GET(UA_DB_URL)) - - if (uaResponse.isSuccessful) { - var listUserAgentString = - json.decodeFromString>>(uaResponse.body.string())["desktop"] - - if (filterIncludeUserAgent.isNotEmpty()) { - listUserAgentString = listUserAgentString!!.filter { - filterIncludeUserAgent.any { filter -> - it.contains(filter, ignoreCase = true) - } - } - } - if (filterExcludeUserAgent.isNotEmpty()) { - listUserAgentString = listUserAgentString!!.filterNot { - filterExcludeUserAgent.any { filter -> - it.contains(filter, ignoreCase = true) - } - } - } - userAgent = listUserAgentString!!.random() - checkedUa = true - } - - uaResponse.close() - } - - if (userAgent.isNullOrBlank().not()) { - val newRequest = chain.request().newBuilder() - .header("User-Agent", userAgent!!.trim()) - .build() - - return chain.proceed(newRequest) - } - } - - return chain.proceed(chain.request()) - } catch (e: Exception) { - throw IOException(e.message) - } - } - } - - override val client: OkHttpClient = network.cloudflareClient.newBuilder() - .addInterceptor(uaIntercept) + override val client = network.cloudflareClient.newBuilder() + .setRandomUserAgent( + randomUAPrefHelper.getPrefUAType(), + randomUAPrefHelper.getPrefCustomUA(), + ) .connectTimeout(10, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .build() @@ -524,7 +455,9 @@ abstract class MangaThemesia( val links = response.asJsoup().select("a[itemprop=item]") // near the top of page: home > manga > current chapter if (links.size == 3) { - return links[1].attr("href").toHttpUrlOrNull()?.encodedPath + val newUrl = links[1].attr("href").toHttpUrlOrNull() ?: return null + val isNewMangaUrl = (baseMangaUrl.host == newUrl.host && pathLengthIs(newUrl, 2) && newUrl.pathSegments[0] == baseMangaUrl.pathSegments[0]) + if (isNewMangaUrl) return newUrl.pathSegments[1] } } } @@ -566,58 +499,7 @@ abstract class MangaThemesia( override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not Used") override fun setupPreferenceScreen(screen: PreferenceScreen) { - addRandomAndCustomUserAgentPreferences(screen) - } - - protected fun addRandomAndCustomUserAgentPreferences(screen: PreferenceScreen) { - if (!hasUaIntercept) { - return // Unable to change the user agent. Therefore the preferences won't be displayed. - } - - val prefRandomUserAgent = SwitchPreferenceCompat(screen.context).apply { - key = PREF_KEY_RANDOM_UA - title = TITLE_RANDOM_UA - summary = if (preferences.getBoolean(PREF_KEY_RANDOM_UA, useRandomUserAgentByDefault)) userAgent else "" - setDefaultValue(useRandomUserAgentByDefault) - - setOnPreferenceChangeListener { _, newValue -> - val useRandomUa = newValue as Boolean - preferences.edit().putBoolean(PREF_KEY_RANDOM_UA, useRandomUa).apply() - if (!useRandomUa) { - Toast.makeText(screen.context, RESTART_APP_STRING, Toast.LENGTH_LONG).show() - } else { - userAgent = null - if (preferences.getString(PREF_KEY_CUSTOM_UA, "").isNullOrBlank().not()) { - Toast.makeText(screen.context, SUMMARY_CLEANING_CUSTOM_UA, Toast.LENGTH_LONG).show() - } - } - - preferences.edit().putString(PREF_KEY_CUSTOM_UA, "").apply() - true - } - } - - val prefCustomUserAgent = EditTextPreference(screen.context).apply { - key = PREF_KEY_CUSTOM_UA - title = TITLE_CUSTOM_UA - summary = preferences.getString(PREF_KEY_CUSTOM_UA, "")!!.trim() - setOnPreferenceChangeListener { _, newValue -> - val customUa = newValue as String - preferences.edit().putString(PREF_KEY_CUSTOM_UA, customUa).apply() - if (customUa.isBlank()) { - Toast.makeText(screen.context, RESTART_APP_STRING, Toast.LENGTH_LONG).show() - } else { - userAgent = null - } - summary = customUa.trim() - prefRandomUserAgent.summary = "" - prefRandomUserAgent.isChecked = false - true - } - } - - screen.addPreference(prefRandomUserAgent) - screen.addPreference(prefCustomUserAgent) + randomUAPrefHelper.addPreferenceToScreen(screen) } companion object { @@ -629,16 +511,5 @@ abstract class MangaThemesia( private val CHAPTER_PAGE_ID_REGEX = "chapter_id\\s*=\\s*(\\d+);".toRegex() val JSON_IMAGE_LIST_REGEX = "\"images\"\\s*:\\s*(\\[.*?])".toRegex() - - const val TITLE_RANDOM_UA = "Use Random Latest User-Agent" - const val PREF_KEY_RANDOM_UA = "pref_key_random_ua" - - const val TITLE_CUSTOM_UA = "Custom User-Agent" - const val PREF_KEY_CUSTOM_UA = "pref_key_custom_ua" - - const val SUMMARY_CLEANING_CUSTOM_UA = "$TITLE_CUSTOM_UA cleared." - - const val RESTART_APP_STRING = "Restart Tachiyomi to apply new setting." - private const val UA_DB_URL = "https://tachiyomiorg.github.io/user-agents/user-agents.json" } } diff --git a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt index d432236b5..359ff2683 100644 --- a/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt +++ b/multisrc/src/main/java/eu/kanade/tachiyomi/multisrc/mangathemesia/MangaThemesiaGenerator.kt @@ -11,7 +11,7 @@ class MangaThemesiaGenerator : ThemeSourceGenerator { override val themeClass = "MangaThemesia" - override val baseVersionCode: Int = 25 + override val baseVersionCode: Int = 26 override val sources = listOf( MultiLang("Asura Scans", "https://www.asurascans.com", listOf("en", "tr"), className = "AsuraScansFactory", pkgName = "asurascans", overrideVersionCode = 23), diff --git a/settings.gradle.kts b/settings.gradle.kts index 025aa944a..62e6f6d93 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,8 +1,10 @@ include(":core") -listOf("dataimage", "unpacker", "cryptoaes", "textinterceptor", "synchrony").forEach { - include(":lib-$it") - project(":lib-$it").projectDir = File("lib/$it") +// all the directories under /lib instead of manually adding each to a list +File(rootDir, "lib").eachDir { + val libName = it.name + include(":lib-$libName") + project(":lib-$libName").projectDir = File("lib/$libName") } if (System.getenv("CI") == null || System.getenv("CI_MODULE_GEN") == "true") { diff --git a/src/all/nhentai/build.gradle b/src/all/nhentai/build.gradle index a66b45085..e2b948455 100644 --- a/src/all/nhentai/build.gradle +++ b/src/all/nhentai/build.gradle @@ -5,8 +5,12 @@ ext { extName = 'NHentai' pkgNameSuffix = 'all.nhentai' extClass = '.NHFactory' - extVersionCode = 37 + extVersionCode = 38 isNsfw = true } +dependencies { + implementation(project(":lib-randomua")) +} + apply from: "$rootDir/common.gradle" diff --git a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt index 8023aeebd..c48df5593 100644 --- a/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt +++ b/src/all/nhentai/src/eu/kanade/tachiyomi/extension/all/nhentai/NHentai.kt @@ -2,12 +2,16 @@ package eu.kanade.tachiyomi.extension.all.nhentai import android.app.Application import android.content.SharedPreferences +import androidx.preference.ListPreference +import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getArtists import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getGroups import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getNumPages import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTagDescription import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTags import eu.kanade.tachiyomi.extension.all.nhentai.NHUtils.getTime +import eu.kanade.tachiyomi.lib.randomua.UserAgentType +import eu.kanade.tachiyomi.lib.randomua.setRandomUserAgent import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.asObservableSuccess import eu.kanade.tachiyomi.network.interceptor.rateLimit @@ -22,7 +26,6 @@ import eu.kanade.tachiyomi.source.model.UpdateStrategy import eu.kanade.tachiyomi.source.online.ParsedHttpSource import eu.kanade.tachiyomi.util.asJsoup import okhttp3.HttpUrl.Companion.toHttpUrlOrNull -import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response import org.jsoup.nodes.Document @@ -44,7 +47,11 @@ open class NHentai( override val supportsLatest = true - override val client: OkHttpClient = network.cloudflareClient.newBuilder() + override val client = network.cloudflareClient.newBuilder() + .setRandomUserAgent( + userAgentType = UserAgentType.MOBILE, + filterInclude = listOf("chrome"), + ) .rateLimit(4) .build() @@ -60,13 +67,14 @@ open class NHentai( private val shortenTitleRegex = Regex("""(\[[^]]*]|[({][^)}]*[)}])""") private fun String.shortenTitle() = this.replace(shortenTitleRegex, "").trim() - override fun setupPreferenceScreen(screen: androidx.preference.PreferenceScreen) { - val serverPref = androidx.preference.ListPreference(screen.context).apply { + override fun setupPreferenceScreen(screen: PreferenceScreen) { + ListPreference(screen.context).apply { key = TITLE_PREF title = TITLE_PREF entries = arrayOf("Full Title", "Short Title") entryValues = arrayOf("full", "short") summary = "%s" + setDefaultValue("full") setOnPreferenceChangeListener { _, newValue -> displayFullTitle = when (newValue) { @@ -75,13 +83,7 @@ open class NHentai( } true } - } - - if (!preferences.contains(TITLE_PREF)) { - preferences.edit().putString(TITLE_PREF, "full").apply() - } - - screen.addPreference(serverPref) + }.also(screen::addPreference) } override fun latestUpdatesRequest(page: Int) = GET(if (nhLang.isBlank()) "$baseUrl/?page=$page" else "$baseUrl/language/$nhLang/?page=$page", headers)