diff --git a/app/build.gradle b/app/build.gradle index 1762fa54..7faa0bbc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -138,10 +138,11 @@ dependencies { implementation 'ca.gosyer:voyager-navigator:1.0.0-rc07' implementation 'com.squareup.logcat:logcat:0.1' implementation 'com.github.inorichi.injekt:injekt-core:65b0440' - implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.11' - implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.11' + implementation 'com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.12' + implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.12' implementation 'com.squareup.okhttp3:okhttp-dnsoverhttps' implementation 'com.squareup.okio:okio:3.7.0' + implementation 'com.squareup.okhttp3:okhttp-brotli:5.0.0-alpha.12' implementation 'ch.acra:acra-http:5.11.3' implementation 'org.jsoup:jsoup:1.15.4' implementation 'org.jetbrains.kotlinx:kotlinx-serialization-json-okio:1.6.2' diff --git a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt index 0ad6ecaf..1d7a8497 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/AnimeWatchAdapter.kt @@ -257,8 +257,15 @@ class AnimeWatchAdapter( val url = sourceHttp?.baseUrl url?.let { refresh = true + val headersMap = try { + sourceHttp.headers.toMultimap() + .mapValues { it.value.getOrNull(0) ?: "" } + } catch (e: Exception) { + emptyMap() + } val intent = Intent(fragment.requireContext(), CookieCatcher::class.java) .putExtra("url", url) + .putExtra("headers", headersMap as HashMap) startActivity(fragment.requireContext(), intent, null) } } diff --git a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt index cbe39704..4354a21d 100644 --- a/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt +++ b/app/src/main/java/ani/dantotsu/media/anime/ExoplayerView.kt @@ -97,7 +97,6 @@ import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import okhttp3.internal.immutableListOf import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get import java.util.* @@ -1375,16 +1374,16 @@ class ExoplayerView : AppCompatActivity(), Player.Listener, SessionAvailabilityL logger("mimeType: $mimeType") if (sub != null) { - val listofnotnullsubs = immutableListOf(sub).filterNotNull() + val listofnotnullsubs = listOfNotNull(sub) builder.setSubtitleConfigurations(listofnotnullsubs) } builder.build() } else { val addedSubsDownloadedMediaItem = downloadedMediaItem.buildUpon() if (sub != null) { - val listofnotnullsubs = immutableListOf(sub).filterNotNull() + val listofnotnullsubs = listOfNotNull(sub) val addLanguage = listofnotnullsubs[0].buildUpon().setLanguage("en").build() - addedSubsDownloadedMediaItem.setSubtitleConfigurations(immutableListOf(addLanguage)) + addedSubsDownloadedMediaItem.setSubtitleConfigurations(listOf(addLanguage)) episode.selectedSubtitle = 0 } addedSubsDownloadedMediaItem.build() diff --git a/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt b/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt index d1f3635e..22f11f3f 100644 --- a/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt +++ b/app/src/main/java/ani/dantotsu/others/webview/CookieCatcher.kt @@ -17,12 +17,14 @@ import uy.kohesive.injekt.api.get class CookieCatcher : AppCompatActivity() { @SuppressLint("SetJavaScriptEnabled") + @Suppress("UNCHECKED_CAST") override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ThemeManager(this).applyTheme() //get url from intent val url = intent.getStringExtra("url") ?: "https://www.youtube.com/watch?v=dQw4w9WgXcQ" + val headers: Map = intent.getSerializableExtra("headers") as? Map ?: emptyMap() if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { val process = Application.getProcessName() @@ -54,7 +56,7 @@ class CookieCatcher : AppCompatActivity() { } } - webView.loadUrl(url) + webView.loadUrl(url, headers) } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt index 4d14f649..a4fe08b4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.network.interceptor.UserAgentInterceptor import okhttp3.Cache import okhttp3.OkHttpClient import okhttp3.logging.HttpLoggingInterceptor +import okhttp3.brotli.BrotliInterceptor import java.io.File import java.util.concurrent.TimeUnit @@ -19,26 +20,23 @@ class NetworkHelper( context: Context ) { - private val cacheDir = File(context.cacheDir, "network_cache") - private val cacheSize = 5L * 1024 * 1024 // 5 MiB - val cookieJar = AndroidCookieJar() - private val userAgentInterceptor by lazy { - UserAgentInterceptor(::defaultUserAgentProvider) - } - private val cloudflareInterceptor by lazy { - CloudflareInterceptor(context, cookieJar, ::defaultUserAgentProvider) - } - - private fun baseClientBuilder(callTimeout: Int = 2): OkHttpClient.Builder { + val client: OkHttpClient = run { val builder = OkHttpClient.Builder() .cookieJar(cookieJar) .connectTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) - .callTimeout(callTimeout.toLong(), TimeUnit.MINUTES) + .callTimeout(2, TimeUnit.MINUTES) + .cache( + Cache( + directory = File(context.cacheDir, "network_cache"), + maxSize = 5L * 1024 * 1024, // 5 MiB + ), + ) + .addInterceptor(BrotliInterceptor) .addInterceptor(UncaughtExceptionInterceptor()) - .addInterceptor(userAgentInterceptor) + .addInterceptor(UserAgentInterceptor(::defaultUserAgentProvider)) if (PrefManager.getVal(PrefName.VerboseLogging)) { val httpLoggingInterceptor = HttpLoggingInterceptor().apply { @@ -47,6 +45,10 @@ class NetworkHelper( builder.addNetworkInterceptor(httpLoggingInterceptor) } + builder.addInterceptor( + CloudflareInterceptor(context, cookieJar, ::defaultUserAgentProvider), + ) + when (PrefManager.getVal(PrefName.DohProvider)) { PREF_DOH_CLOUDFLARE -> builder.dohCloudflare() PREF_DOH_GOOGLE -> builder.dohGoogle() @@ -63,19 +65,17 @@ class NetworkHelper( PREF_DOH_LIBREDNS -> builder.dohLibreDNS() } - return builder + builder.build() } + val downloadClient = client.newBuilder().callTimeout(20, TimeUnit.MINUTES).build() - val client by lazy { baseClientBuilder().cache(Cache(cacheDir, cacheSize)).build() } - val downloadClient by lazy { baseClientBuilder(20).build() } - + /** + * @deprecated Since extension-lib 1.5 + */ + @Deprecated("The regular client handles Cloudflare by default") @Suppress("UNUSED") - val cloudflareClient by lazy { - client.newBuilder() - .addInterceptor(cloudflareInterceptor) - .build() - } + val cloudflareClient: OkHttpClient = client val requestClient = Requests( client,